Message.php in Entity Legal 4.0.x
Same filename and directory in other branches
Namespace
Drupal\entity_legal\Plugin\EntityLegalFile
src/Plugin/EntityLegal/Message.phpView source
<?php
namespace Drupal\entity_legal\Plugin\EntityLegal;
use Drupal\entity_legal\EntityLegalPluginBase;
use Drupal\Core\Link;
/**
* Method class for alerting existing users via Drupal set message.
*
* @EntityLegal(
* id = "message",
* label = @Translation("Drupal warning message, prompting the user, until accepted"),
* type = "existing_users",
* )
*/
class Message extends EntityLegalPluginBase {
/**
* {@inheritdoc}
*/
public function execute(array &$context = []) {
/** @var \Drupal\entity_legal\EntityLegalDocumentInterface $document */
foreach ($this->documents as $document) {
$message = t('Please accept the @document_name.', [
'@document_name' => Link::createFromRoute($document
->getPublishedVersion()
->label(), 'entity.entity_legal_document.canonical', [
'entity_legal_document' => $document
->id(),
])
->toString(),
]);
\Drupal::messenger()
->addWarning($message);
}
}
}