From 15c4dc0b132ba0549c0dea8db6e77e338094f35f Mon Sep 17 00:00:00 2001 From: Henrik Elsner Date: Sun, 14 Mar 2021 11:51:27 +0100 Subject: [PATCH] [BUGFIX] Prevent plugins to cause empty page meta tags Refs #187 --- Classes/Controller/PostController.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Classes/Controller/PostController.php b/Classes/Controller/PostController.php index 6f746e64..c637ed47 100644 --- a/Classes/Controller/PostController.php +++ b/Classes/Controller/PostController.php @@ -235,7 +235,10 @@ public function listPostsByCategoryAction(Category $category = null): void $this->view->assign('posts', $posts); $this->view->assign('category', $category); MetaTagService::set(MetaTagService::META_TITLE, (string) $category->getTitle()); - MetaTagService::set(MetaTagService::META_DESCRIPTION, (string) $category->getDescription()); + + if (!empty($categoryDescription = (string) $category->getDescription())) { + MetaTagService::set(MetaTagService::META_DESCRIPTION, $categoryDescription); + } } else { $this->view->assign('categories', $this->categoryRepository->findAll()); } @@ -256,7 +259,10 @@ public function listPostsByAuthorAction(Author $author = null): void $this->view->assign('posts', $posts); $this->view->assign('author', $author); MetaTagService::set(MetaTagService::META_TITLE, (string) $author->getName()); - MetaTagService::set(MetaTagService::META_DESCRIPTION, (string) $author->getBio()); + + if (!empty($authorBio = (string) $author->getBio())) { + MetaTagService::set(MetaTagService::META_DESCRIPTION, $authorBio); + } } else { $this->view->assign('authors', $this->authorRepository->findAll()); } @@ -277,7 +283,10 @@ public function listPostsByTagAction(Tag $tag = null): void $this->view->assign('posts', $posts); $this->view->assign('tag', $tag); MetaTagService::set(MetaTagService::META_TITLE, (string) $tag->getTitle()); - MetaTagService::set(MetaTagService::META_DESCRIPTION, (string) $tag->getDescription()); + + if (!empty($tagDescription = (string) $tag->getDescription())) { + MetaTagService::set(MetaTagService::META_DESCRIPTION, $tagDescription); + } } else { $this->view->assign('tags', $this->tagRepository->findAll()); }