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
4 changes: 2 additions & 2 deletions doc/fields.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1127,8 +1127,8 @@ the full address is only visible on the detail and edit pages::

[$local, $domain] = explode('@', $email, 2);
$field->setFormattedValue(substr($local, 0, 1).'***@'.$domain);
}
}
}
}

.. tip::

Expand Down
13 changes: 13 additions & 0 deletions src/Config/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,19 @@ public function asDangerAction(bool $asDangerAction = true): self
return $this;
}

/**
* By default, actions are rendered as `btn-secondary` buttons. This method makes
* the action to be rendered as a `btn-info` button with light blue text.
*/
public function asInfoAction(bool $asInfoAction = true): self
{
if ($asInfoAction) {
$this->dto->setVariant(ButtonVariant::Info);
}

return $this;
}

/**
* By default, actions are rendered as solid buttons. This method makes
* the action to be rendered as a simple text link without button background
Expand Down
9 changes: 9 additions & 0 deletions src/Config/ActionGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ public function asDangerActionGroup(bool $asDangerActionGroup = true): self
return $this;
}

public function asInfoActionGroup(bool $asInfoActionGroup = true): self
{
if ($asInfoActionGroup) {
$this->dto->setVariant(ButtonVariant::Info);
}

return $this;
}

public function getAsDto(): ActionGroupDto
{
if (null === $this->dto->getIcon() && (null === $this->dto->getLabel() || false === $this->dto->getLabel())) {
Expand Down
1 change: 1 addition & 0 deletions src/Dto/ActionDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ public function getAsConfigObject(): Action
$action->asSuccessAction(ButtonVariant::Success === $this->variant);
$action->asDangerAction(ButtonVariant::Danger === $this->variant);
$action->asWarningAction(ButtonVariant::Warning === $this->variant);
$action->asInfoAction(ButtonVariant::Info === $this->variant);

if (null !== $this->crudActionName) {
$action->linkToCrudAction($this->crudActionName);
Expand Down
1 change: 1 addition & 0 deletions src/Factory/ActionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ private function getActionPriority(ActionDto|ActionGroupDto $item): int
ButtonVariant::Primary => 100,
ButtonVariant::Default => 90,
ButtonVariant::Success => 80,
ButtonVariant::Info => 75,
ButtonVariant::Warning => 70,
ButtonVariant::Danger => 60,
};
Expand Down
1 change: 1 addition & 0 deletions src/Twig/Component/Option/ButtonVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ enum ButtonVariant: string
case Success = 'success';
case Warning = 'warning';
case Danger = 'danger';
case Info = 'info';
}
2 changes: 1 addition & 1 deletion templates/components/Button.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% props
variant = 'default', # primary|default|danger|success|warning (default: 'default')
variant = 'default', # primary|default|danger|success|warning|info (default: 'default')
isInvisible = false, # true|false (default: false) if true, button has transparent background and no border
isBlock = false, # true|false (default: false) if true, button takes full width of container
size = 'md', # sm|md|lg (default: 'md')
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/Factory/ActionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Factory\ActionFactory;
use EasyCorp\Bundle\EasyAdminBundle\Twig\Component\Option\ButtonVariant;
use PHPUnit\Framework\TestCase;

class ActionFactoryTest extends TestCase
Expand All @@ -18,6 +19,7 @@ public function testAutomaticOrdering(): void
$actions->add('index', Action::new('action_primary')->linkToCrudAction('index')->asPrimaryAction());
$actions->add('index', Action::new('action_danger_text')->linkToCrudAction('index')->asDangerAction()->asTextLink());
$actions->add('index', Action::new('action_success')->linkToCrudAction('index')->asSuccessAction());
$actions->add('index', Action::new('action_info')->linkToCrudAction('index')->asInfoAction());
$actions->add('index', Action::new('action_text')->linkToCrudAction('index')->asTextLink());
$actions->add('index', Action::new('action_danger')->linkToCrudAction('index')->asDangerAction());
$actions->add('index', Action::new('action_default')->linkToCrudAction('index'));
Expand All @@ -31,6 +33,7 @@ public function testAutomaticOrdering(): void
'action_primary',
'action_danger_text',
'action_success',
'action_info',
'action_text',
'action_danger',
'action_default',
Expand All @@ -40,6 +43,15 @@ public function testAutomaticOrdering(): void
$this->assertSame($expectedOrderBeforeSorting, $actionNames);
}

public function testInfoVariantSurvivesConfigObjectRoundTrip(): void
{
$action = Action::new('info_action')->linkToCrudAction('index')->asInfoAction();

$roundTripped = $action->getAsDto()->getAsConfigObject();

$this->assertSame(ButtonVariant::Info, $roundTripped->getAsDto()->getVariant());
}

public function testDisableAutomaticOrdering(): void
{
$actions = Actions::new();
Expand Down
Loading