Add simple_message module

This commit is contained in:
Oliver Davies 2020-01-29 02:32:35 +00:00
parent 0fb0dd693e
commit 15985541ba
4 changed files with 54 additions and 0 deletions

View file

@ -34,6 +34,7 @@ module:
rdf: 0
search: 0
shortcut: 0
simple_message: 0
system: 0
taxonomy: 0
text: 0

View file

@ -0,0 +1,5 @@
name: Simple Message
description: Displays a simple message.
core: 8.x
type: module
package: Custom

View file

@ -0,0 +1,5 @@
services:
Drupal\simple_message\DisplaySimpleMessage:
autowire: true
tags:
- { name: event_subscriber }

View file

@ -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;
}
}