diff --git a/Controller/Adminhtml/Post/Save.php b/Controller/Adminhtml/Post/Save.php index 29df935d..576753f3 100755 --- a/Controller/Adminhtml/Post/Save.php +++ b/Controller/Adminhtml/Post/Save.php @@ -114,19 +114,26 @@ protected function _beforeSave($model, $request) } /* Prepare Tags */ - $tagInput = trim($request->getPost('tag_input')); + $tagInput = trim((string)$request->getPost('tag_input')); if ($tagInput) { $tagInput = explode(',', $tagInput); $tagsCollection = $this->_objectManager->create(\Magefan\Blog\Model\ResourceModel\Tag\Collection::class); $allTags = []; foreach ($tagsCollection as $item) { - $allTags[strtolower($item->getTitle())] = $item->getId(); + if (!$item->getTitle()) { + continue; + } + $allTags[strtolower((string)$item->getTitle())] = $item->getId(); } $tags = []; foreach ($tagInput as $tagTitle) { - if (empty($allTags[strtolower($tagTitle)])) { + $tagTitle = strtolower(trim((string)$tagTitle)); + if (!$tagTitle) { + continue; + } + if (empty($allTags[$tagTitle])) { $tagModel = $this->_objectManager->create(\Magefan\Blog\Model\Tag::class); $tagModel->setData('title', $tagTitle); $tagModel->setData('is_active', 1); @@ -134,7 +141,7 @@ protected function _beforeSave($model, $request) $tags[] = $tagModel->getId(); } else { - $tags[] = $allTags[strtolower($tagTitle)]; + $tags[] = $allTags[$tagTitle]; } } $model->setData('tags', $tags);