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

Add list_action_button_content and logo_content options #7325

Merged
merged 1 commit into from
Jul 19, 2021
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
14 changes: 14 additions & 0 deletions docs/reference/action_list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,20 @@ You need to add option ``show_mosaic_button`` in your admin services:
tags:
- { name: sonata.admin, manager_type: orm, group: admin, label: News, show_mosaic_button: false }

Show Icons on Action Buttons
----------------------------

You can choose if the action buttons on the list-page show an icon, text or both.

.. code-block:: yaml

# config/packages/sonata_admin.yaml

sonata_admin:
options:
# Choices are: text, icon or all (default)
list_action_button_content: icon

Checkbox range selection
------------------------

Expand Down
3 changes: 2 additions & 1 deletion docs/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ Full Configuration Options
default_label_catalogue: SonataAdminBundle
default_icon: 'fa fa-folder'
dropdown_number_groups_per_colums: 2
title_mode: ~ # One of "single_text"; "single_image"; "both"
logo_content: 'all' # One of "text"; "icon"; "all"
list_action_button_content: 'all' # One of "text"; "icon"; "all"

# Enable locking when editing an object, if the corresponding object manager supports it.
lock_protection: false
Expand Down
12 changes: 12 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,23 @@ public function getConfigTreeBuilder()
->info('Icon used for admin services if one isn\'t provided.')
->end()
->integerNode('dropdown_number_groups_per_colums')->defaultValue(2)->end()
// NEXT_MAJOR: Remove this option.
->enumNode('title_mode')
->setDeprecated('The "%node%" option is deprecated since sonata-project/admin-bundle 3.x. Use "logo_content" instead.')
->values(['single_text', 'single_image', 'both'])
->defaultValue('both')
->cannotBeEmpty()
->end()
->enumNode('logo_content')
->values(['text', 'icon', 'all'])
->defaultValue('all')
->cannotBeEmpty()
->end()
->enumNode('list_action_button_content')
->values(['text', 'icon', 'all'])
->defaultValue('all')
->cannotBeEmpty()
->end()
->booleanNode('lock_protection')
->defaultFalse()
->info('Enable locking when editing an object, if the corresponding object manager supports it.')
Expand Down
13 changes: 11 additions & 2 deletions src/Resources/views/CRUD/list__action_delete.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ file that was distributed with this source code.
#}

{% if admin.hasAccess('delete', object) and admin.hasRoute('delete') %}
{% set button_content = sonata_config.getOption('list_action_button_content') %}
<a
href="{{ admin.generateObjectUrl('delete', object, actions.link_parameters|default([])) }}"
class="btn btn-sm btn-default delete_link"
title="{{ 'action_delete'|trans({}, 'SonataAdminBundle') }}"
>
<i class="fa fa-times" aria-hidden="true"></i>
{{ 'action_delete'|trans({}, 'SonataAdminBundle') }}
{% if button_content == 'icon' or button_content == 'all' %}
<i class="fa fa-times" aria-hidden="true"></i>
{% endif %}
{% if button_content == 'text' or button_content == 'all' %}
{{ 'action_delete'|trans({}, 'SonataAdminBundle') }}
{% else %}
<span class="sr-only">
{{ 'action_delete'|trans({}, 'SonataAdminBundle') }}
</span>
{% endif %}
</a>
{% endif %}
13 changes: 11 additions & 2 deletions src/Resources/views/CRUD/list__action_edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ file that was distributed with this source code.
#}

{% if admin.hasAccess('edit', object) and admin.hasRoute('edit') %}
{% set button_content = sonata_config.getOption('list_action_button_content') %}
<a
href="{{ admin.generateObjectUrl('edit', object, actions.link_parameters|default([])) }}"
class="btn btn-sm btn-default edit_link"
title="{{ 'action_edit'|trans({}, 'SonataAdminBundle') }}"
>
<i class="fa fa-pencil" aria-hidden="true"></i>
{{ 'action_edit'|trans({}, 'SonataAdminBundle') }}
{% if button_content == 'icon' or button_content == 'all' %}
<i class="fa fa-pencil" aria-hidden="true"></i>
{% endif %}
{% if button_content == 'text' or button_content == 'all' %}
{{ 'action_edit'|trans({}, 'SonataAdminBundle') }}
{% else %}
<span class="sr-only">
{{ 'action_edit'|trans({}, 'SonataAdminBundle') }}
</span>
{% endif %}
</a>
{% endif %}
13 changes: 11 additions & 2 deletions src/Resources/views/CRUD/list__action_history.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ file that was distributed with this source code.
#}

{% if admin.hasAccess('history', object) and admin.hasRoute('history') %}
{% set button_content = sonata_config.getOption('list_action_button_content') %}
<a
href="{{ admin.generateObjectUrl('history', object, actions.link_parameters|default([])) }}"
class="btn btn-sm btn-default view_link"
title="{{ 'link_action_history'|trans({}, 'SonataAdminBundle') }}"
>
<i class="fa fa-history" aria-hidden="true"></i>
{{ 'link_action_history'|trans({}, 'SonataAdminBundle') }}
{% if button_content == 'icon' or button_content == 'all' %}
<i class="fa fa-history" aria-hidden="true"></i>
{% endif %}
{% if button_content == 'text' or button_content == 'all' %}
{{ 'link_action_history'|trans({}, 'SonataAdminBundle') }}
{% else %}
<span class="sr-only">
{{ 'link_action_history'|trans({}, 'SonataAdminBundle') }}
</span>
{% endif %}
</a>
{% endif %}
13 changes: 11 additions & 2 deletions src/Resources/views/CRUD/list__action_show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ file that was distributed with this source code.
#}

{% if admin.hasAccess('show', object) and admin.hasRoute('show') %}
{% set button_content = sonata_config.getOption('list_action_button_content') %}
<a
href="{{ admin.generateObjectUrl('show', object, actions.link_parameters|default([])) }}"
class="btn btn-sm btn-default view_link"
title="{{ 'action_show'|trans({}, 'SonataAdminBundle') }}"
>
<i class="fa fa-eye" aria-hidden="true"></i>
{{ 'action_show'|trans({}, 'SonataAdminBundle') }}
{% if button_content == 'icon' or button_content == 'all' %}
<i class="fa fa-eye" aria-hidden="true"></i>
{% endif %}
{% if button_content == 'text' or button_content == 'all' %}
{{ 'action_show'|trans({}, 'SonataAdminBundle') }}
{% else %}
<span class="sr-only">
{{ 'action_show'|trans({}, 'SonataAdminBundle') }}
</span>
{% endif %}
</a>
{% endif %}
12 changes: 10 additions & 2 deletions src/Resources/views/standard_layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,18 @@ file that was distributed with this source code.
{% block logo %}
{% apply spaceless %}
<a class="logo" href="{{ path('sonata_admin_dashboard') }}">
{% if 'single_image' == sonata_config.getOption('title_mode') or 'both' == sonata_config.getOption('title_mode') %}
{# NEXT_MAJOR: Remove the title_mode check #}
{% if 'icon' == sonata_config.getOption('logo_content')
or 'all' == sonata_config.getOption('logo_content')
and ('single_image' == sonata_config.getOption('title_mode') or 'both' == sonata_config.getOption('title_mode'))
%}
<img src="{{ asset(sonata_config.logo) }}" alt="{{ sonata_config.title }}">
{% endif %}
{% if 'single_text' == sonata_config.getOption('title_mode') or 'both' == sonata_config.getOption('title_mode') %}
{# NEXT_MAJOR: Remove the title_mode check #}
{% if 'text' == sonata_config.getOption('logo_content')
or 'all' == sonata_config.getOption('logo_content')
and ('single_text' == sonata_config.getOption('title_mode') or 'both' == sonata_config.getOption('title_mode'))
%}
<span>{{ sonata_config.title }}</span>
{% endif %}
</a>
Expand Down
3 changes: 2 additions & 1 deletion src/SonataConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
* javascripts: list<string>,
* js_debug: bool,
* legacy_twig_text_extension: bool,
* list_action_button_content: 'text'|'icon'|'all',
* lock_protection: bool,
* logo_content: 'text'|'icon'|'all',
* mosaic_background: string,
* pager_links: ?int,
* role_admin: string,
Expand All @@ -34,7 +36,6 @@
* skin: string,
* sort_admins: bool,
* stylesheets: list<string>,
* title_mode: 'single_text'|'single_image'|'both',
* use_bootlint: bool,
* use_icheck: bool,
* use_select2: bool,
Expand Down