Skip to content
Open
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
27 changes: 25 additions & 2 deletions assets/css/easyadmin-theme/datagrids.css
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,29 @@ table.datagrid:not(.datagrid-empty) tr:not(.empty-row) td.actions.actions-as-dro
.datagrid td.actions {
text-align: right;
}
.datagrid td.actions a:not(.dropdown-item) {
.datagrid td.actions a:not(.dropdown-item),
.datagrid td.actions form:not(.dropdown-item) {
font-size: var(--font-size-sm);
font-weight: 500;
}
.datagrid td.actions a:not(.dropdown-item) + a:not(.dropdown-item) {

.datagrid td.actions form:not(.dropdown-item) {
display: inline-block;
color: var(--link-color);
}

.datagrid td.actions form:not(.dropdown-item) button {
all: unset;
cursor: pointer;
width: 100%;
}

.datagrid td.actions a:not(.dropdown-item) + a:not(.dropdown-item),
.datagrid td.actions form:not(.dropdown-item) + a:not(.dropdown-item),
.datagrid td.actions a:not(.dropdown-item) + form:not(.dropdown-item) {
margin-inline-start: 10px;
}

.datagrid td.actions a:not(.dropdown-item) .action-icon {
font-size: var(--font-size-base);
margin-inline-end: 2px;
Expand Down Expand Up @@ -205,6 +221,13 @@ table.datagrid:not(.datagrid-empty) tr:not(.empty-row) td.actions.actions-as-dro

.datagrid .dropdown-actions .dropdown-menu { z-index: var(--zindex-900); }

.datagrid .dropdown-actions .dropdown-menu form button.action-button {
all: unset;
cursor: pointer;
width: 100%;
}


.datagrid .ea-lightbox-thumbnail img {
background: var(--white);
border: 1px solid transparent;
Expand Down
14 changes: 14 additions & 0 deletions templates/components/ActionMenu/ActionList/Item.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@
icon = null,
url = null,
htmlAttributes = {},
type = "a",
name = ""
%}

<li>
{% if type == "form" %}
{%- set form_id = 'form-' ~ name ~ '-' ~ random() -%}
<form action="{{ url }}" method="POST" id="{{ form_id }}" class="dropdown-item">
<button {{ attributes.defaults({class: 'action-button', href: url, form: form_id}|merge(htmlAttributes)) }}>
<span class="btn-label">
{%- if icon %}<twig:ea:Icon name="{{ icon }}"/> {% endif -%}
{%- if label is not empty -%}<span class="action-label">{{ renderLabelRaw ? label|trans|raw : label|trans }}</span>{%- endif -%}
</span>
</button>
</form>
{% else %}
<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>
{% endif %}
</li>
4 changes: 3 additions & 1 deletion templates/crud/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@
class="{{ action.cssClass }}" url="{{ action.linkUrl }}"
icon="{{ action.icon }}" icon:class="action-icon"
htmlAttributes="{{ action.htmlAttributes }}"
label="{{ action.label|trans }}" label:class="action-label" renderLabelRaw />
label="{{ action.label|trans }}" label:class="action-label" renderLabelRaw
type="{{ 'form' == action.htmlElement ? 'form' : 'a' }}"
name="{{ action.name }}"/>
{% endfor %}
</twig:ea:ActionMenu:ActionList>
</twig:ea:ActionMenu:Overlay>
Expand Down
5 changes: 5 additions & 0 deletions tests/Controller/ActionsCrudControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,10 @@ public function testFormAction()
static::assertCount(1, $crawler->filter('form[id^="form-action9-"]'));
static::assertCount(1, $crawler->filter('form[id^="form-action9-"] > .btn'));
static::assertSame('POST', $crawler->filter('form[id^="form-action9-"]')->attr('method'));

// use of 20 as there will be 1 on each of the line => by default 20 as defined in EasyAdminBundle\Config\Crud
static::assertCount(20, $crawler->filter('form[id^="form-action_form_entity-"]'), 'There is no Action Entity form in the dropdown');
static::assertCount(20, $crawler->filter('form[id^="form-action_form_entity-"] > button', 'There is no Action Entity form button in the dropdown'));
static::assertSame('POST', $crawler->filter('form[id^="form-action_form_entity-"]')->attr('method'), 'The method of the Action Entity form is not POST');
}
}
51 changes: 51 additions & 0 deletions tests/Controller/InlineActionsCrudControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace EasyCorp\Bundle\EasyAdminBundle\Tests\Controller;

use Doctrine\ORM\EntityRepository;
use EasyCorp\Bundle\EasyAdminBundle\Test\AbstractCrudTestCase;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Controller\InlineActionsCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Controller\SecureDashboardController;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\Category;

class InlineActionsCrudControllerTest extends AbstractCrudTestCase
{
protected EntityRepository $categories;

protected function getControllerFqcn(): string
{
return InlineActionsCrudController::class;
}

protected function getDashboardFqcn(): string
{
return SecureDashboardController::class;
}

protected function setUp(): void
{
parent::setUp();
$this->client->followRedirects();
$this->client->setServerParameters(['PHP_AUTH_USER' => 'admin', 'PHP_AUTH_PW' => '1234']);

$this->categories = $this->entityManager->getRepository(Category::class);
}

public function testCssClasses(): void
{
$crawler = $this->client->request('GET', $this->generateIndexUrl());

// TODO : see how to test the presence of the form into the inline actions
}

public function testFormAction(): void
{
$crawler = $this->client->request('GET', $this->generateIndexUrl());

// use of 20 as there will be 1 on each of the line => by default 20 as defined in EasyAdminBundle\Config\Crud
$nbEntitiesPerPage = 20;
static::assertCount($nbEntitiesPerPage, $crawler->filter('form[id^="form-action_form_entity-"]'));
static::assertCount($nbEntitiesPerPage, $crawler->filter('form[id^="form-action_form_entity-"] > button'));
static::assertSame('POST', $crawler->filter('form[id^="form-action_form_entity-"]')->attr('method'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public function configureActions(Actions $actions): Actions

$action9 = Action::new('action9')->linkToCrudAction('')->createAsGlobalAction()->displayAsForm();

// this tests the existence of the form action in an entity action
$actionFormEntity = Action::new('action_form_entity')->linkToCrudAction('')->displayAsForm();

return $actions
->add(Crud::PAGE_INDEX, $action1)
->add(Crud::PAGE_INDEX, $action2)
Expand All @@ -55,6 +58,7 @@ public function configureActions(Actions $actions): Actions
->add(Crud::PAGE_INDEX, $action7)
->add(Crud::PAGE_INDEX, $action8)
->add(Crud::PAGE_INDEX, $action9)
->add(Crud::PAGE_INDEX, $actionFormEntity)
->update(Crud::PAGE_INDEX, Action::NEW, function (Action $action) {
return $action->setIcon('fa fa-fw fa-plus')->setLabel(false);
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Controller;

use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\Category;

/**
* Tests the configureActions() method and the generated actions.
*/
class InlineActionsCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Category::class;
}

public function configureCrud(Crud $crud): Crud
{
return parent::configureCrud($crud)
->showEntityActionsInlined(true)
;
}

public function configureFields(string $pageName): iterable
{
return [
TextField::new('name'),
];
}

public function configureActions(Actions $actions): Actions
{
// this tests the existence of the form action in an entity action
$actionFormEntity = Action::new('action_form_entity')->linkToCrudAction('')->displayAsForm();

return $actions
->add(Crud::PAGE_INDEX, $actionFormEntity)
;
}
}