MessengerTrait.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/Messenger/MessengerTrait.php
  2. 8.9.x core/lib/Drupal/Core/Messenger/MessengerTrait.php
  3. 10 core/lib/Drupal/Core/Messenger/MessengerTrait.php

Namespace

Drupal\Core\Messenger

File

core/lib/Drupal/Core/Messenger/MessengerTrait.php

View source
<?php

namespace Drupal\Core\Messenger;


/**
 * Provides a trait for the messenger service.
 */
trait MessengerTrait {
    
    /**
     * The messenger.
     *
     * @var \Drupal\Core\Messenger\MessengerInterface
     */
    protected $messenger;
    
    /**
     * Sets the messenger.
     *
     * @param \Drupal\Core\Messenger\MessengerInterface $messenger
     *   The messenger.
     */
    public function setMessenger(MessengerInterface $messenger) {
        $this->messenger = $messenger;
    }
    
    /**
     * Gets the messenger.
     *
     * @return \Drupal\Core\Messenger\MessengerInterface
     *   The messenger.
     */
    public function messenger() {
        if (!isset($this->messenger)) {
            $this->messenger = \Drupal::messenger();
        }
        return $this->messenger;
    }

}

Traits

Title Deprecated Summary
MessengerTrait Provides a trait for the messenger service.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.