Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZEE-2111: Landing Page field is visible while creating new Page with COTF #530

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\AbstractParser;
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

/**
* Configuration parser for Admin UI forms settings.
*
* Example configuration:
* ```yaml
* ezpublish:
* system:
* admin_group: # configuration per SiteAccess or SiteAccess group
* admin_ui_forms:
* content_edit_form_templates:
* - { template: 'template.html.twig', priority: 0 }
* ```
*/
class AdminUiForms extends AbstractParser
{
const FORM_TEMPLATES_PARAM = 'admin_ui_forms.content_edit_form_templates';

/**
* Adds semantic configuration definition.
*
* @param \Symfony\Component\Config\Definition\Builder\NodeBuilder $nodeBuilder Node just under ezpublish.system.<siteaccess>
*/
public function addSemanticConfig(NodeBuilder $nodeBuilder)
{
$nodeBuilder
->arrayNode('admin_ui_forms')
->info('Admin UI forms configuration settings')
->children()
->arrayNode('content_edit_form_templates')
->info('A list of Content Edit (and create) default Twig form templates')
->arrayPrototype()
->children()
->scalarNode('template')->end()
->integerNode('priority')->end()
->end()
->end()
->end()
->end()
->end();
}

/**
* {@inheritdoc}
*/
public function mapConfig(
array &$scopeSettings,
$currentScope,
ContextualizerInterface $contextualizer
): void {
$contextualizer->setContextualParameter(
static::FORM_TEMPLATES_PARAM,
$currentScope,
$this->processContentEditFormTemplates(
$scopeSettings['admin_ui_forms']['content_edit_form_templates'] ?? []
)
);
}

/**
* Processes given prioritized list of templates, sorts them according to their priorities and
* returns as a simple list of templates.
*
* The input list of the templates needs to be in the form of:
* <code>
* [
* [ 'template' => '<file_path>', 'priority' => <int> ],
* ],
* </code>
*
* @param array $formTemplates
*
* @return array ordered list of templates
*/
private function processContentEditFormTemplates(array $formTemplates)
{
$priorities = array_column($formTemplates, 'priority');
array_multisort($priorities, SORT_DESC, $formTemplates);

// return as a simple list of templates.
return array_column($formTemplates, 'template');
}
}
12 changes: 12 additions & 0 deletions src/bundle/DependencyInjection/EzPlatformAdminUiExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function prepend(ContainerBuilder $container)
$this->prependImageVariations($container);
$this->prependUniversalDiscoveryWidget($container);
$this->prependEzDesignConfiguration($container);
$this->prependAdminUiFormsConfiguration($container);
}

/**
Expand Down Expand Up @@ -93,4 +94,15 @@ private function prependEzDesignConfiguration(ContainerBuilder $container)
$container->prependExtensionConfig('ezpublish', $config['ezpublish']);
$container->addResource(new FileResource($eZDesignConfigFile));
}

/**
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
private function prependAdminUiFormsConfiguration(ContainerBuilder $container)
{
$adminUiFormsConfigFile = __DIR__ . '/../Resources/config/admin_ui_forms.yml';
$config = Yaml::parseFile($adminUiFormsConfigFile);
$container->prependExtensionConfig('ezpublish', $config);
$container->addResource(new FileResource($adminUiFormsConfigFile));
}
}
2 changes: 2 additions & 0 deletions src/bundle/EzPlatformAdminUiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Compiler\TabPass;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Compiler\UiConfigProviderPass;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Compiler\ViewBuilderRegistryPass;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\AdminUiForms;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\ContentTranslateView;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\LocationIds;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\Module;
Expand Down Expand Up @@ -78,6 +79,7 @@ private function getConfigParsers(): array
new SubtreeOperations(),
new Notifications(),
new ContentTranslateView(),
new AdminUiForms(),
];
}
}
5 changes: 5 additions & 0 deletions src/bundle/Resources/config/admin_ui_forms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
system:
admin_group:
admin_ui_forms:
content_edit_form_templates:
- { template: '@ezdesign/content/form_fields.html.twig', priority: 0 }
7 changes: 7 additions & 0 deletions src/bundle/Resources/config/services/ui_config/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ services:
tags:
- { name: ezplatform.admin_ui.config_provider, key: 'imageVariations' }

ezsystems.ezplatform_admin_ui.ui.config.provider.content_edit_form_templates:
class: EzSystems\EzPlatformAdminUi\UI\Config\Provider\Value
arguments:
$value: '$admin_ui_forms.content_edit_form_templates$'
tags:
- { name: ezplatform.admin_ui.config_provider, key: 'contentEditFormTemplates' }

EzSystems\EzPlatformAdminUi\UI\Config\Provider\User:
tags:
- { name: ezplatform.admin_ui.config_provider, key: 'user' }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends viewbaseLayout is defined ? viewbaseLayout : '@ezdesign/layout.html.twig' %}

{% set default_form_templates = ['@ezdesign/content/form_fields.html.twig'] %}
{% set default_form_templates = admin_ui_config.contentEditFormTemplates %}
{% set form_templates = form_templates is defined ? form_templates|merge(default_form_templates) : default_form_templates %}

{% trans_default_domain 'content_edit' %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\EzPlatformAdminUiBundle\Tests\DependencyInjection\Configuration\Parser;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\AdminUiForms;
use PHPUnit\Framework\TestCase;

/**
* Test AdminUiForms SiteAccess-aware Configuration Parser.
*/
class AdminUiFormsTest extends TestCase
{
/**
* @var \EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\AdminUiForms
*/
private $parser;

/**
* @var \PHPUnit\Framework\MockObject\MockObject|\eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface
*/
private $contextualizer;

public function setUp()
{
$this->parser = new AdminUiForms();
$this->contextualizer = $this->createMock(ContextualizerInterface::class);
}

/**
* Test given Content edit form templates are sorted according to their priority when mapping.
*/
public function testContentEditFormTemplatesAreMapped()
{
$scopeSettings = [
'admin_ui_forms' => [
'content_edit_form_templates' => [
['template' => 'my_template-01.html.twig', 'priority' => 1],
['template' => 'my_template-02.html.twig', 'priority' => 0],
['template' => 'my_template-03.html.twig', 'priority' => 2],
],
],
];
$currentScope = 'admin_group';

$expectedTemplatesList = [
'my_template-03.html.twig',
'my_template-01.html.twig',
'my_template-02.html.twig',
];

$this->contextualizer
->expects($this->once())
->method('setContextualParameter')
->with(
AdminUiForms::FORM_TEMPLATES_PARAM,
$currentScope,
$expectedTemplatesList
);

$this->parser->mapConfig($scopeSettings, $currentScope, $this->contextualizer);
}
}