From 8c36e2b956a51c5884003b0b5152e9536a67299f Mon Sep 17 00:00:00 2001 From: Nattfarinn Date: Fri, 19 Jan 2018 23:16:44 +0100 Subject: [PATCH] fix: Unify a langauge displayed across Admin aplication --- .../Controller/ContentViewController.php | 11 ++++-- src/bundle/Controller/PolicyController.php | 21 ++++++++++++ .../ContentTypeParamConverter.php | 9 +++-- src/bundle/Resources/config/services.yml | 7 ++++ .../Resources/config/services/controllers.yml | 1 + .../config/services/tabs/locationview.yml | 8 +++++ .../translations/ezrepoforms_role.en.xliff | 5 --- .../Resources/translations/role.en.xliff | 5 +++ .../views/content/locationview.html.twig | 15 ++++---- .../views/content/tab/content.html.twig | 5 +-- .../ContentTypeParamConverterTest.php | 2 +- src/lib/Form/Type/Policy/PolicyUpdateType.php | 2 +- src/lib/Tab/LocationView/ContentTab.php | 34 +++++++++++++++---- 13 files changed, 99 insertions(+), 26 deletions(-) diff --git a/src/bundle/Controller/ContentViewController.php b/src/bundle/Controller/ContentViewController.php index 7eaecd0d1c..97043cf940 100644 --- a/src/bundle/Controller/ContentViewController.php +++ b/src/bundle/Controller/ContentViewController.php @@ -46,6 +46,9 @@ class ContentViewController extends Controller /** @var int */ private $defaultPaginationLimit; + /** @var array */ + private $siteAccessLanguages; + /** * @param ContentTypeService $contentTypeService * @param LanguageService $languageService @@ -54,6 +57,7 @@ class ContentViewController extends Controller * @param SubitemsContentViewParameterSupplier $subitemsContentViewParameterSupplier * @param UserService $userService * @param int $defaultPaginationLimit + * @param array $siteAccessLanguages */ public function __construct( ContentTypeService $contentTypeService, @@ -62,7 +66,8 @@ public function __construct( FormFactory $formFactory, SubitemsContentViewParameterSupplier $subitemsContentViewParameterSupplier, UserService $userService, - int $defaultPaginationLimit + int $defaultPaginationLimit, + array $siteAccessLanguages ) { $this->contentTypeService = $contentTypeService; $this->languageService = $languageService; @@ -71,6 +76,7 @@ public function __construct( $this->subitemsContentViewParameterSupplier = $subitemsContentViewParameterSupplier; $this->userService = $userService; $this->defaultPaginationLimit = $defaultPaginationLimit; + $this->siteAccessLanguages = $siteAccessLanguages; } public function locationViewAction(Request $request, ContentView $view) @@ -117,7 +123,8 @@ private function supplyPathLocations(ContentView $view): void private function supplyContentType(ContentView $view): void { $content = $view->getContent(); - $contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId); + $contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId, $this->siteAccessLanguages); + $view->addParameters(['contentType' => $contentType]); } diff --git a/src/bundle/Controller/PolicyController.php b/src/bundle/Controller/PolicyController.php index 7b0472b9f5..6abf3cb7c4 100644 --- a/src/bundle/Controller/PolicyController.php +++ b/src/bundle/Controller/PolicyController.php @@ -166,6 +166,27 @@ public function createAction(Request $request, Role $role): Response public function updateAction(Request $request, Role $role, Policy $policy): Response { + $limitationTypes = $policy->module + ? $this->roleService->getLimitationTypesByModuleFunction($policy->module, $policy->function) + : []; + + $isEditable = !empty($limitationTypes); + + if (!$isEditable) { + $this->notificationHandler->error( + $this->translator->trans( + /** @Desc("Policy type '%policy%' does not contain limitations.") */ + 'policy.edit.no_limitations', + ['%policy%' => $policy->module . '/' . $policy->function], + 'role' + ) + ); + + return new RedirectResponse($this->generateUrl('ezplatform.role.view', [ + 'roleId' => $role->id, + ])); + } + $form = $this->formFactory->updatePolicy( new PolicyUpdateData($policy) ); diff --git a/src/bundle/ParamConverter/ContentTypeParamConverter.php b/src/bundle/ParamConverter/ContentTypeParamConverter.php index 0f80de6b3d..dc2ab8246d 100644 --- a/src/bundle/ParamConverter/ContentTypeParamConverter.php +++ b/src/bundle/ParamConverter/ContentTypeParamConverter.php @@ -22,12 +22,17 @@ class ContentTypeParamConverter implements ParamConverterInterface /** @var ContentTypeService */ private $contentTypeService; + /** @var array */ + private $siteAccessLanguages; + /** * @param ContentTypeService $contentTypeGroupService + * @param array $siteAccessLanguages */ - public function __construct(ContentTypeService $contentTypeGroupService) + public function __construct(ContentTypeService $contentTypeGroupService, array $siteAccessLanguages) { $this->contentTypeService = $contentTypeGroupService; + $this->siteAccessLanguages = $siteAccessLanguages; } /** @@ -41,7 +46,7 @@ public function apply(Request $request, ParamConverter $configuration) $id = (int)$request->get(self::PARAMETER_CONTENT_TYPE_ID); - $contentType = $this->contentTypeService->loadContentType($id); + $contentType = $this->contentTypeService->loadContentType($id, $this->siteAccessLanguages); if (!$contentType) { throw new NotFoundHttpException("ContentType $id not found!"); } diff --git a/src/bundle/Resources/config/services.yml b/src/bundle/Resources/config/services.yml index 55737a6862..77ca52eff9 100644 --- a/src/bundle/Resources/config/services.yml +++ b/src/bundle/Resources/config/services.yml @@ -30,6 +30,13 @@ services: tags: - { name: 'request.param_converter' } + EzSystems\EzPlatformAdminUiBundle\ParamConverter\ContentTypeParamConverter: + public: true + arguments: + $siteAccessLanguages: '$languages$' + tags: + - { name: 'request.param_converter' } + EzSystems\EzPlatformAdminUi\EventListener\: resource: "../../../lib/EventListener/*" public: true diff --git a/src/bundle/Resources/config/services/controllers.yml b/src/bundle/Resources/config/services/controllers.yml index 37d7e4e982..13f6cdf55c 100644 --- a/src/bundle/Resources/config/services/controllers.yml +++ b/src/bundle/Resources/config/services/controllers.yml @@ -64,3 +64,4 @@ services: parent: EzSystems\EzPlatformAdminUiBundle\Controller\Controller arguments: $defaultPaginationLimit: '$pagination.version_draft_limit$' + $siteAccessLanguages: '$languages$' diff --git a/src/bundle/Resources/config/services/tabs/locationview.yml b/src/bundle/Resources/config/services/tabs/locationview.yml index ccab4ff6c3..bc2c04766c 100644 --- a/src/bundle/Resources/config/services/tabs/locationview.yml +++ b/src/bundle/Resources/config/services/tabs/locationview.yml @@ -5,3 +5,11 @@ services: public: true tags: - { name: ezplatform.tab, group: location-view } + + EzSystems\EzPlatformAdminUi\Tab\LocationView\ContentTab: + public: true + autowire: true + arguments: + $siteAccessLanguages: '$languages$' + tags: + - { name: ezplatform.tab, group: location-view } diff --git a/src/bundle/Resources/translations/ezrepoforms_role.en.xliff b/src/bundle/Resources/translations/ezrepoforms_role.en.xliff index bc3f11a8dc..c002431ce5 100644 --- a/src/bundle/Resources/translations/ezrepoforms_role.en.xliff +++ b/src/bundle/Resources/translations/ezrepoforms_role.en.xliff @@ -31,11 +31,6 @@ All modules / All functions key: role.policy.all_modules_all_functions - - role.policy.available_limitations - role.policy.available_limitations - key: role.policy.available_limitations - Type Type diff --git a/src/bundle/Resources/translations/role.en.xliff b/src/bundle/Resources/translations/role.en.xliff index 676ef96272..9d7198a9f0 100644 --- a/src/bundle/Resources/translations/role.en.xliff +++ b/src/bundle/Resources/translations/role.en.xliff @@ -46,6 +46,11 @@ Policies in role '%role%' removed. key: policy.delete.success + + Policy type '%policy%' does not contain limitations. + Policy type '%policy%' does not contain limitations. + key: policy.edit.no_limitations + "%identifier%" Limitation "%identifier%" Limitation diff --git a/src/bundle/Resources/views/content/locationview.html.twig b/src/bundle/Resources/views/content/locationview.html.twig index 066536c54f..3948007059 100644 --- a/src/bundle/Resources/views/content/locationview.html.twig +++ b/src/bundle/Resources/views/content/locationview.html.twig @@ -25,15 +25,18 @@
{% set items = [] %} {% for pathLocation in pathLocations %} - {% set items = items|merge([{ - 'value': pathLocation.contentInfo.name, - 'url': path('_ezpublishLocation', {'locationId': pathLocation.id}) - }]) %} + {% if not loop.last %} + {% set items = items|merge([{ + 'value': pathLocation.contentInfo.name, + 'url': path('_ezpublishLocation', {'locationId': pathLocation.id}) + }]) %} + {% endif %} {% endfor %} - {% include '@EzPlatformAdminUi/parts/breadcrumbs.html.twig' with { items: items} %} + {% set items = items|merge([{ 'value': content.name }]) %} + {% include '@EzPlatformAdminUi/parts/breadcrumbs.html.twig' with { items: items } %} {% include '@EzPlatformAdminUi/parts/page_title.html.twig' with { - title: ez_content_name(content), + title: content.name, iconName: contentType.identifier, contentTypeName: contentType.name } %} diff --git a/src/bundle/Resources/views/content/tab/content.html.twig b/src/bundle/Resources/views/content/tab/content.html.twig index 488009ab73..725528abfb 100644 --- a/src/bundle/Resources/views/content/tab/content.html.twig +++ b/src/bundle/Resources/views/content/tab/content.html.twig @@ -3,12 +3,13 @@

{{ 'tab.view.content'|trans()|desc('Content') }}

+ {% set current_language = app.request.get('languageCode') ?: content.prioritizedFieldLanguageCode %} {% if languages|length > 1 %}
@@ -21,7 +22,7 @@

{{ group.name }}

{% for fieldDefinition in group.fieldDefinitions %}
-

{{ ez_field_name(content, fieldDefinition.identifier) }}:

+

{{ fieldDefinition.name }}:

{% if ez_is_field_empty(content, fieldDefinition.identifier) %} {{ 'fieldview.field.empty'|trans({}, 'fieldview')|desc('This field is empty') }} diff --git a/src/bundle/Tests/ParamConverter/ContentTypeParamConverterTest.php b/src/bundle/Tests/ParamConverter/ContentTypeParamConverterTest.php index 4592a4de79..2d2f0ff5df 100644 --- a/src/bundle/Tests/ParamConverter/ContentTypeParamConverterTest.php +++ b/src/bundle/Tests/ParamConverter/ContentTypeParamConverterTest.php @@ -28,7 +28,7 @@ public function setUp() { $this->serviceMock = $this->createMock(ContentTypeService::class); - $this->converter = new ContentTypeParamConverter($this->serviceMock); + $this->converter = new ContentTypeParamConverter($this->serviceMock, []); } public function testApply() diff --git a/src/lib/Form/Type/Policy/PolicyUpdateType.php b/src/lib/Form/Type/Policy/PolicyUpdateType.php index e8602447a4..0b2701e657 100644 --- a/src/lib/Form/Type/Policy/PolicyUpdateType.php +++ b/src/lib/Form/Type/Policy/PolicyUpdateType.php @@ -65,7 +65,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ); $form->add('limitations', CollectionType::class, [ - 'label' => 'role.policy.available_limitations', + 'label' => false, 'translation_domain' => 'ezrepoforms_role', 'entry_type' => LimitationType::class, 'data' => $this->generateLimitationList( diff --git a/src/lib/Tab/LocationView/ContentTab.php b/src/lib/Tab/LocationView/ContentTab.php index c3d223ebea..35d9146338 100644 --- a/src/lib/Tab/LocationView/ContentTab.php +++ b/src/lib/Tab/LocationView/ContentTab.php @@ -26,22 +26,28 @@ class ContentTab extends AbstractTab implements OrderedTabInterface /** @var LanguageService */ private $languageService; + /** @var array */ + private $siteAccessLanguages; + /** * @param Environment $twig * @param TranslatorInterface $translator * @param FieldsGroupsList $fieldsGroupsListHelper - * @param LanguageService $langaugeService + * @param LanguageService $languageService + * @param array $siteAccessLanguages */ public function __construct( Environment $twig, TranslatorInterface $translator, FieldsGroupsList $fieldsGroupsListHelper, - LanguageService $langaugeService + LanguageService $languageService, + array $siteAccessLanguages ) { parent::__construct($twig, $translator); $this->fieldsGroupsListHelper = $fieldsGroupsListHelper; - $this->languageService = $langaugeService; + $this->languageService = $languageService; + $this->siteAccessLanguages = $siteAccessLanguages; } public function getIdentifier(): string @@ -124,9 +130,23 @@ public function loadContentLanguages(Content $content): array return $language->enabled && in_array($language->languageCode, $contentLanguages, true); }; - return array_filter( - $this->languageService->loadLanguages(), - $filter - ); + $languagesByCode = []; + + foreach (array_filter($this->languageService->loadLanguages(), $filter) as $language) { + $languagesByCode[$language->languageCode] = $language; + } + + $saLanguages = []; + + foreach ($this->siteAccessLanguages as $languageCode) { + if (!isset($languagesByCode[$languageCode])) { + continue; + } + + $saLanguages[] = $languagesByCode[$languageCode]; + unset($languagesByCode[$languageCode]); + } + + return array_merge($saLanguages, array_values($languagesByCode)); } }