Skip to content

Commit b1a81ca

Browse files
committed
PHP 8.1 compatability on post save in admin panel
1 parent 1aa9cbd commit b1a81ca

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Controller/Adminhtml/Post/Save.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,27 +114,34 @@ protected function _beforeSave($model, $request)
114114
}
115115

116116
/* Prepare Tags */
117-
$tagInput = trim($request->getPost('tag_input'));
117+
$tagInput = trim((string)$request->getPost('tag_input'));
118118
if ($tagInput) {
119119
$tagInput = explode(',', $tagInput);
120120

121121
$tagsCollection = $this->_objectManager->create(\Magefan\Blog\Model\ResourceModel\Tag\Collection::class);
122122
$allTags = [];
123123
foreach ($tagsCollection as $item) {
124-
$allTags[strtolower($item->getTitle())] = $item->getId();
124+
if (!$item->getTitle()) {
125+
continue;
126+
}
127+
$allTags[strtolower((string)$item->getTitle())] = $item->getId();
125128
}
126129

127130
$tags = [];
128131
foreach ($tagInput as $tagTitle) {
129-
if (empty($allTags[strtolower($tagTitle)])) {
132+
$tagTitle = strtolower(trim((string)$tagTitle));
133+
if (!$tagTitle) {
134+
continue;
135+
}
136+
if (empty($allTags[$tagTitle])) {
130137
$tagModel = $this->_objectManager->create(\Magefan\Blog\Model\Tag::class);
131138
$tagModel->setData('title', $tagTitle);
132139
$tagModel->setData('is_active', 1);
133140
$tagModel->save();
134141

135142
$tags[] = $tagModel->getId();
136143
} else {
137-
$tags[] = $allTags[strtolower($tagTitle)];
144+
$tags[] = $allTags[$tagTitle];
138145
}
139146
}
140147
$model->setData('tags', $tags);

0 commit comments

Comments
 (0)