/** * @param $owner * @void */ public function afterOwnerSave($owner) { if (method_exists($owner, 'getAbsoluteUrl')) { $metaConfig = $owner->metaConfig; $attributes = $this->getAttributes(); if (empty($attributes['is_custom'])) { $this->setAttributes(['title' => $owner->{$metaConfig['title']}, 'keywords' => MetaGenerator::generateKeywords($owner->{$metaConfig['keywords']}), 'description' => MetaGenerator::generateDescription($owner->{$metaConfig['description']}), 'url' => $owner->getAbsoluteUrl()]); } else { $this->setAttributes(['url' => $owner->getAbsoluteUrl()]); } } }
/** * @param \Mindy\Form\BaseForm|ModelForm $owner * @param array $attributes * @throws Exception * @return array */ public function beforeSetAttributes($owner, array $attributes) { $model = $owner->getModel(); $ownerModel = $owner->getParentForm()->getInstance(); if (!isset($ownerModel->metaConfig)) { throw new Exception("metaConfig doesn't exists in model: " . $model->className()); } $meta = $ownerModel->metaConfig; if (empty($attributes['is_custom'])) { $attributes = array_merge($attributes, ['title' => $ownerModel->{$meta['title']}, 'keywords' => MetaGenerator::generateKeywords($ownerModel->{$meta['keywords']}), 'description' => MetaGenerator::generateDescription($ownerModel->{$meta['description']})]); } return parent::beforeSetAttributes($owner, $attributes); }