heimrichhannot / contao-alert-reminder-bundle
This utility bundle offers functionality to remind the backend users of existing alerts in the Contao CMS.
Installs: 1 319
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 5
Forks: 0
Open Issues: 0
Type:contao-bundle
Requires
- php: ^7.4 || ^8.0
- contao/core-bundle: ^4.9
- heimrichhannot/contao-utils-bundle: ^2.229
- symfony/config: ^4.4||^5.4
- symfony/dependency-injection: ^4.4||^5.4
- symfony/event-dispatcher: ^4.4||^5.4
- symfony/event-dispatcher-contracts: ^1||^2||^3
- symfony/http-kernel: ^4.4||^5.4
- symfony/translation: ^4.4||^5.4
- symfony/translation-contracts: ^1.1.6||^2||^3
README
This utility bundle offers functionality to remind the backend users of existing alerts in the Contao CMS.
Features
- looks for existing (configurable) contao backend alerts (added via the hook
getSystemMessages
) and adds a backend message in order to remind the backend user of it
Use case
You might ask what's the use case of this functionality?
The original use case was in order to remind the backend users to add missing alt
attributes to images (accessibility).
Without the functionality, the user might forget about it. Making the alt
mandatory has also not been an option because of contao's simple file upload functionality which doesn't contain the field at all.
Hence the need for reminding the backend user of it.
Installation
- Run
composer require heimrichhannot/contao-alert-reminder-bundle
and update the database.
Technical instructions
Add new contao alerts to the context of this bundle
-
Register a
getSystemMessages
hook as usual in contao:// config.php (or use yaml tags in contao 4.9+) $GLOBALS['TL_HOOKS']['getSystemMessages']['myBundle'] = [ \Acme\MyBundle\EventListener\GetSystemMessagesListener::class, '__invoke' ];
// GetSystemMessagesListener.php namespace Acme\MyBundle\EventListener; use Acme\AlertReminderBundle\Manager\AlertReminderManager; use Acme\RequestBundle\Component\HttpFoundation\Request; use Symfony\Contracts\Translation\TranslatorInterface; class GetSystemMessagesListener { /** * @var TranslatorInterface */ private $translator; /** * @var Request */ private $request; /** * @var AlertReminderManager */ private $alertReminderManager; public function __construct(AlertReminderManager $alertReminderManager, TranslatorInterface $translator, Request $request) { $this->translator = $translator; $this->request = $request; $this->alertReminderManager = $alertReminderManager; } public function __invoke() { $message = '<p class="tl_error">My alert message</p>'; return $this->alertReminderManager->prepareSystemMessage($message, 'some_alert_type_alias'); } }
-
In order to activate the reminding you have to add your alert type in your project's
app/config/config.yml
:huh_alert_reminder: alert_types: - { name: some_alert_type_alias }
Add your alerts to the alert queue backend module
This bundle introduces the AlertQueueModule
. It's just a list of messages. You might use it to add the full list of
alerts you want to the user to notice. In the context of reminding the user of missing alt-attributes this is the place
to add shortcuts to the concrete media files.
You can add your messages by registering an event listener for the event AddAlertsToAlertReminderQueueEvent
for example as follows:
public function __invoke(AddAlertsToAlertReminderQueueEvent $event) { if ('alt_issues_existing' !== Input::get('type')) { return; } $messages = $event->getAlerts(); $messages[] = [ 'class' => 'tl_error', // you can use Contao's tl_ classes 'message' => 'My message' ]; $event->setAlerts($messages); }