In a Element::EVENT_BEFORE_SAVE event within a custom module I'd like to set an SEOMatic field. setFieldValue doesn't work presumably because it's a custom field, is there any reliable way to do this?

Example event I have set up within a module:

public function init()
    self::$instance = $this;

    Event::on(Entry::class, Element::EVENT_BEFORE_SAVE, function(ModelEvent $e) {
        $entry = $e->sender;
        // $entry->seoField seems to be seomatic\models\MetaBundle
        // Setting $entry->seoField->metaGlobalVars->canonicalUrl with setFieldValue doesn't work:
        $entry->setFieldValue('seoField.metaGlobalVars.canonicalUrl', 'special canonical');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.