Skip to content

Commit

Permalink
[Fix][#10] Allow multiple attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Wambre committed May 2, 2023
1 parent b19a668 commit e15501f
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ class Category

### ActionButton

This will add button next to your add button in a list view. [Here](https://sonata-project.org/bundles/admin/3-x/doc/cookbook/recipe_custom_action.html#custom-action-without-entity)
This will add button next to your add button in a list view. [Here](https://docs.sonata-project.org/projects/SonataAdminBundle/en/4.x/reference/dashboard/#configuring-what-actions-are-available-for-each-item-on-the-dashboard)
you can find how the template should look like.

```php
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/Sonata/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @author Marko Kunic <kunicmarko20@gmail.com>
* @author Mathieu Wambre <contact@neimheadh.fr>
*/
#[Attribute(Attribute::TARGET_CLASS)]
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
final class Access extends AbstractAnnotation
{

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/Sonata/ActionButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author Marko Kunic <kunicmarko20@gmail.com>
* @author Mathieu Wambre <contact@neimheadh.fr>
*/
#[Attribute(Attribute::TARGET_CLASS)]
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
final class ActionButton extends AbstractAction
{
}
2 changes: 1 addition & 1 deletion src/Annotation/Sonata/AddChild.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @author Marko Kunic <kunicmarko20@gmail.com>
* @author Mathieu Wambre <contact@neimheadh.fr>
*/
#[Attribute(Attribute::TARGET_CLASS)]
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
final class AddChild extends AbstractAnnotation
{

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/Sonata/AddRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @author Marko Kunic <kunicmarko20@gmail.com>
* @author Mathieu Wambre <contact@neimheadh.fr>
*/
#[Attribute(Attribute::TARGET_CLASS)]
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
final class AddRoute extends AbstractAnnotation implements
RouteAnnotationInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/Sonata/DashboardAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author Marko Kunic <kunicmarko20@gmail.com>
* @author Mathieu Wambre <contact@neimheadh.fr>
*/
#[Attribute(Attribute::TARGET_CLASS)]
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
final class DashboardAction extends AbstractAction
{
}
2 changes: 1 addition & 1 deletion src/Annotation/Sonata/ListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @author Marko Kunic <kunicmarko20@gmail.com>
* @author Mathieu Wambre <contact@neimheadh.fr>
*/
#[Attribute(Attribute::TARGET_CLASS)]
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
final class ListAction extends AbstractAnnotation
{

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/Sonata/RemoveRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @author Marko Kunic <kunicmarko20@gmail.com>
* @author Mathieu Wambre <contact@neimheadh.fr>
*/
#[Attribute(Attribute::TARGET_CLASS)]
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
final class RemoveRoute extends AbstractAnnotation implements
RouteAnnotationInterface
{
Expand Down
52 changes: 50 additions & 2 deletions tests/Reader/ListReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Neimheadh\SonataAnnotationBundle\Annotation\Sonata\ListField;
use Neimheadh\SonataAnnotationBundle\AnnotationReader;
use Neimheadh\SonataAnnotationBundle\Exception\MissingAnnotationArgumentException;
use Neimheadh\SonataAnnotationBundle\Reader\FormReader;
use Neimheadh\SonataAnnotationBundle\Reader\ListReader;
use Neimheadh\SonataAnnotationBundle\Tests\Resources\Extension\CreateNewAnnotationAdminTrait;
use Neimheadh\SonataAnnotationBundle\Tests\Resources\Model\Entity\EmptyEntity;
Expand Down Expand Up @@ -268,6 +267,40 @@ public function shouldAdminAnnotationWorks(): void
$this->assertEquals(['id', 'name', '_actions'], $mapper->keys());
}

/**
* Test multiple list action works.
*
* @link https://github.com/neimheadh/SonataAnnotationBundle/issues/10
* @test
* @functionnal
*
* @return void
*/
public function shouldAllowMultipleListActionAttribute(): void
{
$reader = new ListReader(new AnnotationReader());
$class = new ReflectionClass(MultipleListAction::class);
$mapper = $this->createNewListMapper();

$reader->configureFields($class, $mapper);
$actions = $mapper->get('_actions');

$this->assertEquals([
'show' => [
'template' => '@SonataAdmin/CRUD/list__action_show.html.twig',
],
'edit' => [
'template' => '@SonataAdmin/CRUD/list__action_edit.html.twig',
],
'delete' => [
'template' => '@SonataAdmin/CRUD/list__action_delete.html.twig',
],
'import' => [
'template' => 'import_list_button.html.twig',
],
], $actions->getOption('actions'));
}

/**
* Create new empty list mapper.
*
Expand All @@ -284,11 +317,16 @@ private function createNewListMapper(
/** @var ListBuilderInterface $listBuilder */
$listBuilder = $container->get('sonata.admin.builder.orm_list');

return new ListMapper(
$mapper = new ListMapper(
$listBuilder,
new FieldDescriptionCollection(),
$this->createNewAnnotationAdmin($class),
);

$mapper->getAdmin()->hasListFieldDescription('_actions')
&& $mapper->getAdmin()->removeListFieldDescription('_actions');

return $mapper;
}

}
Expand Down Expand Up @@ -345,4 +383,14 @@ public function getField2(): string
class BadListAction
{

}


#[ListAction(name: "show")]
#[ListAction(name: "edit")]
#[ListAction(name: "delete")]
#[ListAction(name: "import", options: ['template' => 'import_list_button.html.twig'])]
class MultipleListAction
{

}
2 changes: 1 addition & 1 deletion tests/Resources/Model/Entity/EmptyEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Neimheadh\SonataAnnotationBundle\Tests\Resources\Model\Entity;

use Neimheadh\SonataAnnotationBundle\Annotation\Sonata;
use Doctrine\ORM\Mapping as ORM;

/**
Expand All @@ -20,4 +19,5 @@ class EmptyEntity
* @var int
*/
private int $_id;

}

0 comments on commit e15501f

Please sign in to comment.