Skip to content

Commit

Permalink
Deep link for reference article field types
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Apr 28, 2020
1 parent 84a9dad commit a4b417b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 46 deletions.
1 change: 1 addition & 0 deletions Content/ArticleDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ protected function getConfigurationBuilder(): BuilderInterface
]
);

// for sulu versions < 2.1 the enableView does not exist
if (method_exists($builder, 'enableView')) {
$builder->enableView(ArticleAdmin::EDIT_FORM_VIEW, ['id' => 'id']);
}
Expand Down
107 changes: 62 additions & 45 deletions DependencyInjection/SuluArticleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Sulu\Bundle\ArticleBundle\DependencyInjection;

use Sulu\Bundle\ArticleBundle\Admin\ArticleAdmin;
use Sulu\Bundle\ArticleBundle\Document\ArticleDocument;
use Sulu\Bundle\ArticleBundle\Document\ArticlePageDocument;
use Sulu\Bundle\ArticleBundle\Document\Form\ArticleDocumentType;
Expand All @@ -19,6 +20,7 @@
use Sulu\Bundle\ArticleBundle\Document\Structure\ArticlePageBridge;
use Sulu\Bundle\ArticleBundle\Exception\ArticlePageNotFoundException;
use Sulu\Bundle\ArticleBundle\Exception\ParameterNotAllowedException;
use Sulu\Component\SmartContent\Configuration\BuilderInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
Expand Down Expand Up @@ -174,62 +176,77 @@ public function prepend(ContainerBuilder $container)
}

if ($container->hasExtension('sulu_admin')) {
$container->prependExtensionConfig(
'sulu_admin',
[
'lists' => [
'directories' => [
__DIR__ . '/../Resources/config/lists',
],
$suluAdminConfig = [
'lists' => [
'directories' => [
__DIR__ . '/../Resources/config/lists',
],
'forms' => [
'directories' => [
__DIR__ . '/../Resources/config/forms',
],
],
'forms' => [
'directories' => [
__DIR__ . '/../Resources/config/forms',
],
'resources' => [
'articles' => [
'routes' => [
'list' => 'sulu_article.get_articles',
'detail' => 'sulu_article.get_article',
],
],
'resources' => [
'articles' => [
'routes' => [
'list' => 'sulu_article.get_articles',
'detail' => 'sulu_article.get_article',
],
],
'field_type_options' => [
'selection' => [
'article_selection' => [
'default_type' => 'list_overlay',
'resource_key' => 'articles',
'types' => [
'list_overlay' => [
'adapter' => 'table',
'list_key' => 'articles',
'display_properties' => ['title', 'routePath'],
'icon' => 'su-newspaper',
'label' => 'sulu_article.selection_label',
'overlay_title' => 'sulu_article.selection_overlay_title',
],
],
'field_type_options' => [
'selection' => [
'article_selection' => [
'default_type' => 'list_overlay',
'resource_key' => 'articles',
'types' => [
'list_overlay' => [
'adapter' => 'table',
'list_key' => 'articles',
'display_properties' => ['title', 'routePath'],
'icon' => 'su-newspaper',
'label' => 'sulu_article.selection_label',
'overlay_title' => 'sulu_article.selection_overlay_title',
],
],
],
'single_selection' => [
'single_article_selection' => [
'default_type' => 'list_overlay',
'resource_key' => 'articles',
'types' => [
'list_overlay' => [
'adapter' => 'table',
'list_key' => 'articles',
'display_properties' => ['title'],
'empty_text' => 'sulu_article.no_article_selected',
'icon' => 'su-newspaper',
'overlay_title' => 'sulu_article.single_selection_overlay_title',
],
],
'single_selection' => [
'single_article_selection' => [
'default_type' => 'list_overlay',
'resource_key' => 'articles',
'types' => [
'list_overlay' => [
'adapter' => 'table',
'list_key' => 'articles',
'display_properties' => ['title'],
'empty_text' => 'sulu_article.no_article_selected',
'icon' => 'su-newspaper',
'overlay_title' => 'sulu_article.single_selection_overlay_title',
],
],
],
],
]
],
];

$articleViewConfig = [
'name' => ArticleAdmin::EDIT_FORM_VIEW,
'result_to_view' => [
'id' => 'id',
],
];

// for sulu versions < 2.1 the view config does not exist and will fail
if (method_exists(BuilderInterface::class, 'enableView')) {
$suluAdminConfig['field_type_options']['selection']['article_selection']['view'] = $articleViewConfig;
$suluAdminConfig['field_type_options']['single_selection']['single_article_selection']['view'] = $articleViewConfig;
}

$container->prependExtensionConfig(
'sulu_admin',
$suluAdminConfig
);
}

Expand Down
5 changes: 4 additions & 1 deletion Teaser/ArticleTeaserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use ONGR\ElasticsearchBundle\Service\Manager;
use ONGR\ElasticsearchDSL\Query\TermLevel\IdsQuery;
use Sulu\Bundle\ArticleBundle\Admin\ArticleAdmin;
use Sulu\Bundle\ArticleBundle\Document\ArticleViewDocument;
use Sulu\Bundle\ArticleBundle\Metadata\ArticleViewDocumentIdTrait;
use Sulu\Bundle\PageBundle\Teaser\Configuration\TeaserConfiguration;
Expand Down Expand Up @@ -59,7 +60,9 @@ public function getConfiguration()
'articles',
'table',
['title'],
$this->translator->trans('sulu_article.single_selection_overlay_title', [], 'admin')
$this->translator->trans('sulu_article.single_selection_overlay_title', [], 'admin'),
ArticleAdmin::EDIT_FORM_VIEW,
['id' => 'id']
);
}

Expand Down

0 comments on commit a4b417b

Please sign in to comment.