Skip to content
Snippets Groups Projects
Commit 67e1979f authored by Shibin Das's avatar Shibin Das
Browse files

Issue #3465208: Create a demo page to showcase Drupal Status messages

parent 073209a0
No related branches found
No related tags found
No related merge requests found
......@@ -13,3 +13,11 @@ fsk_demo.user_login:
_title: 'User Login'
requirements:
_access: 'TRUE'
fsk_demo.fsk_demo_status_messages:
path: '/fsk-demo/status-messages'
defaults:
_title: 'Demo Status Messages'
_controller: '\Drupal\fsk_demo\Controller\FskDemoStatusMessagesController'
requirements:
_permission: 'access content'
<?php
declare(strict_types=1);
namespace Drupal\fsk_demo\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Returns responses for Factorial Starter Kit Demo routes.
*/
final class FskDemoStatusMessagesController implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The controller constructor.
*/
public function __construct(
private readonly MessengerInterface $messenger,
) {}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container): self {
return new self(
$container->get('messenger'),
);
}
/**
* Builds the response.
*/
public function __invoke(): array {
$url = \Drupal\Core\Url::fromUri('https://api.drupal.org/api/drupal/core%21modules%21system%21templates%21status-messages.html.twig/10', ['absolute' => TRUE]);
$link = \Drupal::linkGenerator()->generate('Drupal API', $url);
$this->messenger->addStatus('A "status" message (this was printed first).');
$this->messenger->addStatus('Another "status" message.');
$this->messenger->addMessage('A "default" message.');
$this->messenger->addMessage('Another "default" message.');
$this->messenger->addWarning('A "warning" message.');
$this->messenger->addError('An "error" message.');
$this->messenger->addStatus('A "status" message which was printed after some errors and warning were printed would still appear along with other status messages..');
$this->messenger->addStatus($this->t('A "status" message can also have links like this @link.', ['@link' => $link]));
$build['heading'] = [
'#type' => 'item',
'#markup' => $this->t('Fsk Demo status messages.'),
];
$build['description'] = [
'#type' => 'item',
'#markup' => $this->t('More information about status messages is available at <a href=',['@link' => '']),
];
return $build;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment