How to programmatically add keywords to an existing page
PermalinkI'm trying to programmatically add keywords to an existing page.
I get keywords from a form, they look like $tags="kw1,kw2,kw3".
Then i try with this :
$importTags = explode(",", $tags); $ak = CollectionAttributeKey::getByHandle('tags'); $tagValues = array(); foreach ($importTags as $tag) { if (!$tagValueObject = SelectAttributeTypeOption::getByValue($tag, $ak)) { $tagValueObject = SelectAttributeTypeOption::add($ak, $tag); } $tagValues[] = $tagValueObject; } $newPage->setAttribute('tags', $tagValues);
This code seems to be used in 5.7, I work on 5.8.
I get this error : "concrete5 Class 'SelectAttributeTypeOption' not found"
If i declare this :
use Concrete\Core\Entity\Attribute\Value\Value\SelectValueOption as SelectAttributeTypeOption;
I get this error : "Call to undefined method Concrete\Core\Entity\Attribute\Value\Value\SelectValueOption::getByValue()"
I don't find any documentation to do this correctly.
Any idea ?

It give no error in response. But the tags aren't saved into the database, so they are not saved as attribute of the page.
I don't know 100% but I thought you just had to send in an array of values not an array of objects.
Not sure it is the main thing i don't understand, but from where do you get $option at the end of the code ?
Thank you very much ! I'll work on it !