Skip to content

Commit 1deb1c4

Browse files
committed
-
1 parent 79ad886 commit 1deb1c4

File tree

4 files changed

+10
-23
lines changed

4 files changed

+10
-23
lines changed

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Welcome, 🤖 AI assistant! Please follow these guidelines when contributing to
9494
- Use the custom Twig components defined in templates/components/ when needed
9595
- Follow accessibility best practices (e.g. `aria-*, semantic tags, labels)
9696
- Use trans for all user-facing strings; never hardcode text in templates
97+
- All translations must be done in Twig templates using `|trans`; avoid translation logic in PHP code (use TranslatableInterface objects that will be translated in templates)
9798

9899
## JavaScript
99100

src/Dto/ActionDto.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class ActionDto
2121
private ?string $icon = null;
2222
private string $cssClass = '';
2323
private string $addedCssClass = '';
24-
/** @var array<string, string> */
24+
/** @var array<string, string|TranslatableInterface> */
2525
private array $htmlAttributes = [];
2626
private ?string $linkUrl = null;
2727
private ?string $templatePath = null;
@@ -39,7 +39,6 @@ final class ActionDto
3939
private ButtonType $buttonType = ButtonType::Submit;
4040
private ButtonVariant $variant = ButtonVariant::Default;
4141
private ButtonStyle $style = ButtonStyle::Solid;
42-
private string|TranslatableInterface|null $batchConfirmationMessage = null;
4342

4443
public function getType(): string
4544
{
@@ -168,30 +167,30 @@ public function setButtonType(ButtonType $buttonType): void
168167
}
169168

170169
/**
171-
* @return array<string, string>
170+
* @return array<string, string|TranslatableInterface>
172171
*/
173172
public function getHtmlAttributes(): array
174173
{
175174
return $this->htmlAttributes;
176175
}
177176

178177
/**
179-
* @param array<string, string> $htmlAttributes
178+
* @param array<string, string|TranslatableInterface> $htmlAttributes
180179
*/
181180
public function addHtmlAttributes(array $htmlAttributes): void
182181
{
183182
$this->htmlAttributes = array_merge($this->htmlAttributes, $htmlAttributes);
184183
}
185184

186185
/**
187-
* @param array<string, string> $htmlAttributes
186+
* @param array<string, string|TranslatableInterface> $htmlAttributes
188187
*/
189188
public function setHtmlAttributes(array $htmlAttributes): void
190189
{
191190
$this->htmlAttributes = $htmlAttributes;
192191
}
193192

194-
public function setHtmlAttribute(string $attributeName, string $attributeValue): void
193+
public function setHtmlAttribute(string $attributeName, string|TranslatableInterface $attributeValue): void
195194
{
196195
$this->htmlAttributes[$attributeName] = $attributeValue;
197196
}
@@ -355,16 +354,6 @@ public function usesTextStyle(): bool
355354
return ButtonStyle::Text === $this->style;
356355
}
357356

358-
public function getBatchConfirmationMessage(): string|TranslatableInterface|null
359-
{
360-
return $this->batchConfirmationMessage;
361-
}
362-
363-
public function setBatchConfirmationMessage(string|TranslatableInterface|null $message): void
364-
{
365-
$this->batchConfirmationMessage = $message;
366-
}
367-
368357
/**
369358
* @internal
370359
*/

src/Factory/ActionFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ private function processAction(string $pageName, ActionDto $actionDto, ?EntityDt
229229

230230
// if the confirmation config is not a boolean, it's a string or TranslatableInterface with the custom confirmation message
231231
if (true !== $confirmationConfig) {
232-
$actionDto->setBatchConfirmationMessage($confirmationConfig);
232+
$batchActionAttributes['data-batch-action-confirm-message'] = $confirmationConfig instanceof TranslatableInterface
233+
? $confirmationConfig
234+
: t($confirmationConfig, $defaultTranslationParameters, $translationDomain);
233235
}
234236
}
235237

templates/crud/action.html.twig

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@
22
{# @var action \EasyCorp\Bundle\EasyAdminBundle\Dto\ActionDto #}
33
{# @var entity \EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto #}
44

5-
{% set html_attributes = action.htmlAttributes %}
6-
{% if action.batchConfirmationMessage is not null %}
7-
{% set html_attributes = html_attributes|merge({'data-batch-action-confirm-message': action.batchConfirmationMessage|trans}) %}
8-
{% endif %}
9-
105
<twig:ea:Button
116
variant="{{ action.variant }}"
127
isInvisible="{{ action.usesTextStyle }}"
138
class="{{ action.htmlElement.isLink and isIncludedInDropdown|default(false) ? 'dropdown-item' }} {{ action.cssClass }}"
14-
htmlAttributes="{{ html_attributes }}"
9+
htmlAttributes="{{ action.htmlAttributes }}"
1510
htmlElement="{{ action.htmlElement }}"
1611
type="{{ action.buttonType.value }}"
1712
icon="{{ action.icon }}"

0 commit comments

Comments
 (0)