Skip to content

Commit

Permalink
Add Link, Teaser, Sitemap providers
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Feb 22, 2024
1 parent 5a3875f commit 46a3dff
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Application/Mapper/ArticleContentMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @internal This class should be instantiated inside a project.
* Use the message to create or modify an article.
* Or the inject all the mappers into a custom service.
* Or inject all the mappers into a custom service.
* Create an own Mapper to extend the mapper with
* custom logic.
*/
Expand Down
50 changes: 50 additions & 0 deletions src/Infrastructure/Sulu/Content/ArticleLinkProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Article\Infrastructure\Sulu\Content;

use Doctrine\ORM\EntityManagerInterface;
use Sulu\Article\Domain\Model\ArticleDimensionContentInterface;
use Sulu\Article\Domain\Model\ArticleInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentManager\ContentManagerInterface;
use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Link\ContentLinkProvider;
use Sulu\Bundle\MarkupBundle\Markup\Link\LinkConfiguration;
use Sulu\Bundle\MarkupBundle\Markup\Link\LinkConfigurationBuilder;
use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactoryInterface;

/**
* @extends ContentLinkProvider<ArticleDimensionContentInterface, ArticleInterface>
*/
class ArticleLinkProvider extends ContentLinkProvider
{
public function __construct(
ContentManagerInterface $contentManager,
StructureMetadataFactoryInterface $structureMetadataFactory,
EntityManagerInterface $entityManager,
) {
parent::__construct($contentManager, $structureMetadataFactory, $entityManager, ArticleInterface::class);
}

public function getConfiguration(): LinkConfiguration
{
return LinkConfigurationBuilder::create()
->setTitle('Example')
->setResourceKey(ArticleInterface::RESOURCE_KEY)
->setListAdapter('table')
->setDisplayProperties(['id'])
->setOverlayTitle('Select Example')
->setEmptyText('No example selected')
->setIcon('su-document')
->getLinkConfiguration();
}
}
73 changes: 73 additions & 0 deletions src/Infrastructure/Sulu/Content/ArticleTeaserProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Article\Infrastructure\Sulu\Content;

use Doctrine\ORM\EntityManagerInterface;
use Sulu\Article\Domain\Model\ArticleDimensionContentInterface;
use Sulu\Article\Domain\Model\ArticleInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentManager\ContentManagerInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentMetadataInspector\ContentMetadataInspectorInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Teaser\ContentTeaserProvider;
use Sulu\Bundle\PageBundle\Teaser\Configuration\TeaserConfiguration;
use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactoryInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* @extends ContentTeaserProvider<ArticleDimensionContentInterface, ArticleInterface>
*/
class ArticleTeaserProvider extends ContentTeaserProvider
{
/**
* @var TranslatorInterface
*/
protected $translator;

public function __construct(
ContentManagerInterface $contentManager,
EntityManagerInterface $entityManager,
ContentMetadataInspectorInterface $contentMetadataInspector,
StructureMetadataFactoryInterface $metadataFactory,
TranslatorInterface $translator,
bool $showDrafts,
) {
parent::__construct($contentManager, $entityManager, $contentMetadataInspector, $metadataFactory, ArticleInterface::class, $showDrafts);

$this->translator = $translator;
}

public function getConfiguration(): TeaserConfiguration
{
return new TeaserConfiguration(
$this->translator->trans('sulu_article.article', [], 'admin'),
$this->getResourceKey(),
'table',
['title'],
$this->translator->trans('sulu_article.single_selection_overlay_title', [], 'admin'),
);
}

/**
* @param array{
* article?: string|null,
* description?: string|null,
* } $data
*/
protected function getDescription(DimensionContentInterface $dimensionContent, array $data): ?string
{
$article = \strip_tags($data['article'] ?? '');

return $article ?: parent::getDescription($dimensionContent, $data);
}
}
37 changes: 37 additions & 0 deletions src/Infrastructure/Symfony/HttpKernel/SuluArticleBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
use Sulu\Article\Domain\Repository\ArticleRepositoryInterface;
use Sulu\Article\Infrastructure\Doctrine\Repository\ArticleRepository;
use Sulu\Article\Infrastructure\Sulu\Admin\ArticleAdmin;
use Sulu\Article\Infrastructure\Sulu\Content\ArticleLinkProvider;
use Sulu\Article\Infrastructure\Sulu\Content\ArticleTeaserProvider;
use Sulu\Article\UserInterface\Controller\Admin\ArticleController;
use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Preview\ContentObjectProvider;
use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Sitemap\ContentSitemapProvider;
use Sulu\Bundle\PersistenceBundle\DependencyInjection\PersistenceExtensionTrait;
use Sulu\Bundle\PersistenceBundle\PersistenceBundleTrait;
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
Expand Down Expand Up @@ -189,6 +192,40 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
])
->tag('sulu.context', ['context' => 'admin'])
->tag('sulu_preview.object_provider', ['provider-key' => 'articles']);

// Content
$services->set('sulu_article.article_sitemap_provider')
->class(ContentSitemapProvider::class)
->args([
new Reference('doctrine.orm.entity_manager'),
new Reference('sulu_core.webspace.webspace_manager'),
'%kernel.environment%',
ArticleInterface::class,
'%sulu.model.route.class%',
ArticleInterface::RESOURCE_KEY,
])
->tag('sulu.sitemap.provider');

$services->set('sulu_article.article_teaser_provider')
->class(ArticleTeaserProvider::class)
->args([
new Reference('sulu_content.content_manager'), // TODO teaser provider should not build on manager
new Reference('doctrine.orm.entity_manager'),
new Reference('sulu_content.content_metadata_inspector'),
new Reference('sulu_page.structure.factory'),
new Reference('translator'),
'%sulu_document_manager.show_drafts%',
])
->tag('sulu.teaser.provider', ['alias' => ArticleInterface::RESOURCE_KEY]);

$services->set('sulu_article.article_link_provider')
->class(ArticleLinkProvider::class)
->args([
new Reference('sulu_content.content_manager'), // TODO link provider should not build on manager
new Reference('sulu_page.structure.factory'),
new Reference('doctrine.orm.entity_manager'),
])
->tag('sulu.link.provider', ['alias' => ArticleInterface::RESOURCE_KEY]);
}

/**
Expand Down

0 comments on commit 46a3dff

Please sign in to comment.