Skip to content

Commit

Permalink
Merge pull request #319 from ezsystems/ezp-admin-translations
Browse files Browse the repository at this point in the history
fix: Unify a langauge displayed across Admin aplication
  • Loading branch information
Łukasz Serwatka committed Jan 22, 2018
2 parents 9ed909d + 8c36e2b commit 4754bc9
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 26 deletions.
11 changes: 9 additions & 2 deletions src/bundle/Controller/ContentViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class ContentViewController extends Controller
/** @var int */
private $defaultPaginationLimit;

/** @var array */
private $siteAccessLanguages;

/**
* @param ContentTypeService $contentTypeService
* @param LanguageService $languageService
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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]);
}

Expand Down
21 changes: 21 additions & 0 deletions src/bundle/Controller/PolicyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down
9 changes: 7 additions & 2 deletions src/bundle/ParamConverter/ContentTypeParamConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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!");
}
Expand Down
7 changes: 7 additions & 0 deletions src/bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/bundle/Resources/config/services/controllers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ services:
parent: EzSystems\EzPlatformAdminUiBundle\Controller\Controller
arguments:
$defaultPaginationLimit: '$pagination.version_draft_limit$'
$siteAccessLanguages: '$languages$'
8 changes: 8 additions & 0 deletions src/bundle/Resources/config/services/tabs/locationview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
5 changes: 0 additions & 5 deletions src/bundle/Resources/translations/ezrepoforms_role.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
<target state="new">All modules / All functions</target>
<note>key: role.policy.all_modules_all_functions</note>
</trans-unit>
<trans-unit id="2a8bdc606cd0c96a53e2f661f0585029840af4b9" resname="role.policy.available_limitations">
<source>role.policy.available_limitations</source>
<target state="new">role.policy.available_limitations</target>
<note>key: role.policy.available_limitations</note>
</trans-unit>
<trans-unit id="d3c70d265ab037db5ade02a8b738b5981353c7ac" resname="role.policy.type">
<source>Type</source>
<target state="new">Type</target>
Expand Down
5 changes: 5 additions & 0 deletions src/bundle/Resources/translations/role.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
<target state="new">Policies in role '%role%' removed.</target>
<note>key: policy.delete.success</note>
</trans-unit>
<trans-unit id="9c322357fb302e5b708bc1c11c287d8a4e4859ec" resname="policy.edit.no_limitations">
<source>Policy type '%policy%' does not contain limitations.</source>
<target state="new">Policy type '%policy%' does not contain limitations.</target>
<note>key: policy.edit.no_limitations</note>
</trans-unit>
<trans-unit id="41bcfef149f877e1abb0ce2cd2aa5afb713ea1de" resname="policy.limitation.identifier_tooltip">
<source>"%identifier%" Limitation</source>
<target state="new">"%identifier%" Limitation</target>
Expand Down
15 changes: 9 additions & 6 deletions src/bundle/Resources/views/content/locationview.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@
<div class="container">
{% 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
} %}
Expand Down
5 changes: 3 additions & 2 deletions src/bundle/Resources/views/content/tab/content.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
<h2>
{{ 'tab.view.content'|trans()|desc('Content') }}
</h2>
{% set current_language = app.request.get('languageCode') ?: content.prioritizedFieldLanguageCode %}
{% if languages|length > 1 %}
<form class="form-inline">
<select class="form-control ez-location-language-change">
{% for language in languages %}
<option value="{{ path('_ezpublishLocation', {'locationId': location.id, 'languageCode': language.languageCode}) }}"
{% if app.request.get('languageCode') == language.languageCode %} selected="selected" {% endif %}
{% if current_language == language.languageCode %} selected="selected" {% endif %}
>{{ language.name }}</option>
{% endfor %}
</select>
Expand All @@ -21,7 +22,7 @@
<h3 class="ez-fieldgroup-name">{{ group.name }}</h3>
{% for fieldDefinition in group.fieldDefinitions %}
<div class="ez-content-field">
<p class="ez-content-field-name">{{ ez_field_name(content, fieldDefinition.identifier) }}:</p>
<p class="ez-content-field-name">{{ fieldDefinition.name }}:</p>
<div class="ez-content-field-value">
{% if ez_is_field_empty(content, fieldDefinition.identifier) %}
<em>{{ 'fieldview.field.empty'|trans({}, 'fieldview')|desc('This field is empty') }}</em>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Form/Type/Policy/PolicyUpdateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
34 changes: 27 additions & 7 deletions src/lib/Tab/LocationView/ContentTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
}

0 comments on commit 4754bc9

Please sign in to comment.