Skip to content
Permalink
Browse files

EZP-29757: As an administrator, I want to be able to translate a cont…

…ent type (#730)

* EZP-29757: As an administrator, I want to be able to translate a content type (AdminUI frontend)

* EZP-29757: Code review fixes - backend

* EZP-29757: code review fixes - frontend

* EZP-29757: code review fixes - phpdocs

* Fix HTML structure

* EZP-29757: Add missing menu translation

* EZP-29757: Fix for wrong action form url

* Style content type tabs

* EZP-29757: Code review fixes

* Update src/bundle/Controller/ContentTypeController.php

Co-Authored-By: ViniTou <vinniczek@gmail.com>

* Update src/lib/Form/Factory/ContentTypeFormFactory.php

Co-Authored-By: ViniTou <vinniczek@gmail.com>

* Update src/bundle/Resources/views/admin/content_type/tab/view.html.twig

Co-Authored-By: ViniTou <vinniczek@gmail.com>

* Update src/bundle/Resources/views/admin/content_type/edit.html.twig

Co-Authored-By: ViniTou <vinniczek@gmail.com>

* Update src/lib/Form/Factory/ContentTypeFormFactory.php

Co-Authored-By: ViniTou <vinniczek@gmail.com>

* EZP-29757: cs fix

* EZP-29757: Change css class for navbar

* EZP-29757: Change include from ezdesign to EzPlatformAdminUi

* Fix HTML structure

* Fix Edit button extra actions - Select language

* EZP-29757: Add missing info about translation

* EZP-29887: Fix for translator language selector

* EZP-29757: Change how fields are disabled when translating content type

* EZP-29757: Disable buttons on missing class create policy

* EZP-29757: Content Type translations in COTF

* EZP-29757: cs fixes

* EZP-29757: remove unused properties
  • Loading branch information...
ViniTou authored and lserwatka committed Dec 14, 2018
1 parent 9196c1c commit cfb4806425d6da41a3ee5f93094dafa4b75e1669
Showing with 2,078 additions and 216 deletions.
  1. +288 −40 src/bundle/Controller/ContentTypeController.php
  2. +9 −2 src/bundle/ParamConverter/ContentTypeParamConverter.php
  3. +20 −9 src/bundle/ParamConverter/LanguageParamConverter.php
  4. +76 −0 src/bundle/ParamConverter/TranslationLanguageParamConverter.php
  5. +18 −3 src/bundle/Resources/config/routing.yml
  6. +2 −1 src/bundle/Resources/config/services/forms.yml
  7. +5 −0 src/bundle/Resources/config/services/menu.yml
  8. +1 −0 src/bundle/Resources/config/services/tabs.yml
  9. +7 −0 src/bundle/Resources/config/services/tabs/content_type.yml
  10. +21 −0 src/bundle/Resources/public/js/scripts/sidebar/btn/contenttype.edit.js
  11. +2 −1 src/bundle/Resources/public/scss/_tabs.scss
  12. +20 −0 src/bundle/Resources/translations/content_type.en.xliff
  13. +5 −0 src/bundle/Resources/translations/menu.en.xliff
  14. +9 −3 src/bundle/Resources/views/admin/content_type/edit.html.twig
  15. +3 −0 src/bundle/Resources/views/admin/content_type/modal_add_translation.html.twig
  16. +9 −0 src/bundle/Resources/views/admin/content_type/parts/nontranslatable_fields_disabled.html.twig
  17. +8 −0 src/bundle/Resources/views/admin/content_type/tab/translations.html.twig
  18. +126 −0 src/bundle/Resources/views/admin/content_type/tab/view.html.twig
  19. +18 −120 src/bundle/Resources/views/admin/content_type/view.html.twig
  20. +23 −0 src/bundle/Resources/views/admin/content_type/widgets/content_type_edit.html.twig
  21. +2 −1 src/bundle/Resources/views/content/modal_add_translation.html.twig
  22. +46 −29 src/bundle/Resources/views/content/tab/translations/tab.html.twig
  23. +68 −0 src/bundle/Resources/views/parts/tab/content_type.html.twig
  24. +88 −0 src/lib/Form/Data/ContentType/ContentTypeEditData.php
  25. +141 −0 src/lib/Form/Data/ContentType/Translation/TranslationAddData.php
  26. +108 −0 src/lib/Form/Data/ContentType/Translation/TranslationRemoveData.php
  27. +81 −0 src/lib/Form/Factory/ContentTypeFormFactory.php
  28. +1 −7 src/lib/Form/Factory/FormFactory.php
  29. +44 −0 src/lib/Form/Type/ChoiceList/Loader/AvailableTranslationLanguageChoiceLoader.php
  30. +63 −0 src/lib/Form/Type/ChoiceList/Loader/BaseChoiceLoader.php
  31. +44 −0 src/lib/Form/Type/ChoiceList/Loader/BaseTranslationLanguageChoiceLoader.php
  32. +105 −0 src/lib/Form/Type/ContentType/ContentTypeEditType.php
  33. +208 −0 src/lib/Form/Type/ContentType/Translation/TranslationAddType.php
  34. +75 −0 src/lib/Form/Type/ContentType/Translation/TranslationRemoveType.php
  35. +104 −0 src/lib/Menu/ContentTypeRightSidebarBuilder.php
  36. +1 −0 src/lib/Menu/Event/ConfigureMenuEvent.php
  37. +124 −0 src/lib/Tab/ContentType/TranslationsTab.php
  38. +60 −0 src/lib/Tab/ContentType/ViewTab.php
  39. +25 −0 src/lib/UI/Dataset/TranslationsDataset.php
  40. +20 −0 src/lib/UI/Value/ValueFactory.php

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -44,13 +44,20 @@ public function apply(Request $request, ParamConverter $configuration)
if (!$request->get(self::PARAMETER_CONTENT_TYPE_ID) && !$request->get(self::PARAMETER_CONTENT_TYPE_IDENTIFIER)) {
return false;
}
$prioritizedLanguages = $this->siteAccessLanguages;
if ($request->get(LanguageParamConverter::PARAMETER_LANGUAGE_CODE)) {
array_unshift(
$prioritizedLanguages,
$request->get(LanguageParamConverter::PARAMETER_LANGUAGE_CODE)
);
}
if ($request->get(self::PARAMETER_CONTENT_TYPE_ID)) {
$id = (int)$request->get(self::PARAMETER_CONTENT_TYPE_ID);
$contentType = $this->contentTypeService->loadContentType($id, $this->siteAccessLanguages);
$contentType = $this->contentTypeService->loadContentType($id, $prioritizedLanguages);
} elseif ($request->get(self::PARAMETER_CONTENT_TYPE_IDENTIFIER)) {
$identifier = $request->get(self::PARAMETER_CONTENT_TYPE_IDENTIFIER);
$contentType = $this->contentTypeService->loadContentTypeByIdentifier($identifier, $this->siteAccessLanguages);
$contentType = $this->contentTypeService->loadContentTypeByIdentifier($identifier, $prioritizedLanguages);
}
if (!$contentType) {
@@ -8,6 +8,7 @@
namespace EzSystems\EzPlatformAdminUiBundle\ParamConverter;
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
use eZ\Publish\API\Repository\LanguageService;
use eZ\Publish\API\Repository\Values\Content\Language;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
@@ -18,14 +19,13 @@
class LanguageParamConverter implements ParamConverterInterface
{
const PARAMETER_LANGUAGE_ID = 'languageId';
const PARAMETER_LANGUAGE_CODE = 'languageCode';
/** @var LanguageService */
/** @var \eZ\Publish\API\Repository\LanguageService */
private $languageService;
/**
* LanguageParamConverter constructor.
*
* @param LanguageService $languageService
* @param \eZ\Publish\API\Repository\LanguageService $languageService
*/
public function __construct(LanguageService $languageService)
{
@@ -37,15 +37,26 @@ public function __construct(LanguageService $languageService)
*/
public function apply(Request $request, ParamConverter $configuration)
{
if (!$request->get(self::PARAMETER_LANGUAGE_ID)) {
if (!$request->get(self::PARAMETER_LANGUAGE_ID) && !$request->get(self::PARAMETER_LANGUAGE_CODE)) {
return false;
}
$id = (int)$request->get(self::PARAMETER_LANGUAGE_ID);
if ($request->get(self::PARAMETER_LANGUAGE_ID)) {
$id = (int)$request->get(self::PARAMETER_LANGUAGE_ID);
$language = $this->languageService->loadLanguageById($id);
if (!$language) {
throw new NotFoundHttpException("Language $id not found!");
try {
$language = $this->languageService->loadLanguageById($id);
} catch (NotFoundException $e) {
throw new NotFoundHttpException("Language $id not found!");
}
} elseif ($request->get(self::PARAMETER_LANGUAGE_CODE)) {
$languageCode = $request->get(self::PARAMETER_LANGUAGE_CODE);
try {
$language = $this->languageService->loadLanguage($languageCode);
} catch (NotFoundException $e) {
throw new NotFoundHttpException("Language $languageCode not found!");
}
}
$request->attributes->set($configuration->getName(), $language);
@@ -0,0 +1,76 @@
<?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\ParamConverter;
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
use eZ\Publish\API\Repository\LanguageService;
use eZ\Publish\API\Repository\Values\Content\Language;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class TranslationLanguageParamConverter implements ParamConverterInterface
{
const PARAMETER_LANGUAGE_CODE_TO = 'toLanguageCode';
const PARAMETER_LANGUAGE_CODE_FROM = 'fromLanguageCode';
/** @var \eZ\Publish\API\Repository\LanguageService */
private $languageService;
/**
* @param \eZ\Publish\API\Repository\LanguageService $languageService
*/
public function __construct(LanguageService $languageService)
{
$this->languageService = $languageService;
}
/**
* {@inheritdoc}
*/
public function apply(Request $request, ParamConverter $configuration)
{
if ($request->get(self::PARAMETER_LANGUAGE_CODE_TO) && 'language' === $configuration->getName()) {
$languageCode = $request->get(self::PARAMETER_LANGUAGE_CODE_TO);
} elseif ($request->get(self::PARAMETER_LANGUAGE_CODE_FROM) && 'baseLanguage' === $configuration->getName()) {
$languageCode = $request->get(self::PARAMETER_LANGUAGE_CODE_FROM);
} else {
return false;
}
$request->attributes->set($configuration->getName(), $this->getLanguage($languageCode));
return true;
}
/**
* {@inheritdoc}
*/
public function supports(ParamConverter $configuration)
{
return Language::class === $configuration->getClass();
}
/**
* @param string $languageCode
*
* @return \eZ\Publish\API\Repository\Values\Content\Language
*/
private function getLanguage(string $languageCode): Language
{
try {
$language = $this->languageService->loadLanguage($languageCode);
} catch (NotFoundException $e) {
throw new NotFoundHttpException("Language $languageCode not found!");
}
return $language;
}
}
@@ -346,17 +346,19 @@ ezplatform.content_type.add:

ezplatform.content_type.edit:
path: /contenttypegroup/{contentTypeGroupId}/contenttype/{contentTypeId}/edit
methods: ['GET']
methods: ['GET', 'POST']
defaults:
_controller: 'EzPlatformAdminUiBundle:ContentType:edit'
requirements:
contentTypeGroupId: \d+

ezplatform.content_type.update:
path: /contenttypegroup/{contentTypeGroupId}/contenttype/{contentTypeId}/update
path: /contenttypegroup/{contentTypeGroupId}/contenttype/{contentTypeId}/update/{toLanguageCode}/{fromLanguageCode}
methods: ['GET', 'POST']
defaults:
_controller: 'EzPlatformAdminUiBundle:ContentType:update'
toLanguageCode: ~
fromLanguageCode: ~
requirements:
contentTypeGroupId: \d+

@@ -377,13 +379,26 @@ ezplatform.content_type.bulk_delete:
contentTypeGroupId: \d+

ezplatform.content_type.view:
path: /contenttypegroup/{contentTypeGroupId}/contenttype/{contentTypeId}
path: /contenttypegroup/{contentTypeGroupId}/contenttype/{contentTypeId}/{languageCode}
methods: ['GET']
defaults:
_controller: 'EzPlatformAdminUiBundle:ContentType:view'
languageCode: null
requirements:
contentTypeGroupId: \d+

ezplatform.content_type.add_translation:
path: /content-type/translation/add
methods: ['POST']
defaults:
_controller: 'EzPlatformAdminUiBundle:ContentType:addTranslation'

ezplatform.content_type.remove_translation:
path: /content-type/translation/remove
methods: ['POST']
defaults:
_controller: 'EzPlatformAdminUiBundle:ContentType:removeTranslation'

#
# Location View
#
@@ -6,7 +6,8 @@ services:

EzSystems\EzPlatformAdminUi\Form\SubmitHandler: ~

EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory: ~
EzSystems\EzPlatformAdminUi\Form\Factory\:
resource: '../../../lib/Form/Factory'

EzSystems\EzPlatformAdminUi\Form\DataMapper\:
resource: '../../../lib/Form/DataMapper'
@@ -162,3 +162,8 @@ services:
EzSystems\EzPlatformAdminUi\Menu\Admin\ReorderMenuListener:
tags:
- { name: kernel.event_listener, event: ezplatform_admin_ui.menu_configure.main_menu, method: moveAdminToLast, priority: -50 }

EzSystems\EzPlatformAdminUi\Menu\ContentTypeRightSidebarBuilder:
public: true
tags:
- { name: knp_menu.menu_builder, method: build, alias: ezplatform_admin_ui.menu.content_type.sidebar_right }
@@ -1,5 +1,6 @@
imports:
- { resource: tabs/locationview.yml }
- { resource: tabs/content_type.yml }

services:
_defaults:
@@ -0,0 +1,7 @@
services:
EzSystems\EzPlatformAdminUi\Tab\ContentType\:
resource: "../../../lib/Tab/ContentType/*"
parent: EzSystems\EzPlatformAdminUi\Tab\AbstractEventDispatchingTab
public: true
tags:
- { name: ezplatform.tab, group: content-type }
@@ -0,0 +1,21 @@
(function (global, doc) {
const editButton = doc.querySelector('.ez-btn--edit');
const languageRadioOption = doc.querySelector('.ez-extra-actions--edit.ez-extra-actions--prevent-show [type="radio"]');
const editActions = doc.querySelector('.ez-extra-actions--edit')
const btns = [...editActions.querySelectorAll('.form-check [type="radio"]')];
const changeHandler = () => {
const form = doc.querySelector('.ez-extra-actions--edit form');
form.submit()
};

btns.forEach((btn) => btn.addEventListener('change', changeHandler, false));

if (!languageRadioOption) {
return;
}

editButton.addEventListener('click', () => {
languageRadioOption.checked = true;
changeHandler();
}, false);
})(window, document);
@@ -50,7 +50,8 @@
}
}

.nav-tabs-systeminfo {
.nav-tabs-systeminfo,
.ez-nav-tabs--content-type {
border-bottom: none;
}

@@ -86,6 +86,11 @@
<target state="new">Draft of the Content Type '%name%' already exists and is locked by '%userContentName%'</target>
<note>key: content_type.edit.error.already_exists</note>
</trans-unit>
<trans-unit id="f0338ef34826caa021c41ff85413e48601af30b7" resname="content_type.edit.select_language">
<source>Select language</source>
<target state="new">Select language</target>
<note>key: content_type.edit.select_language</note>
</trans-unit>
<trans-unit id="9eb89a2f51954babc5ff51f9060cbcda91dcf408" resname="content_type.field_definitions.modal.message">
<source>Do you want to delete selected field definitions?</source>
<target state="new">Do you want to delete selected field definitions?</target>
@@ -216,6 +221,11 @@
<target state="new">Global properties</target>
<note>key: content_type.view.edit.global_properties</note>
</trans-unit>
<trans-unit id="36fb0205d165f72c996205435b5a06ba42695bb6" resname="content_type.view.edit.notranslatable_fields_disabled">
<source>Some of the fields are disabled when translating a Content Type. To modify them, please edit the Content Type in the main language</source>
<target state="new">Some of the fields are disabled when translating a Content Type. To modify them, please edit the Content Type in the main language</target>
<note>key: content_type.view.edit.notranslatable_fields_disabled</note>
</trans-unit>
<trans-unit id="7eee653a60490713df6bcf4b847853020b79a1ee" resname="content_type.view.edit.title">
<source>Editing Content Type: %name%</source>
<target state="new">Editing Content Type: %name%</target>
@@ -401,6 +411,16 @@
<target state="new">Delete</target>
<note>key: modal.delete</note>
</trans-unit>
<trans-unit id="0b83b391386f47130b2d3ac1869fe27aa8c45fb7" resname="tab.name.translations">
<source>Translations</source>
<target state="new">Translations</target>
<note>key: tab.name.translations</note>
</trans-unit>
<trans-unit id="eb3b504a0281951f15692e888226579aa99bb512" resname="tab.name.view">
<source>View</source>
<target state="new">View</target>
<note>key: tab.name.view</note>
</trans-unit>
<trans-unit id="3e9deeb426f08a404990a6926d70558955272593" resname="yes_no">
<source>{0}No|{1}Yes</source>
<target state="new">{0}No|{1}Yes</target>
@@ -81,6 +81,11 @@
<target state="new">Save</target>
<note>key: content_edit__sidebar_right__save_draft</note>
</trans-unit>
<trans-unit id="3b59d1cdd9c85ff781a3a442345bb648cc49dd31" resname="content_type__sidebar_right__edit">
<source>Edit</source>
<target state="new">Edit</target>
<note>key: content_type__sidebar_right__edit</note>
</trans-unit>
<trans-unit id="750939fc55f9a3143db99bed66680e8646e029a0" resname="content_type_create__sidebar_right__cancel">
<source>Discard changes</source>
<target state="new">Discard changes</target>
@@ -23,7 +23,11 @@

{% block form %}
{{ form_start(form) }}
{% set language_code = language_code|default(content_type.mainLanguageCode) %}

{% if language_code != content_type.mainLanguageCode %}
{% include '@ezdesign/admin/content_type/parts/nontranslatable_fields_disabled.html.twig' %}
{% endif %}
<section class="container mt-4 px-5">
<div class="card ez-card">
<div class="ez-card__header ez-card__header--secondary">
@@ -59,7 +63,9 @@
title="{{ 'content_type.view.edit.content_field_definition.delete'|trans|desc('Delete Content field definition') }}"
class="btn btn-danger"
data-toggle="modal"
data-target="#delete-content-type-modal">
data-target="#delete-content-type-modal"
{% if form.addFieldDefinition.vars.disabled %}disabled{% endif %}
>
<svg class="ez-icon">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#trash"></use>
</svg>
@@ -70,14 +76,14 @@
{% include '@ezdesign/admin/content_type/delete_confirmation_modal.html.twig' with {'form': form} %}

<div class="card-body">
{% set language_code = content_type.mainLanguageCode %}
{% for field_definition in form.fieldDefinitionsData %}
{% set value = field_definition.vars.value %}

<div class="card ez-card ez-card--fieldtype-container mb-3 ez-card--collapsed">
<div id="field-definition-{{ value.identifier }}" class="ez-card__header ez-card__header--secondary">
{% set name = value.names[language_code] ?? value.names[content_type.mainLanguageCode] %}
{{ form_widget(field_definition.selected, {
'label': '%s (%s)' | format(value.names[language_code], value.fieldTypeIdentifier),
'label': '%s (%s)'|format(name, value.fieldTypeIdentifier),
'label_attr': {'class': 'checkbox-inline'}
}) }}
<button class="ez-card__body-display-toggler btn">
@@ -0,0 +1,3 @@
{% include '@EzPlatformAdminUi/content/modal_add_translation.html.twig' with {
action : path('ezplatform.content_type.add_translation')
} %}
@@ -0,0 +1,9 @@
{% trans_default_domain 'content_type' %}

<div class="alert alert-info mt-3 mx-5 ez-alert ez-alert--info" role="alert">
<svg class="ez-icon ez-icon--small ez-icon-warning">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#warning"></use>
</svg>

{{ 'content_type.view.edit.notranslatable_fields_disabled'|trans|desc('Some of the fields are disabled when translating a Content Type. To modify them, please edit the Content Type in the main language') }}
</div>
@@ -0,0 +1,8 @@
{% block modal_add_translation %}
{% include '@ezdesign/admin/content_type/modal_add_translation.html.twig' with {'form': form_translation_add} only %}
{% endblock %}

{% include '@ezdesign/content/tab/translations/tab.html.twig' with {
can_translate : can_translate
} %}

Oops, something went wrong.

0 comments on commit cfb4806

Please sign in to comment.
You can’t perform that action at this time.