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

EZP-29757: As an administrator, I want to be able to translate a content type #730

Merged
merged 26 commits into from Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
326dc39
EZP-29757: As an administrator, I want to be able to translate a cont…
ViniTou Nov 30, 2018
691815c
EZP-29757: Code review fixes - backend
ViniTou Dec 7, 2018
3706fcf
EZP-29757: code review fixes - frontend
ViniTou Dec 7, 2018
e18f175
EZP-29757: code review fixes - phpdocs
ViniTou Dec 7, 2018
7f7f30b
Fix HTML structure
tischsoic Dec 7, 2018
b5b4b7b
EZP-29757: Add missing menu translation
ViniTou Dec 7, 2018
e85a050
EZP-29757: Fix for wrong action form url
ViniTou Dec 10, 2018
723a2a8
Style content type tabs
tischsoic Dec 10, 2018
d1c8f8c
EZP-29757: Code review fixes
ViniTou Dec 10, 2018
2c24411
Update src/bundle/Controller/ContentTypeController.php
adamwojs Dec 10, 2018
17bdc1f
Update src/lib/Form/Factory/ContentTypeFormFactory.php
adamwojs Dec 10, 2018
d866b98
Update src/bundle/Resources/views/admin/content_type/tab/view.html.twig
adamwojs Dec 10, 2018
3038b56
Update src/bundle/Resources/views/admin/content_type/edit.html.twig
adamwojs Dec 10, 2018
c4c57bf
Update src/lib/Form/Factory/ContentTypeFormFactory.php
adamwojs Dec 10, 2018
952e964
EZP-29757: cs fix
ViniTou Dec 10, 2018
ea8d27a
EZP-29757: Change css class for navbar
ViniTou Dec 11, 2018
4535e87
EZP-29757: Change include from ezdesign to EzPlatformAdminUi
ViniTou Dec 11, 2018
00aceaa
Fix HTML structure
tischsoic Dec 11, 2018
bcd3b69
Fix Edit button extra actions - Select language
tischsoic Dec 13, 2018
6ebf75a
EZP-29757: Add missing info about translation
ViniTou Dec 14, 2018
f191b95
EZP-29887: Fix for translator language selector
ViniTou Dec 14, 2018
65f93e3
EZP-29757: Change how fields are disabled when translating content type
ViniTou Dec 14, 2018
94896f4
EZP-29757: Disable buttons on missing class create policy
ViniTou Dec 14, 2018
5655610
EZP-29757: Content Type translations in COTF
ViniTou Dec 14, 2018
fba0786
EZP-29757: cs fixes
ViniTou Dec 14, 2018
9e5b4bb
EZP-29757: remove unused properties
ViniTou Dec 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
328 changes: 288 additions & 40 deletions src/bundle/Controller/ContentTypeController.php

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions src/bundle/ParamConverter/ContentTypeParamConverter.php
Expand Up @@ -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) {
Expand Down
29 changes: 20 additions & 9 deletions src/bundle/ParamConverter/LanguageParamConverter.php
Expand Up @@ -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;
Expand All @@ -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)
{
Expand All @@ -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);
Expand Down
76 changes: 76 additions & 0 deletions src/bundle/ParamConverter/TranslationLanguageParamConverter.php
@@ -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;
}
}
21 changes: 18 additions & 3 deletions src/bundle/Resources/config/routing.yml
Expand Up @@ -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+

Expand All @@ -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
#
Expand Down
3 changes: 2 additions & 1 deletion src/bundle/Resources/config/services/forms.yml
Expand Up @@ -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'
Expand Down
5 changes: 5 additions & 0 deletions src/bundle/Resources/config/services/menu.yml
Expand Up @@ -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 change: 1 addition & 0 deletions src/bundle/Resources/config/services/tabs.yml
@@ -1,5 +1,6 @@
imports:
- { resource: tabs/locationview.yml }
- { resource: tabs/content_type.yml }

services:
_defaults:
Expand Down
7 changes: 7 additions & 0 deletions src/bundle/Resources/config/services/tabs/content_type.yml
@@ -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);
3 changes: 2 additions & 1 deletion src/bundle/Resources/public/scss/_tabs.scss
Expand Up @@ -50,7 +50,8 @@
}
}

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

Expand Down
20 changes: 20 additions & 0 deletions src/bundle/Resources/translations/content_type.en.xliff
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
5 changes: 5 additions & 0 deletions src/bundle/Resources/translations/menu.en.xliff
Expand Up @@ -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>
Expand Down
12 changes: 9 additions & 3 deletions src/bundle/Resources/views/admin/content_type/edit.html.twig
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand All @@ -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">
Expand Down
@@ -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
} %}