FOF30\Model\DataModel\Behaviour\Tags::onAfterSave PHP Method

onAfterSave() public method

The event which runs after binding data to the table
public onAfterSave ( &$model ) : void
return void
    public function onAfterSave(&$model)
    {
        $tagField = $model->getBehaviorParam('tagFieldName', 'tags');
        // Avoid to update on other method (e.g. publish, ...)
        if (!in_array($model->getContainer()->input->getCmd('task'), array('apply', 'save', 'savenew'))) {
            return;
        }
        $oldTags = $this->tagsHelper->getTagIds($model->getId(), $model->getContentType());
        $newTags = $model->{$tagField} ? implode(',', $model->{$tagField}) : null;
        // If no changes, we stop here
        if ($oldTags == $newTags) {
            return;
        }
        // Check if the content type exists, and create it if it does not
        $model->checkContentType();
        $this->tagsHelper->typeAlias = $model->getContentType();
        if (!$this->tagsHelper->postStoreProcess($model, $model->{$tagField})) {
            throw new \Exception('Error storing tags');
        }
    }