File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
Controller/Adminhtml/Post Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -114,27 +114,34 @@ protected function _beforeSave($model, $request)
114
114
}
115
115
116
116
/* Prepare Tags */
117
- $ tagInput = trim ($ request ->getPost ('tag_input ' ));
117
+ $ tagInput = trim (( string ) $ request ->getPost ('tag_input ' ));
118
118
if ($ tagInput ) {
119
119
$ tagInput = explode (', ' , $ tagInput );
120
120
121
121
$ tagsCollection = $ this ->_objectManager ->create (\Magefan \Blog \Model \ResourceModel \Tag \Collection::class);
122
122
$ allTags = [];
123
123
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 ();
125
128
}
126
129
127
130
$ tags = [];
128
131
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 ])) {
130
137
$ tagModel = $ this ->_objectManager ->create (\Magefan \Blog \Model \Tag::class);
131
138
$ tagModel ->setData ('title ' , $ tagTitle );
132
139
$ tagModel ->setData ('is_active ' , 1 );
133
140
$ tagModel ->save ();
134
141
135
142
$ tags [] = $ tagModel ->getId ();
136
143
} else {
137
- $ tags [] = $ allTags [strtolower ( $ tagTitle) ];
144
+ $ tags [] = $ allTags [$ tagTitle ];
138
145
}
139
146
}
140
147
$ model ->setData ('tags ' , $ tags );
You can’t perform that action at this time.
0 commit comments