From cec386692a38b84d5be6065d259f6c178c0b5bc2 Mon Sep 17 00:00:00 2001 From: Pavol Tuka <30590523+pavol-tk@users.noreply.github.com> Date: Fri, 15 May 2020 09:45:16 +0200 Subject: [PATCH 01/12] Pass menu label attributes to translation translations/messages.en.yaml ``` item_label_translation: Translatable label with %placeholder%. ``` Menu builder ``` $group->addChild('item', [ 'label' => 'item_label_translation', 'labelAttributes' => ['%placeholder%' => 'dynamic_value'] ]); ``` --- src/Resources/views/Menu/sonata_menu.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/views/Menu/sonata_menu.html.twig b/src/Resources/views/Menu/sonata_menu.html.twig index 46415733a1..d96df785cf 100644 --- a/src/Resources/views/Menu/sonata_menu.html.twig +++ b/src/Resources/views/Menu/sonata_menu.html.twig @@ -47,4 +47,4 @@ {% endapply %} {% endblock %} -{% block label %}{% if is_link is defined and is_link %}{{ icon|default|raw }}{% endif %}{% if options.allow_safe_labels and item.extra('safe_label', false) %}{{ item.label|raw }}{% else %}{{ item.label|trans({}, translation_domain|default('messages')) }}{% endif %}{% endblock %} +{% block label %}{% if is_link is defined and is_link %}{{ icon|default|raw }}{% endif %}{% if options.allow_safe_labels and item.extra('safe_label', false) %}{{ item.label|raw }}{% else %}{{ item.label|trans(item.labelAttributes, translation_domain|default('messages')) }}{% endif %}{% endblock %} From fc82781b316bb09aa956990b7bce2acce8270f07 Mon Sep 17 00:00:00 2001 From: Pavol Tuka <30590523+pavol-tk@users.noreply.github.com> Date: Sun, 17 May 2020 09:13:08 +0200 Subject: [PATCH 02/12] Pass translation_params to label translations Do it the same way as here: https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Resources/views/standard_layout.html.twig#L101 --- src/Resources/views/Menu/sonata_menu.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/views/Menu/sonata_menu.html.twig b/src/Resources/views/Menu/sonata_menu.html.twig index d96df785cf..d545bcf59e 100644 --- a/src/Resources/views/Menu/sonata_menu.html.twig +++ b/src/Resources/views/Menu/sonata_menu.html.twig @@ -47,4 +47,4 @@ {% endapply %} {% endblock %} -{% block label %}{% if is_link is defined and is_link %}{{ icon|default|raw }}{% endif %}{% if options.allow_safe_labels and item.extra('safe_label', false) %}{{ item.label|raw }}{% else %}{{ item.label|trans(item.labelAttributes, translation_domain|default('messages')) }}{% endif %}{% endblock %} +{% block label %}{% if is_link is defined and is_link %}{{ icon|default|raw }}{% endif %}{% if options.allow_safe_labels and item.extra('safe_label', false) %}{{ item.label|raw }}{% else %}{{ item.label|trans(item.extra('translation_params') | default({}), translation_domain|default('messages')) }}{% endif %}{% endblock %} From a8b28ec3681b3fe7bacad9e787478315002a74ff Mon Sep 17 00:00:00 2001 From: Pavol Tuka Date: Sun, 17 May 2020 18:39:02 +0200 Subject: [PATCH 03/12] Use label_translation_parameters of menu item extra's --- docs/reference/advanced_configuration.rst | 6 +++--- src/Resources/views/Menu/sonata_menu.html.twig | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/reference/advanced_configuration.rst b/docs/reference/advanced_configuration.rst index 7e7aa0cbfb..543abe8807 100644 --- a/docs/reference/advanced_configuration.rst +++ b/docs/reference/advanced_configuration.rst @@ -306,12 +306,12 @@ If you want to use the Tab Menu in a different way, you can replace the Menu Tem Translations ^^^^^^^^^^^^ -The translation parameters and domain can be customised by using the -``translation_domain`` and ``translation_parameters`` keys of the extra array +The label translation parameters and domain can be customised by using the +``label_translation_parameters`` and ``translation_domain`` keys of the extra array of data associated with the item, respectively:: $menuItem->setExtras([ - 'translation_parameters' => ['myparam' => 'myvalue'], + 'label_translation_parameters' => ['myparam' => 'myvalue'], 'translation_domain' => 'My domain', ]); diff --git a/src/Resources/views/Menu/sonata_menu.html.twig b/src/Resources/views/Menu/sonata_menu.html.twig index d545bcf59e..17f9314f1f 100644 --- a/src/Resources/views/Menu/sonata_menu.html.twig +++ b/src/Resources/views/Menu/sonata_menu.html.twig @@ -47,4 +47,4 @@ {% endapply %} {% endblock %} -{% block label %}{% if is_link is defined and is_link %}{{ icon|default|raw }}{% endif %}{% if options.allow_safe_labels and item.extra('safe_label', false) %}{{ item.label|raw }}{% else %}{{ item.label|trans(item.extra('translation_params') | default({}), translation_domain|default('messages')) }}{% endif %}{% endblock %} +{% block label %}{% if is_link is defined and is_link %}{{ icon|default|raw }}{% endif %}{% if options.allow_safe_labels and item.extra('safe_label', false) %}{{ item.label|raw }}{% else %}{{ item.label|trans(item.extra('label_translation_parameters')|default({}), translation_domain|default('messages')) }}{% endif %}{% endblock %} From a0a823d90715e22e75cf353b292b2d0651fc5cf9 Mon Sep 17 00:00:00 2001 From: Pavol Tuka <30590523+pavol-tk@users.noreply.github.com> Date: Sun, 17 May 2020 20:11:46 +0200 Subject: [PATCH 04/12] Use second parameter of extra to set default value Co-authored-by: Vincent Langlet --- src/Resources/views/Menu/sonata_menu.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/views/Menu/sonata_menu.html.twig b/src/Resources/views/Menu/sonata_menu.html.twig index 17f9314f1f..ecf403b3a4 100644 --- a/src/Resources/views/Menu/sonata_menu.html.twig +++ b/src/Resources/views/Menu/sonata_menu.html.twig @@ -47,4 +47,4 @@ {% endapply %} {% endblock %} -{% block label %}{% if is_link is defined and is_link %}{{ icon|default|raw }}{% endif %}{% if options.allow_safe_labels and item.extra('safe_label', false) %}{{ item.label|raw }}{% else %}{{ item.label|trans(item.extra('label_translation_parameters')|default({}), translation_domain|default('messages')) }}{% endif %}{% endblock %} +{% block label %}{% if is_link is defined and is_link %}{{ icon|default|raw }}{% endif %}{% if options.allow_safe_labels and item.extra('safe_label', false) %}{{ item.label|raw }}{% else %}{{ item.label|trans(item.extra('label_translation_parameters', {}), translation_domain|default('messages')) }}{% endif %}{% endblock %} From 36256ea13fc4168bf17cf7cb1427119baa9833f6 Mon Sep 17 00:00:00 2001 From: Pavol Tuka Date: Sun, 17 May 2020 20:21:32 +0200 Subject: [PATCH 05/12] Reformat label block to multiple lines with apply spaceless --- src/Resources/views/Menu/sonata_menu.html.twig | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Resources/views/Menu/sonata_menu.html.twig b/src/Resources/views/Menu/sonata_menu.html.twig index ecf403b3a4..df3aa534d7 100644 --- a/src/Resources/views/Menu/sonata_menu.html.twig +++ b/src/Resources/views/Menu/sonata_menu.html.twig @@ -47,4 +47,15 @@ {% endapply %} {% endblock %} -{% block label %}{% if is_link is defined and is_link %}{{ icon|default|raw }}{% endif %}{% if options.allow_safe_labels and item.extra('safe_label', false) %}{{ item.label|raw }}{% else %}{{ item.label|trans(item.extra('label_translation_parameters', {}), translation_domain|default('messages')) }}{% endif %}{% endblock %} +{% block label %} + {% apply spaceless %} + {% if is_link is defined and is_link %} + {{ icon|default|raw }} + {% endif %} + {% if options.allow_safe_labels and item.extra('safe_label', false) %} + {{ item.label|raw }} + {% else %} + {{ item.label|trans(item.extra('label_translation_parameters', {}), translation_domain|default('messages')) }} + {% endif %} + {% endapply %} +{% endblock %} From 296b10be7b44eec1a70e3306d090900a85ef096d Mon Sep 17 00:00:00 2001 From: Pavol Tuka Date: Sun, 17 May 2020 20:27:19 +0200 Subject: [PATCH 06/12] Add variable translation_domain to label block --- src/Resources/views/Menu/sonata_menu.html.twig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Resources/views/Menu/sonata_menu.html.twig b/src/Resources/views/Menu/sonata_menu.html.twig index df3aa534d7..772dd9eef3 100644 --- a/src/Resources/views/Menu/sonata_menu.html.twig +++ b/src/Resources/views/Menu/sonata_menu.html.twig @@ -55,7 +55,8 @@ {% if options.allow_safe_labels and item.extra('safe_label', false) %} {{ item.label|raw }} {% else %} - {{ item.label|trans(item.extra('label_translation_parameters', {}), translation_domain|default('messages')) }} + {% set translation_domain = item.extra('label_catalogue', 'messages') %} + {{ item.label|trans(item.extra('label_translation_parameters', {}), translation_domain) }} {% endif %} {% endapply %} {% endblock %} From 41b9a63d6d27098e9620f6a85f11425a81bc059a Mon Sep 17 00:00:00 2001 From: Pavol Tuka Date: Sun, 17 May 2020 20:28:36 +0200 Subject: [PATCH 07/12] Mark option label_catalogue as deprecated in twig templates --- src/Resources/views/Block/block_admin_list.html.twig | 1 + src/Resources/views/Core/add_block.html.twig | 1 + src/Resources/views/Menu/sonata_menu.html.twig | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Resources/views/Block/block_admin_list.html.twig b/src/Resources/views/Block/block_admin_list.html.twig index 59a06c2da5..068ce4413b 100644 --- a/src/Resources/views/Block/block_admin_list.html.twig +++ b/src/Resources/views/Block/block_admin_list.html.twig @@ -18,6 +18,7 @@ file that was distributed with this source code. {% if display %}
+ {# NEXT_MAJOR: Remove the deprecated option 'label_catalogue'. #}

{{ group.label|trans({}, group.label_catalogue) }}

diff --git a/src/Resources/views/Core/add_block.html.twig b/src/Resources/views/Core/add_block.html.twig index 7eada64fdf..2ebc241e75 100644 --- a/src/Resources/views/Core/add_block.html.twig +++ b/src/Resources/views/Core/add_block.html.twig @@ -34,6 +34,7 @@ {% endif %} diff --git a/src/Resources/views/Menu/sonata_menu.html.twig b/src/Resources/views/Menu/sonata_menu.html.twig index 772dd9eef3..72dede74e2 100644 --- a/src/Resources/views/Menu/sonata_menu.html.twig +++ b/src/Resources/views/Menu/sonata_menu.html.twig @@ -22,6 +22,7 @@ {% block linkElement %} {% apply spaceless %} + {# NEXT_MAJOR: Remove the deprecated option 'label_catalogue'. #} {% set translation_domain = item.extra('label_catalogue', 'messages') %} {% if item.extra('on_top') is defined and not item.extra('on_top') %} {% set icon = item.extra('icon')|default(item.level > 1 ? '' : '') %} @@ -36,7 +37,8 @@ {% block spanElement %} {% apply spaceless %} - {% set translation_domain = item.extra('label_catalogue') %} + {# NEXT_MAJOR: Remove the deprecated option 'label_catalogue'. #} + {% set translation_domain = item.extra('label_catalogue', 'messages') %} {% set icon = item.extra('icon')|default('') %} {{ icon|raw }} {{ parent() }} @@ -55,6 +57,7 @@ {% if options.allow_safe_labels and item.extra('safe_label', false) %} {{ item.label|raw }} {% else %} + {# NEXT_MAJOR: Remove the deprecated option 'label_catalogue'. #} {% set translation_domain = item.extra('label_catalogue', 'messages') %} {{ item.label|trans(item.extra('label_translation_parameters', {}), translation_domain) }} {% endif %} From b7fdb4edad7549870a0480c1f4b42e5f67d57653 Mon Sep 17 00:00:00 2001 From: Pavol Tuka <30590523+pavol-tk@users.noreply.github.com> Date: Mon, 18 May 2020 09:40:17 +0200 Subject: [PATCH 08/12] Update src/Resources/views/Menu/sonata_menu.html.twig Co-authored-by: Vincent Langlet --- src/Resources/views/Menu/sonata_menu.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/views/Menu/sonata_menu.html.twig b/src/Resources/views/Menu/sonata_menu.html.twig index 72dede74e2..7b776488d2 100644 --- a/src/Resources/views/Menu/sonata_menu.html.twig +++ b/src/Resources/views/Menu/sonata_menu.html.twig @@ -51,7 +51,7 @@ {% block label %} {% apply spaceless %} - {% if is_link is defined and is_link %} + {%- if is_link is defined and is_link -%} {{ icon|default|raw }} {% endif %} {% if options.allow_safe_labels and item.extra('safe_label', false) %} From 95e2d12652be2d9d5fed3c0df66e3cb0637f5d03 Mon Sep 17 00:00:00 2001 From: Pavol Tuka Date: Mon, 18 May 2020 09:42:39 +0200 Subject: [PATCH 09/12] Remove NEXT_MAJOR deprecation comment --- src/Resources/views/Block/block_admin_list.html.twig | 1 - src/Resources/views/Core/add_block.html.twig | 1 - src/Resources/views/Menu/sonata_menu.html.twig | 3 --- 3 files changed, 5 deletions(-) diff --git a/src/Resources/views/Block/block_admin_list.html.twig b/src/Resources/views/Block/block_admin_list.html.twig index 068ce4413b..59a06c2da5 100644 --- a/src/Resources/views/Block/block_admin_list.html.twig +++ b/src/Resources/views/Block/block_admin_list.html.twig @@ -18,7 +18,6 @@ file that was distributed with this source code. {% if display %}
- {# NEXT_MAJOR: Remove the deprecated option 'label_catalogue'. #}

{{ group.label|trans({}, group.label_catalogue) }}

diff --git a/src/Resources/views/Core/add_block.html.twig b/src/Resources/views/Core/add_block.html.twig index 2ebc241e75..7eada64fdf 100644 --- a/src/Resources/views/Core/add_block.html.twig +++ b/src/Resources/views/Core/add_block.html.twig @@ -34,7 +34,6 @@ {% endif %} diff --git a/src/Resources/views/Menu/sonata_menu.html.twig b/src/Resources/views/Menu/sonata_menu.html.twig index 7b776488d2..544b2920cc 100644 --- a/src/Resources/views/Menu/sonata_menu.html.twig +++ b/src/Resources/views/Menu/sonata_menu.html.twig @@ -22,7 +22,6 @@ {% block linkElement %} {% apply spaceless %} - {# NEXT_MAJOR: Remove the deprecated option 'label_catalogue'. #} {% set translation_domain = item.extra('label_catalogue', 'messages') %} {% if item.extra('on_top') is defined and not item.extra('on_top') %} {% set icon = item.extra('icon')|default(item.level > 1 ? '' : '') %} @@ -37,7 +36,6 @@ {% block spanElement %} {% apply spaceless %} - {# NEXT_MAJOR: Remove the deprecated option 'label_catalogue'. #} {% set translation_domain = item.extra('label_catalogue', 'messages') %} {% set icon = item.extra('icon')|default('') %} {{ icon|raw }} @@ -57,7 +55,6 @@ {% if options.allow_safe_labels and item.extra('safe_label', false) %} {{ item.label|raw }} {% else %} - {# NEXT_MAJOR: Remove the deprecated option 'label_catalogue'. #} {% set translation_domain = item.extra('label_catalogue', 'messages') %} {{ item.label|trans(item.extra('label_translation_parameters', {}), translation_domain) }} {% endif %} From ac7eb3568b90f08a75e53788606d597b7204968a Mon Sep 17 00:00:00 2001 From: Pavol Tuka Date: Mon, 18 May 2020 09:48:59 +0200 Subject: [PATCH 10/12] Add dashes to twig markdown to avoid space rendering --- .../views/Menu/sonata_menu.html.twig | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Resources/views/Menu/sonata_menu.html.twig b/src/Resources/views/Menu/sonata_menu.html.twig index 544b2920cc..8d35bb47a9 100644 --- a/src/Resources/views/Menu/sonata_menu.html.twig +++ b/src/Resources/views/Menu/sonata_menu.html.twig @@ -1,34 +1,34 @@ {% extends 'knp_menu.html.twig' %} {% block root %} - {%- set listAttributes = item.childrenAttributes|merge({'class': 'sidebar-menu', 'data-widget': 'tree'}) %} - {%- set request = item.extra('request') ?: app.request %} + {%- set listAttributes = item.childrenAttributes|merge({'class': 'sidebar-menu', 'data-widget': 'tree'}) -%} + {%- set request = item.extra('request') ?: app.request -%} {{ block('list') -}} {% endblock %} {% block item %} - {%- if item.displayed %} + {%- if item.displayed -%} {#- check role of the group #} - {%- set display = item.extra('roles') is empty or is_granted(sonata_admin.adminPool.getOption('role_super_admin')) or item.extra('roles')|filter(role => is_granted(role))|length > 0 %} - {%- endif %} + {%- set display = item.extra('roles') is empty or is_granted(sonata_admin.adminPool.getOption('role_super_admin')) or item.extra('roles')|filter(role => is_granted(role))|length > 0 -%} + {%- endif -%} - {%- if item.displayed and display|default %} - {% set options = options|merge({branch_class: 'treeview', currentClass: "active", ancestorClass: "active"}) %} - {%- do item.setChildrenAttribute('class', (item.childrenAttribute('class')~' active')|trim) %} - {%- do item.setChildrenAttribute('class', (item.childrenAttribute('class')~' treeview-menu')|trim) %} + {%- if item.displayed and display|default -%} + {%- set options = options|merge({branch_class: 'treeview', currentClass: "active", ancestorClass: "active"}) -%} + {%- do item.setChildrenAttribute('class', (item.childrenAttribute('class')~' active')|trim) -%} + {%- do item.setChildrenAttribute('class', (item.childrenAttribute('class')~' treeview-menu')|trim) -%} {{ parent() }} - {% endif %} + {%- endif -%} {% endblock %} {% block linkElement %} {% apply spaceless %} - {% set translation_domain = item.extra('label_catalogue', 'messages') %} - {% if item.extra('on_top') is defined and not item.extra('on_top') %} - {% set icon = item.extra('icon')|default(item.level > 1 ? '' : '') %} - {% else %} - {% set icon = item.extra('icon') %} - {% endif %} - {% set is_link = true %} + {%- set translation_domain = item.extra('label_catalogue', 'messages') -%} + {%- if item.extra('on_top') is defined and not item.extra('on_top') -%} + {%- set icon = item.extra('icon')|default(item.level > 1 ? '' : '') -%} + {%- else -%} + {%- set icon = item.extra('icon') -%} + {%- endif -%} + {%- set is_link = true -%} {{ parent() }} {% endapply %} {% endblock %} @@ -36,8 +36,8 @@ {% block spanElement %} {% apply spaceless %} - {% set translation_domain = item.extra('label_catalogue', 'messages') %} - {% set icon = item.extra('icon')|default('') %} + {%- set translation_domain = item.extra('label_catalogue', 'messages') -%} + {%- set icon = item.extra('icon')|default('') -%} {{ icon|raw }} {{ parent() }} {%- if item.extra('keep_open') is not defined or not item.extra('keep_open') -%} @@ -51,12 +51,12 @@ {% apply spaceless %} {%- if is_link is defined and is_link -%} {{ icon|default|raw }} - {% endif %} - {% if options.allow_safe_labels and item.extra('safe_label', false) %} + {%- endif -%} + {%- if options.allow_safe_labels and item.extra('safe_label', false) -%} {{ item.label|raw }} - {% else %} - {% set translation_domain = item.extra('label_catalogue', 'messages') %} + {%- else -%} + {%- set translation_domain = item.extra('label_catalogue', 'messages') -%} {{ item.label|trans(item.extra('label_translation_parameters', {}), translation_domain) }} - {% endif %} + {%- endif -%} {% endapply %} {% endblock %} From 6863cd8bb22d380e9c355483f8e6a971634b6cc4 Mon Sep 17 00:00:00 2001 From: Pavol Tuka Date: Mon, 18 May 2020 09:53:41 +0200 Subject: [PATCH 11/12] Rename translation_domain to label_catalogue in doc/advanced configuration --- docs/reference/advanced_configuration.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/advanced_configuration.rst b/docs/reference/advanced_configuration.rst index 543abe8807..943ad9e6ea 100644 --- a/docs/reference/advanced_configuration.rst +++ b/docs/reference/advanced_configuration.rst @@ -307,7 +307,7 @@ Translations ^^^^^^^^^^^^ The label translation parameters and domain can be customised by using the -``label_translation_parameters`` and ``translation_domain`` keys of the extra array +``label_translation_parameters`` and ``label_catalogue`` keys of the extra array of data associated with the item, respectively:: $menuItem->setExtras([ From 79cccbd8c40a60e0379ccd2bf6ca24017f809e86 Mon Sep 17 00:00:00 2001 From: Pavol Tuka Date: Mon, 18 May 2020 10:54:44 +0200 Subject: [PATCH 12/12] Rename translation_domain to label_catalogue in doc/advanced configuration --- docs/reference/advanced_configuration.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reference/advanced_configuration.rst b/docs/reference/advanced_configuration.rst index 943ad9e6ea..3605617843 100644 --- a/docs/reference/advanced_configuration.rst +++ b/docs/reference/advanced_configuration.rst @@ -312,13 +312,13 @@ of data associated with the item, respectively:: $menuItem->setExtras([ 'label_translation_parameters' => ['myparam' => 'myvalue'], - 'translation_domain' => 'My domain', + 'label_catalogue' => 'My domain', ]); You can also set the translation domain on the menu root, and children will inherit it:: - $menu->setExtra('translation_domain', 'My domain'); + $menu->setExtra('label_catalogue', 'My domain'); Filter parameters ^^^^^^^^^^^^^^^^^