Hi, guys. I’m back.
Okay. So is it possible to use SluggableBehavior (or something else already within the framework - all I was able find was SluggableBehavior) to create a slug from CSV list that gets split into an array?
We have a ‘tag’ table that has a ‘title’ and ‘value’ field. The tags titles are straight forward what the user entered is the title, the value needs to be a slug, though, because we use it in URLs.
Right now in the beforeValidate it’s splitting the CSV into an array
// set tag array
$tags = explode(',', $this->tag);
foreach($tags as $key => $tag) {
$tag = trim($tag);
// skip 'empty' tags
if(empty($title)) {
continue;
}
$tags[$key] = $tag; //NOTE: this actually needs to be an array of arrays for Tag model insert [['title' => 'Tag 1', 'value' => 'tag-1'], ['title'=> 'tag 2', 'value', 'tag-2']]
}
$this->tag = $tags;
then we run some validation on it,
[['tag'], 'each', 'rule' => ['string', 'min' => 2]] //NOTE: this will actually need custom validation
Also is it possible to validate the length of the array?