Skip to content

Commit

Permalink
Merge pull request #14 from TheCadien/seo
Browse files Browse the repository at this point in the history
Add SEO functionality
  • Loading branch information
TheCadien authored Sep 26, 2021
2 parents 8025d03 + f325126 commit c5d1d8f
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 17 deletions.
18 changes: 16 additions & 2 deletions Admin/NewsAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -62,6 +62,7 @@ class NewsAdmin extends Admin
* @var ActivityViewBuilderFactoryInterface
*/
private $activityViewBuilderFactory;

/**
* ArticleAdmin constructor.
*/
Expand Down Expand Up @@ -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)
);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions Api/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
19 changes: 12 additions & 7 deletions Controller/NewsWebsiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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(
Expand All @@ -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 = [])
{
Expand All @@ -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;
Expand Down
14 changes: 8 additions & 6 deletions Entity/Factory/NewsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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));
}

Expand Down
15 changes: 15 additions & 0 deletions Entity/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ class News implements NewsInterface, AuditableInterface, RoutableInterface
*/
private $locale;

/**
* @var string
*/
private $seo;

/**
* News constructor.
*/
Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions Resources/config/doctrine/News.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<field name="changed" type="datetime" column="changed" nullable="false"/>
<field name="publishedAt" type="datetime" column="publishedAt" nullable="false"/>
<field name="locale" type="string" column="locale" length="16"/>
<field name="seo" type="json" column="seo" nullable="true"/>

<many-to-many field="tags" target-entity="Sulu\Bundle\TagBundle\Tag\TagInterface">
<join-table name="news_tags">
Expand Down
78 changes: 78 additions & 0 deletions Resources/config/forms/news_seo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" ?>
<form xmlns="http://schemas.sulu.io/template/template"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/form-1.0.xsd"
>
<key>news_seo</key>

<properties>
<property name="search_result" type="search_result" colspan="9">
<meta>
<title>sulu_page.search_result</title>
</meta>
</property>
<property name="ext/seo/title" type="text_line">
<meta>
<title>sulu_page.meta_title</title>
<info_text>sulu_page.meta_title_info_text</info_text>
</meta>
<params>
<param name="soft_max_length" value="55" />
</params>
</property>
<property name="ext/seo/description" type="text_area">
<meta>
<title>sulu_page.meta_description</title>
<info_text>sulu_page.meta_description_info_text</info_text>
</meta>
<params>
<param name="soft_max_length" value="160" />
</params>
</property>
<property name="ext/seo/keywords" type="text_line">
<meta>
<title>sulu_page.meta_keywords</title>
<info_text>sulu_page.meta_keywords_info_text</info_text>
</meta>
<params>
<param name="segment_delimiter" value="," />
<param name="max_segments" value="5" />
</params>
</property>
<property name="ext/seo/canonicalUrl" type="text_line">
<meta>
<title>sulu_page.canonical_url</title>
</meta>
</property>
<property name="ext/seo/noIndex" type="checkbox">
<params>
<param name="label">
<meta>
<title>sulu_page.no_index</title>
</meta>
</param>
<param name="type" value="toggler" />
</params>
</property>
<property name="ext/seo/noFollow" type="checkbox">
<params>
<param name="label">
<meta>
<title>sulu_page.no_follow</title>
</meta>
</param>
<param name="type" value="toggler" />
</params>
</property>
<property name="ext/seo/hideInSitemap" type="checkbox">
<params>
<param name="label">
<meta>
<title>sulu_page.hide_in_sitemap</title>
</meta>
</param>
<param name="type" value="toggler" />
</params>
</property>
</properties>
</form>
2 changes: 1 addition & 1 deletion Tests/Unit/Entity/Factory/NewsFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Traits/Entity/NewsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
}

Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@

## Features
* List view of News
* Routing
* Preview
* SULU Media include
* Content Blocks (Title,Editor,Image,Quote)
* Activity Log
* SEO


## Installation
Expand Down

0 comments on commit c5d1d8f

Please sign in to comment.