Skip to content

Commit

Permalink
Add list_action_button_content and logo_content options
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Jul 14, 2021
1 parent 048d7dc commit c2f627d
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 9 deletions.
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
11 changes: 11 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,21 @@ public function getConfigTreeBuilder()
->end()
->integerNode('dropdown_number_groups_per_colums')->defaultValue(2)->end()
->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
11 changes: 10 additions & 1 deletion 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>
{% if button_content == 'icon' or button_content == 'all' %}
<i class="fa fa-times" aria-hidden="true"></i>
{% endif %}
{% if button_content != 'text' and button_content != 'all' %}
<span class="sr-only">
{% endif %}
{{ 'action_delete'|trans({}, 'SonataAdminBundle') }}
{% if button_content != 'text' and button_content != 'all' %}
</span>
{% endif %}
</a>
{% endif %}
11 changes: 10 additions & 1 deletion 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>
{% if button_content == 'icon' or button_content == 'all' %}
<i class="fa fa-pencil" aria-hidden="true"></i>
{% endif %}
{% if button_content != 'text' and button_content != 'all' %}
<span class="sr-only">
{% endif %}
{{ 'action_edit'|trans({}, 'SonataAdminBundle') }}
{% if button_content != 'text' and button_content != 'all' %}
</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' and button_content != 'all' %}
<span class="sr-only">
{% endif %}
{{ 'link_action_history'|trans({}, 'SonataAdminBundle') }}
{% if button_content != 'text' and button_content != 'all' %}
</span>
{% endif %}
</a>
{% endif %}
11 changes: 10 additions & 1 deletion 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>
{% if button_content == 'icon' or button_content == 'all' %}
<i class="fa fa-eye" aria-hidden="true"></i>
{% endif %}
{% if button_content != 'text' and button_content != 'all' %}
<span class="sr-only">
{% endif %}
{{ 'action_show'|trans({}, 'SonataAdminBundle') }}
{% if button_content != 'text' and button_content != 'all' %}
</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

0 comments on commit c2f627d

Please sign in to comment.