/** * Save tag relationships * * @param AbstractController $controller * @param Application $application * @return void */ public static function save(AbstractController $controller, Application $application) { $contentId = null; if ($_POST && $controller->hasView() && null !== $controller->view()->id && null !== $controller->view()->form && $controller->view()->form !== false && $controller->view()->form instanceof \Pop\Form\Form) { $tags = $controller->view()->form->content_tags; $contentId = $controller->view()->id; if (null !== $contentId) { $c2t = new Table\TagItems(); $c2t->delete(['content_id' => $contentId]); } if (!empty($tags)) { $tags = explode(',', $tags); foreach ($tags as $tag) { $tag = trim($tag); $t = Table\Tags::findBy(['title' => $tag]); if (!isset($t->id)) { $t = new Table\Tags(['title' => $tag, 'slug' => Slug::filter($tag)]); $t->save(); } $c2t = new Table\TagItems(['content_id' => $contentId, 'tag_id' => $t->id]); $c2t->save(); } } } }