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

Make action button icons configurable #7166

Closed
wants to merge 7 commits into from
Closed
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 @@ -699,6 +699,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 }

Icons on action buttons
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Icons on action buttons
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 both (default)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Choices are: text,icon or both (default)
# Choices are: text, icon or both (default)

button_mode: icon

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

Expand Down
1 change: 1 addition & 0 deletions docs/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Full Configuration Options
default_icon: '<i class="fa fa-folder"></i>'
dropdown_number_groups_per_colums: 2
title_mode: ~ # One of "single_text"; "single_image"; "both"
button_mode: 'both' # One of "text"; "icon"; "both"

# Enable locking when editing an object, if the corresponding object manager supports it.
lock_protection: false
Expand Down
8 changes: 8 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ public function getConfigTreeBuilder()
'skin-yellow-light',
])
->end()
->enumNode('button_mode')
->defaultValue('both')
->values([
'both',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use a more representative term here, while bringing more flexibility to this feature.
"both" is useful only in case where 2 options are allowed, but what if we decide to add more in the future?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What could we add in the future ? Prior to this change this was always button + text, I don't know what could be added.

Do you have another suggestion ?
An array with the value ['icon', 'text'] ? An option all ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "all", "full" or something like that could be good choices.
BTW, maybe we could also use other name for the option, as the current one is not clear enough to me regarding its presentation purposes. Personally, the "mode" term makes me think about other options like "readonly=yes/no" or "action=edit/show".
I guess choices like "button_view", "button_view_mode", "button_content", "button_render" could work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also add context to the list.
action_buttons or list_action_buttons seems better than button.

'icon',
'text',
])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
])
])

->end()
->booleanNode('use_select2')->defaultTrue()->end()
->booleanNode('use_icheck')->defaultTrue()->end()
->booleanNode('use_bootlint')->defaultFalse()->end()
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_mode = sonata_config.getOption('button_mode') %}
<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_mode != 'text' %}
<i class="fa fa-times" aria-hidden="true"></i>
{% endif %}
{% if _button_mode == 'icon' %}
<span class="sr-only">
{{ 'action_delete'|trans({}, 'SonataAdminBundle') }}
</span>
{% else %}
{{ 'action_delete'|trans({}, 'SonataAdminBundle') }}
{% 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_mode = sonata_config.getOption('button_mode') %}
<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_mode != 'text' %}
<i class="fa fa-edit" aria-hidden="true"></i>
{% endif %}
{% if _button_mode == 'icon' %}
<span class="sr-only">
{{ 'link_action_edit'|trans({}, 'SonataAdminBundle') }}
</span>
{% else %}
{{ 'link_action_edit'|trans({}, 'SonataAdminBundle') }}
{% 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_mode = sonata_config.getOption('button_mode') %}
<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_mode != 'text' %}
<i class="fa fa-history" aria-hidden="true"></i>
{% endif %}
{% if _button_mode == 'icon' %}
<span class="sr-only">
{{ 'link_action_history'|trans({}, 'SonataAdminBundle') }}
</span>
{% else %}
{{ 'link_action_history'|trans({}, 'SonataAdminBundle') }}
{% 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_mode = sonata_config.getOption('button_mode') %}
<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_mode != 'text' %}
<i class="fa fa-eye" aria-hidden="true"></i>
{% endif %}
{% if _button_mode == 'icon' %}
<span class="sr-only">
{{ 'action_show'|trans({}, 'SonataAdminBundle') }}
</span>
{% else %}
{{ 'action_show'|trans({}, 'SonataAdminBundle') }}
{% endif %}
</a>
{% endif %}
1 change: 1 addition & 0 deletions src/SonataConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

/**
* @phpstan-type SonataConfigurationOptions = array{
* button_mode: 'both'|'icon'|'text',
* confirm_exit: bool,
* default_group: string,
* default_icon: string,
Expand Down