Add simple_message module
This commit is contained in:
parent
0fb0dd693e
commit
15985541ba
|
@ -34,6 +34,7 @@ module:
|
|||
rdf: 0
|
||||
search: 0
|
||||
shortcut: 0
|
||||
simple_message: 0
|
||||
system: 0
|
||||
taxonomy: 0
|
||||
text: 0
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
name: Simple Message
|
||||
description: Displays a simple message.
|
||||
core: 8.x
|
||||
type: module
|
||||
package: Custom
|
|
@ -0,0 +1,5 @@
|
|||
services:
|
||||
Drupal\simple_message\DisplaySimpleMessage:
|
||||
autowire: true
|
||||
tags:
|
||||
- { name: event_subscriber }
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\simple_message;
|
||||
|
||||
use Drupal\Core\Messenger\MessengerInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
class DisplaySimpleMessage implements EventSubscriberInterface {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* The Messenger service.
|
||||
*
|
||||
* @var \Drupal\Core\Messenger\MessengerInterface
|
||||
*/
|
||||
private $messenger;
|
||||
|
||||
public function __construct(MessengerInterface $messenger) {
|
||||
$this->messenger = $messenger;
|
||||
}
|
||||
|
||||
public function displayMessage(GetResponseEvent $event) {
|
||||
$this->messenger->addMessage($this->t('This site is running on a <a href="@vagrant">Vagrant</a> server, deployed with <a href="@ansible">Ansible</a> and <a href="@ansistrano">Ansistrano</a>.', [
|
||||
'@ansible' => 'https://ansible.com',
|
||||
'@ansistrano' => 'https://ansistrano.com',
|
||||
'@vagrant' => 'https://vagrantup.com',
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function getSubscribedEvents() {
|
||||
$events[KernelEvents::REQUEST][] = ['displayMessage'];
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue