added translation domain for dashboard widgets (#3909)

This commit is contained in:
Kevin Papst
2023-03-08 19:01:49 +01:00
committed by GitHub
parent 9d503300f6
commit aebd57e311
8 changed files with 53 additions and 439 deletions

View File

@@ -245,6 +245,8 @@ final class DashboardController extends AbstractController
$choices = [];
// the list of widgets for the dropdown is created in the EventListener and not here
// this form is mainly used for saving
foreach ($available as $widget) {
if (empty($widget->getTitle())) {
continue;
@@ -293,7 +295,6 @@ final class DashboardController extends AbstractController
return $this->render('dashboard/grid.html.twig', [
'page_setup' => $page,
'widgets' => $widgets,
'available' => $available,
'form' => $form->createView(),
]);
}

View File

@@ -67,7 +67,7 @@ final class DashboardSubscriber extends AbstractActionsSubscriber
continue;
}
$event->addActionToSubmenu('widget_add', $widget->getId(), ['url' => $this->path('dashboard_add', ['widget' => $widget->getId()]), 'title' => $widget->getTitle()]);
$event->addActionToSubmenu('widget_add', $widget->getId(), ['url' => $this->path('dashboard_add', ['widget' => $widget->getId()]), 'title' => $widget->getTitle(), 'translation_domain' => $widget->getTranslationDomain()]);
}
$event->addAction('reset', ['title' => 'action.reset', 'url' => $this->path('dashboard_reset'), 'icon' => 'delete', 'class' => 'confirmation-link', 'attr' => ['data-question' => 'confirm.delete']]);

View File

@@ -18,6 +18,11 @@ abstract class AbstractWidget implements WidgetInterface
private array $options = [];
private ?User $user = null;
public function getTranslationDomain(): string
{
return 'messages';
}
public function hasForm(): bool
{
return false;

View File

@@ -12,6 +12,10 @@ namespace App\Widget;
use App\Entity\User;
use Symfony\Component\Form\Form;
/**
* No BC promise!
* Use AbstractWidget to get a BC safe base class.
*/
interface WidgetInterface
{
public const COLOR_TODAY = 'green';
@@ -32,37 +36,31 @@ interface WidgetInterface
/**
* Returns a unique ID for this widget.
*
* @return string
*/
public function getId(): string;
/**
* Returns the widget title (must be non-empty).
*
* @return string
*/
public function getTitle(): string;
/**
* Returns the translation domain used by this widget.
*/
public function getTranslationDomain(): string;
/**
* Returns the height for this widget.
*
* @return int
*/
public function getHeight(): int;
/**
* Returns the width for this widget.
*
* @return int
*/
public function getWidth(): int;
/**
* Injects the current user.
*
* @param User $user
* @return void
*/
public function setUser(User $user): void;
@@ -87,8 +85,8 @@ interface WidgetInterface
* You can validate the options or simply return:
* return array_merge($this->options, $options);
*
* @param array $options
* @return array
* @param array<string, string|bool|int|null> $options
* @return array<string, string|bool|int|null|null>
*/
public function getOptions(array $options = []): array;
@@ -96,9 +94,6 @@ interface WidgetInterface
* Sets one widget option, both for internal use and for frontend rendering.
*
* The given option should be persisted and permanently overwrite the internal option.
*
* @param string $name
* @param string|bool|int $value
*/
public function setOption(string $name, string|bool|int $value): void;
@@ -112,29 +107,21 @@ interface WidgetInterface
/**
* Returns the template, which is used to render the widget.
*
* @return string
*/
public function getTemplateName(): string;
/**
* Whether this widget can be configured with options.
*
* @return bool
*/
public function hasForm(): bool;
/**
* A form to edit the widget options or null, if it can't be configured.
*
* @return Form|null
*/
public function getForm(): ?Form;
/**
* Whether this is a widget that is supposed to be selectable by the end-user.
*
* @return bool
*/
public function isInternal(): bool;
}