Skip to content
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
2 changes: 1 addition & 1 deletion assets/css/easyadmin-theme/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ a.user-menu-wrapper .user-details:hover {
}
.content-header .page-actions:empty { display: none; }

.content-header .page-actions :is(.btn,form:has(.btn)) + :is(.btn,form:has(.btn)) {
.content-header .page-actions :is(.btn, form:has(.btn)) + :is(.btn, form:has(.btn)) {
margin-inline-start: 10px;
}

Expand Down
31 changes: 27 additions & 4 deletions doc/actions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,6 @@ Then you can configure the basic HTML/CSS attributes of the button/element
that will represent the action::

$viewInvoice = Action::new('viewInvoice', 'Invoice', 'fa fa-file-invoice')
// renders the action as a <a> HTML element
->displayAsLink()
// renders the action as a <button> HTML element
->displayAsButton()
// a key-value array of attributes to add to the HTML element
->setHtmlAttributes(['data-foo' => 'bar', 'target' => '_blank'])
// removes all existing CSS classes of the action and sets
Expand All @@ -357,13 +353,40 @@ that will represent the action::
// useful when customizing a built-in action, which already has CSS classes)
->addCssClass('some-custom-css-class text-danger')

By default, actions are rendered as ``<a>`` elements that make a ``GET`` request
to the corresponding URL.

$viewInvoice = Action::new('viewInvoice', 'Invoice', 'fa fa-file-invoice')
// ...
// (default) renders the action as a <a> HTML element
->displayAsLink()

// renders the action as a <button> HTML element; this is ignored in the
// index page, where entity actions are displayeds as <a> elements;
// this button sumits the edit/new form which is being rendered
->displayAsButton()

// renders the action as a <button> element inside a <form> element different
// from the edit/new form being rendered; this is useful to call custom
// actions using the POST method
->displayAsForm()
;

.. versionadded:: 4.25

The ``displayAsForm()`` method was introduced in EasyAdmin 4.25.0.

.. note::

When using ``setCssClass()`` or ``addCssClass()`` methods, the action loses
the default CSS classes applied by EasyAdmin (``.btn`` and
``.action-<the-action-name>``). You might want to add those CSS classes
manually to make your actions look as expected.

.. tip::

Custom actions are

Once you've configured the basics, use one of the following methods to define
which method is executed when clicking on the action:

Expand Down
2 changes: 1 addition & 1 deletion public/app.62f32d02.css → public/app.842ae134.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/entrypoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"entrypoints": {
"app": {
"css": [
"/app.62f32d02.css"
"/app.842ae134.css"
],
"js": [
"/app.1ecd6d7a.js"
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"app.css": "app.62f32d02.css",
"app.css": "app.842ae134.css",
"app.js": "app.1ecd6d7a.js",
"form.js": "form.bcec6c2a.js",
"page-layout.js": "page-layout.3347892e.js",
Expand Down
20 changes: 16 additions & 4 deletions templates/components/ActionMenu/ActionList/Item.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% props
type = 'a', # possible values: 'a', 'form'
label = null,
renderLabelRaw = false,
icon = null,
Expand All @@ -7,8 +8,19 @@
%}

<li>
<a {{ attributes.defaults({class: 'dropdown-item', href: url}|merge(htmlAttributes)) }}>
{%- if icon %}<twig:ea:Icon {{ ...attributes.nested('icon').defaults({name: icon}) }} /> {% endif -%}
{%- if label is not empty -%}<span {{ attributes.nested('label') }}>{{ renderLabelRaw ? label|raw : label }}</span>{%- endif -%}
</a>
{% if 'a' == type %}
<a {{ attributes.defaults({class: 'dropdown-item', href: url}|merge(htmlAttributes)) }}>
{%- if icon %}<twig:ea:Icon {{ ...attributes.nested('icon').defaults({name: icon}) }} /> {% endif -%}
{%- if label is not empty -%}<span {{ attributes.nested('label') }}>{{ renderLabelRaw ? label|raw : label }}</span>{%- endif -%}
</a>
{% elseif 'form' == type %}
{% set form_id = 'form-' ~ random() %}
<form id="{{ form_id }}" action="{{ url }}" method="POST">
{% set css_class = 'dropdown-item ' ~ (htmlAttributes.class ?? '') %}
<button {{ attributes.defaults(htmlAttributes|merge({class: css_class, form: form_id})) }}>
{%- if icon %}<twig:ea:Icon {{ ...attributes.nested('icon').defaults({name: icon}) }} /> {% endif -%}
{%- if label is not empty -%}<span {{ attributes.nested('label') }}>{{ renderLabelRaw ? label|raw : label }}</span>{%- endif -%}
</button>
</form>
{% endif %}
</li>
1 change: 1 addition & 0 deletions templates/crud/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
<twig:ea:ActionMenu:ActionList>
{% for action in entity.actions %}
<twig:ea:ActionMenu:ActionList:Item
type="{{ 'form' == action.htmlElement ? 'form' : 'a' }}"
class="{{ action.cssClass }}" url="{{ action.linkUrl }}"
icon="{{ action.icon }}" icon:class="action-icon"
htmlAttributes="{{ action.htmlAttributes }}"
Expand Down