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)
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 );
You can’t perform that action at this time.
0 commit comments