You are here

class PrivateMessageController in Private Message 8

Same name and namespace in other branches
  1. 8.2 src/Controller/PrivateMessageController.php \Drupal\private_message\Controller\PrivateMessageController

Private message page controller. Returns render arrays for the page.

Hierarchy

Expanded class hierarchy of PrivateMessageController

File

src/Controller/PrivateMessageController.php, line 16

Namespace

Drupal\private_message\Controller
View source
class PrivateMessageController extends ControllerBase implements PrivateMessageControllerInterface {

  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountProxyInterface
   */
  protected $currentUser;

  /**
   * The entity manager service.
   *
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  protected $entityManager;

  /**
   * The form builder interface.
   *
   * @var \Drupal\Core\Form\FormBuilderInterface
   */
  protected $formBuilder;

  /**
   * The user data service.
   *
   * @var \Drupal\user\UserDataInterface
   */
  protected $userData;

  /**
   * The private message service.
   *
   * @var \Drupal\private_message\Service\PrivateMessageServiceInterface
   */
  protected $privateMessageService;

  /**
   * The user manager service.
   *
   * @var \Drupal\user\UserStorageInterface
   */
  protected $userManager;

  /**
   * Constructs a PrivateMessageForm object.
   *
   * @param \Drupal\Core\Session\AccountProxyInterface $currentUser
   *   The current user.
   * @param \Drupal\Core\Entity\EntityManagerInterface $entityManager
   *   The entity manager service.
   * @param \Drupal\Core\Form\FormBuilderInterface $formBuilder
   *   The form builder service.
   * @param \Drupal\user\UserDataInterface $userData
   *   The user data service.
   * @param \Drupal\private_message\Service\PrivateMessageServiceInterface $privateMessageService
   *   The private message service.
   */
  public function __construct(AccountProxyInterface $currentUser, EntityManagerInterface $entityManager, FormBuilderInterface $formBuilder, UserDataInterface $userData, PrivateMessageServiceInterface $privateMessageService) {
    $this->currentUser = $currentUser;
    $this->entityManager = $entityManager;
    $this->formBuilder = $formBuilder;
    $this->userData = $userData;
    $this->privateMessageService = $privateMessageService;
    $this->userManager = $entityManager
      ->getStorage('user');
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('current_user'), $container
      ->get('entity.manager'), $container
      ->get('form_builder'), $container
      ->get('user.data'), $container
      ->get('private_message.service'));
  }

  /**
   * {@inheritdoc}
   */
  public function privateMessagePage() {
    $this->privateMessageService
      ->updateLastCheckTime();
    $user = $this->userManager
      ->load($this->currentUser
      ->id());
    $private_message_thread = $this->privateMessageService
      ->getFirstThreadForUser($user);
    if ($private_message_thread) {
      $view_builder = $this->entityManager
        ->getViewBuilder('private_message_thread');

      // No wrapper is provided, as the full view mode of the entity already
      // provides the #private-message-page wrapper.
      $page = $view_builder
        ->view($private_message_thread);
    }
    else {
      $page = [
        '#prefix' => '<div id="private-message-page">',
        '#suffix' => '</div>',
        'no_threads' => [
          '#prefix' => '<p>',
          '#suffix' => '</p>',
          '#markup' => $this
            ->t('You do not have any messages'),
        ],
      ];
    }
    return $page;
  }

  /**
   * {@inheritdoc}
   */
  public function pmSettingsPage() {
    return [
      '#markup' => $this
        ->t('Private Messages'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function pmThreadSettingsPage() {
    return [
      '#markup' => $this
        ->t('Private Message Threads'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function configPage() {
    return [
      '#prefix' => '<div id="private_message_configuration_page">',
      '#suffix' => '</div>',
      'form' => $this->formBuilder
        ->getForm('Drupal\\private_message\\Form\\ConfigForm'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function adminUninstallPage() {
    return [
      '#prefix' => '<div id="private_message_admin_uninstall_page">',
      '#suffix' => '</div>',
      'form' => $this->formBuilder
        ->getForm('Drupal\\private_message\\Form\\AdminUninstallForm'),
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ControllerBase::$configFactory protected property The configuration factory.
ControllerBase::$entityFormBuilder protected property The entity form builder.
ControllerBase::$entityTypeManager protected property The entity type manager.
ControllerBase::$keyValue protected property The key-value storage. 1
ControllerBase::$languageManager protected property The language manager. 1
ControllerBase::$moduleHandler protected property The module handler. 2
ControllerBase::$stateService protected property The state service.
ControllerBase::cache protected function Returns the requested cache bin.
ControllerBase::config protected function Retrieves a configuration object.
ControllerBase::container private function Returns the service container.
ControllerBase::currentUser protected function Returns the current user. 1
ControllerBase::entityFormBuilder protected function Retrieves the entity form builder.
ControllerBase::entityManager Deprecated protected function Retrieves the entity manager service.
ControllerBase::entityTypeManager protected function Retrieves the entity type manager.
ControllerBase::formBuilder protected function Returns the form builder service. 2
ControllerBase::keyValue protected function Returns a key/value storage collection. 1
ControllerBase::languageManager protected function Returns the language manager service. 1
ControllerBase::moduleHandler protected function Returns the module handler. 2
ControllerBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
ControllerBase::state protected function Returns the state storage service.
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PrivateMessageController::$currentUser protected property The current user. Overrides ControllerBase::$currentUser
PrivateMessageController::$entityManager protected property The entity manager service. Overrides ControllerBase::$entityManager
PrivateMessageController::$formBuilder protected property The form builder interface. Overrides ControllerBase::$formBuilder
PrivateMessageController::$privateMessageService protected property The private message service.
PrivateMessageController::$userData protected property The user data service.
PrivateMessageController::$userManager protected property The user manager service.
PrivateMessageController::adminUninstallPage public function The page for preparing to uninstall the module. Overrides PrivateMessageControllerInterface::adminUninstallPage
PrivateMessageController::configPage public function
PrivateMessageController::create public static function Instantiates a new instance of this class. Overrides ControllerBase::create
PrivateMessageController::pmSettingsPage public function The private message module settings page. Overrides PrivateMessageControllerInterface::pmSettingsPage
PrivateMessageController::pmThreadSettingsPage public function The settings page specific to private message threads. Overrides PrivateMessageControllerInterface::pmThreadSettingsPage
PrivateMessageController::privateMessagePage public function The Private message page. Overrides PrivateMessageControllerInterface::privateMessagePage
PrivateMessageController::__construct public function Constructs a PrivateMessageForm object.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.