From 371687857f5e3904d086a178e3f17de351edbc50 Mon Sep 17 00:00:00 2001 From: Oliver Kossin Date: Sun, 26 Sep 2021 11:50:26 +0200 Subject: [PATCH 1/2] add seo to backend --- Admin/NewsAdmin.php | 18 ++++- Api/News.php | 13 ++++ Controller/NewsWebsiteController.php | 19 +++-- Entity/Factory/NewsFactory.php | 14 ++-- Entity/News.php | 15 ++++ Resources/config/doctrine/News.orm.xml | 1 + Resources/config/forms/news_seo.xml | 78 +++++++++++++++++++ Tests/Unit/Entity/Factory/NewsFactoryTest.php | 2 +- Tests/Unit/Traits/Entity/NewsTrait.php | 2 +- 9 files changed, 145 insertions(+), 17 deletions(-) create mode 100644 Resources/config/forms/news_seo.xml diff --git a/Admin/NewsAdmin.php b/Admin/NewsAdmin.php index fc1fd28..874295f 100644 --- a/Admin/NewsAdmin.php +++ b/Admin/NewsAdmin.php @@ -13,6 +13,7 @@ namespace TheCadien\Bundle\SuluNewsBundle\Admin; +use Sulu\Bundle\ActivityBundle\Infrastructure\Sulu\Admin\View\ActivityViewBuilderFactoryInterface; use Sulu\Bundle\AdminBundle\Admin\Admin; use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItem; use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItemCollection; @@ -24,7 +25,6 @@ use Sulu\Component\Security\Authorization\SecurityCheckerInterface; use Sulu\Component\Webspace\Manager\WebspaceManagerInterface; use TheCadien\Bundle\SuluNewsBundle\Entity\News; -use Sulu\Bundle\ActivityBundle\Infrastructure\Sulu\Admin\View\ActivityViewBuilderFactoryInterface; class NewsAdmin extends Admin { @@ -62,6 +62,7 @@ class NewsAdmin extends Admin * @var ActivityViewBuilderFactoryInterface */ private $activityViewBuilderFactory; + /** * ArticleAdmin constructor. */ @@ -166,13 +167,26 @@ public function configureViews(ViewCollection $viewCollection): void $viewCollection->add( $this->activityViewBuilderFactory ->createActivityListViewBuilder( - static::NEWS_EDIT_FORM_VIEW . '.activity', + static::NEWS_EDIT_FORM_VIEW.'.activity', '/activity', News::RESOURCE_KEY ) ->setParent(static::NEWS_EDIT_FORM_VIEW) ); } + + $viewCollection->add( + $this->viewBuilderFactory + ->createPreviewFormViewBuilder('sulu_page.page_edit_form.seo', '/seo') + ->disablePreviewWebspaceChooser() + ->setResourceKey(News::RESOURCE_KEY) + ->setFormKey('news_seo') + ->setTabTitle('sulu_page.seo') + ->addToolbarActions($formToolbarActions) + ->setTitleVisible(true) + ->setTabOrder(2048) + ->setParent(static::NEWS_EDIT_FORM_VIEW) + ); } /** diff --git a/Api/News.php b/Api/News.php index 873bbbf..2f38349 100644 --- a/Api/News.php +++ b/Api/News.php @@ -192,5 +192,18 @@ public function getAuthor(): int return $this->entity->getCreator()->getId(); } + /** + * Get tags. + * + * @VirtualProperty + * @SerializedName("ext") + * @Groups({"fullNews"}) + */ + public function getSeo() + { + $seo = ['seo']; + $seo['seo'] = $this->getEntity()->getSeo(); + return $seo; + } } diff --git a/Controller/NewsWebsiteController.php b/Controller/NewsWebsiteController.php index c991977..28f34da 100644 --- a/Controller/NewsWebsiteController.php +++ b/Controller/NewsWebsiteController.php @@ -29,7 +29,7 @@ public function indexAction(News $news, $attributes = [], $preview = false, $par if (!$news) { throw new NotFoundHttpException(); } - + if ($partial) { $content = $this->renderBlock( 'news/index.html.twig', @@ -38,7 +38,8 @@ public function indexAction(News $news, $attributes = [], $preview = false, $par ); } elseif ($preview) { $content = $this->renderPreview( - 'news/index.html.twig', ['news' => $news] + 'news/index.html.twig', + ['news' => $news] ); } else { $content = $this->renderView( @@ -60,6 +61,10 @@ protected function renderPreview(string $view, array $parameters = []): string /** * Returns rendered part of template specified by block. + * + * @param mixed $template + * @param mixed $block + * @param mixed $attributes */ protected function renderBlock($template, $block, $attributes = []) { @@ -68,17 +73,17 @@ protected function renderBlock($template, $block, $attributes = []) $template = $twig->load($template); - $level = \ob_get_level(); - \ob_start(); + $level = ob_get_level(); + ob_start(); try { $rendered = $template->renderBlock($block, $attributes); - \ob_end_clean(); + ob_end_clean(); return $rendered; } catch (\Exception $e) { - while (\ob_get_level() > $level) { - \ob_end_clean(); + while (ob_get_level() > $level) { + ob_end_clean(); } throw $e; diff --git a/Entity/Factory/NewsFactory.php b/Entity/Factory/NewsFactory.php index 646c7b9..96b3603 100644 --- a/Entity/Factory/NewsFactory.php +++ b/Entity/Factory/NewsFactory.php @@ -13,7 +13,6 @@ namespace TheCadien\Bundle\SuluNewsBundle\Entity\Factory; -use Sulu\Bundle\ContactBundle\Entity\Contact; use Sulu\Bundle\ContactBundle\Entity\ContactRepositoryInterface; use Sulu\Component\Persistence\RelationTrait; use TheCadien\Bundle\SuluNewsBundle\Entity\News; @@ -36,11 +35,10 @@ class NewsFactory extends AbstractFactory implements NewsFactoryInterface * NewsFactory constructor. */ public function __construct( - MediaFactoryInterface $mediaFactory, - TagFactoryInterface $tagFactory, + MediaFactoryInterface $mediaFactory, + TagFactoryInterface $tagFactory, ContactRepositoryInterface $contactRepository - ) - { + ) { $this->mediaFactory = $mediaFactory; $this->tagFactory = $tagFactory; $this->contactRepository = $contactRepository; @@ -73,6 +71,10 @@ public function generateNewsFromRequest(News $news, array $data, string $locale $news->setContent($this->getProperty($data, 'content')); } + if ($this->getProperty($data, 'ext')) { + $news->setSeo($this->getProperty($data['ext'], 'seo')); + } + if ($tags = $this->getProperty($data, 'tags')) { $this->tagFactory->processTags($news, $tags); } @@ -94,7 +96,7 @@ public function generateNewsFromRequest(News $news, array $data, string $locale } if ($author = $this->getProperty($data, 'author')) { - /** @var Contact $contact */ + // @var Contact $contact $news->setCreator($this->contactRepository->find($author)); } diff --git a/Entity/News.php b/Entity/News.php index 10c226f..3419196 100644 --- a/Entity/News.php +++ b/Entity/News.php @@ -99,6 +99,11 @@ class News implements NewsInterface, AuditableInterface, RoutableInterface */ private $locale; + /** + * @var string + */ + private $seo; + /** * News constructor. */ @@ -318,4 +323,14 @@ public function removeDimensionContent(DimensionContentInterface $dimensionConte { // TODO: Implement removeDimensionContent() method. } + + public function getSeo() + { + return $this->seo; + } + + public function setSeo($seo): void + { + $this->seo = $seo; + } } diff --git a/Resources/config/doctrine/News.orm.xml b/Resources/config/doctrine/News.orm.xml index 7212bf2..8755f4c 100644 --- a/Resources/config/doctrine/News.orm.xml +++ b/Resources/config/doctrine/News.orm.xml @@ -35,6 +35,7 @@ + diff --git a/Resources/config/forms/news_seo.xml b/Resources/config/forms/news_seo.xml new file mode 100644 index 0000000..f41d69b --- /dev/null +++ b/Resources/config/forms/news_seo.xml @@ -0,0 +1,78 @@ + +
+ news_seo + + + + + sulu_page.search_result + + + + + sulu_page.meta_title + sulu_page.meta_title_info_text + + + + + + + + sulu_page.meta_description + sulu_page.meta_description_info_text + + + + + + + + sulu_page.meta_keywords + sulu_page.meta_keywords_info_text + + + + + + + + + sulu_page.canonical_url + + + + + + + sulu_page.no_index + + + + + + + + + + sulu_page.no_follow + + + + + + + + + + sulu_page.hide_in_sitemap + + + + + + +
diff --git a/Tests/Unit/Entity/Factory/NewsFactoryTest.php b/Tests/Unit/Entity/Factory/NewsFactoryTest.php index 2d614ac..d4b40cd 100644 --- a/Tests/Unit/Entity/Factory/NewsFactoryTest.php +++ b/Tests/Unit/Entity/Factory/NewsFactoryTest.php @@ -47,7 +47,7 @@ public function __construct($name = null, array $data = [], $dataName = '') $contactRepository = $this->prophesize(ContactRepositoryInterface::class); $contactRepository->find()->willReturn(new Contact()); - $this->factory = new NewsFactory($mediaFactory->reveal(), $tagFactory->reveal(),$contactRepository->reveal()); + $this->factory = new NewsFactory($mediaFactory->reveal(), $tagFactory->reveal(), $contactRepository->reveal()); } public function testNewNewsFactory(): void diff --git a/Tests/Unit/Traits/Entity/NewsTrait.php b/Tests/Unit/Traits/Entity/NewsTrait.php index 82ee086..af069c1 100644 --- a/Tests/Unit/Traits/Entity/NewsTrait.php +++ b/Tests/Unit/Traits/Entity/NewsTrait.php @@ -63,7 +63,7 @@ public function generateNewsContentArray(): array 'locale' => 'en', 'route' => new Route('/test-1', 1, News::class, 'en'), 'enable' => true, - 'publishedAt' => '2017-08-31 00:00:00' + 'publishedAt' => '2017-08-31 00:00:00', ]; } From f325126fee87831575496375679300d145c3bae0 Mon Sep 17 00:00:00 2001 From: Oliver Kossin Date: Sun, 26 Sep 2021 11:53:04 +0200 Subject: [PATCH 2/2] Extend Readme with new features --- readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/readme.md b/readme.md index 9e7bae0..82081ed 100644 --- a/readme.md +++ b/readme.md @@ -26,9 +26,12 @@ ## Features * List view of News +* Routing * Preview +* SULU Media include * Content Blocks (Title,Editor,Image,Quote) * Activity Log +* SEO ## Installation