class DigestFormatter in Message Digest 8
Message digest formatter service.
Hierarchy
- class \Drupal\message_digest\DigestFormatter implements DigestFormatterInterface
Expanded class hierarchy of DigestFormatter
1 string reference to 'DigestFormatter'
1 service uses DigestFormatter
File
- src/
DigestFormatter.php, line 12
Namespace
Drupal\message_digestView source
class DigestFormatter implements DigestFormatterInterface {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Construct the digest formatter service.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The rendering service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer) {
$this->entityTypeManager = $entity_type_manager;
$this->renderer = $renderer;
}
/**
* {@inheritdoc}
*/
public function format(array $digest, array $view_modes, UserInterface $recipient) {
$output = [
'#theme' => 'message_digest',
'#messages' => [],
];
foreach ($digest as $message) {
// Set the user to the recipient. This is similar to how message_subscribe
// works when sending a message to many different users.
$message
->setOwner($recipient);
$rows = [
'#theme' => 'message_digest_rows',
'#message' => $message,
];
foreach ($view_modes as $view_mode) {
$build = $this->entityTypeManager
->getViewBuilder('message')
->view($message, $view_mode);
$rows[] = $build;
}
$output[] = $rows;
}
return $this->renderer
->renderPlain($output);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DigestFormatter:: |
protected | property | The entity type manager service. | |
DigestFormatter:: |
protected | property | The renderer service. | |
DigestFormatter:: |
public | function |
Build the full message digest content for a given set of messages. Overrides DigestFormatterInterface:: |
|
DigestFormatter:: |
public | function | Construct the digest formatter service. |