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-29990: As an Administrator I want to translate ezselection Field Definition options #824

Merged
merged 5 commits into from
Feb 25, 2019
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
9 changes: 7 additions & 2 deletions src/bundle/Controller/ContentTypeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class ContentTypeController extends Controller
/** @var \EzSystems\EzPlatformAdminUi\Form\Factory\ContentTypeFormFactory */
private $contentTypeFormFactory;

/** @var \EzSystems\RepositoryForms\Data\Mapper\ContentTypeDraftMapper */
private $contentTypeDraftMapper;

/**
* @param \EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface $notificationHandler
* @param \Symfony\Component\Translation\TranslatorInterface $translator
Expand All @@ -99,7 +102,8 @@ public function __construct(
int $defaultPaginationLimit,
UserService $userService,
LanguageService $languageService,
ContentTypeFormFactory $contentTypeFormFactory
ContentTypeFormFactory $contentTypeFormFactory,
ContentTypeDraftMapper $contentTypeDraftMapper
) {
$this->notificationHandler = $notificationHandler;
$this->translator = $translator;
Expand All @@ -112,6 +116,7 @@ public function __construct(
$this->userService = $userService;
$this->languageService = $languageService;
$this->contentTypeFormFactory = $contentTypeFormFactory;
$this->contentTypeDraftMapper = $contentTypeDraftMapper;
}

/**
Expand Down Expand Up @@ -623,7 +628,7 @@ public function createUpdateForm(
Language $language = null,
?Language $baseLanguage = null
): FormInterface {
$contentTypeData = (new ContentTypeDraftMapper())->mapToFormData(
$contentTypeData = $this->contentTypeDraftMapper->mapToFormData(
$contentTypeDraft,
[
'language' => $language,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@
{% endblock %}

{% block ezselection_field_definition_edit %}
{% set is_translation = is_translation ?? false %}
<div class="ezselection-settings is-multiple{% if group_class is not empty %} {{ group_class }}{% endif %}">
{{- form_row(form.isMultiple, {'label_attr': {'class': 'checkbox-inline ez-label'}}) -}}
</div>
Expand All @@ -209,8 +208,7 @@
<li class="ezselection-settings-option-value ez-selection-table-row mb-2 d-flex align-items-center">
<input
type="checkbox"
class="ezselection-settings-option-checkbox ez-selection-table-checkbox"
{{ is_translation ? 'disabled' : '' }}>
class="ezselection-settings-option-checkbox ez-selection-table-checkbox">
{{ form_errors(option) }}
{{ form_widget(option, { 'attr': { 'class': 'form-control ml-1 mb-0'}}) }}
</li>
Expand All @@ -229,8 +227,7 @@
<div class="ezselection-settings-toolbar">
<button
type="button"
class="ezselection-settings-option-add ez-font-icon ez-button btn btn-secondary ez-button-add pure-button"
{{ is_translation ? 'disabled' : '' }}>
class="ezselection-settings-option-add ez-font-icon ez-button btn btn-secondary ez-button-add pure-button">
{{ "field_definition.ezselection.add_option"|trans({}, "ezrepoforms_content_type")|desc("Add an option") }}
</button>
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,24 @@

{% block ezselection_field %}
{% spaceless %}
{% set options = fieldSettings.options %}

{% if fieldSettings.multilingualOptions[field.languageCode] is defined %}
{% set options = fieldSettings.multilingualOptions[field.languageCode] %}
{% elseif fieldSettings.multilingualOptions[contentInfo.mainLanguageCode] is defined %}
{% set options = fieldSettings.multilingualOptions[contentInfo.mainLanguageCode] %}
{% endif %}

{% if fieldSettings.isMultiple and field.value.selection|length() > 0 %}
{% set attr = attr|merge({'class': (attr.class|default('') ~ ' ez-field-preview ez-field-preview--ezselection-multiple')|trim}) %}
<ul {{ block( 'field_attributes' ) }}>
{% for selectedIndex in field.value.selection %}
<li class="ez-selection__item">{{ fieldSettings.options[selectedIndex] }}</li>
<li class="ez-selection__item">{{ options[selectedIndex] }}</li>
{% endfor %}
</ul>
{% elseif not fieldSettings.isMultiple %}
{% set attr = attr|merge({'class': (attr.class|default('') ~ ' ez-field-preview ez-field-preview--ezselection-single')|trim}) %}
{% set field_value = fieldSettings.options[field.value.selection.0] %}
{% set field_value = options[field.value.selection|first] %}
{{ block( 'simple_block_field' ) }}
{% endif %}
{% endspaceless %}
Expand Down