PrivateMessageController.php in Private Message 8.2
File
src/Controller/PrivateMessageController.php
View source
<?php
namespace Drupal\private_message\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\private_message\Service\PrivateMessageServiceInterface;
use Drupal\user\UserDataInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PrivateMessageController extends ControllerBase implements PrivateMessageControllerInterface {
protected $currentUser;
protected $entityTypeManager;
protected $formBuilder;
protected $userData;
protected $privateMessageService;
protected $userManager;
public function __construct(AccountProxyInterface $currentUser, EntityTypeManagerInterface $entityTypeManager, FormBuilderInterface $formBuilder, UserDataInterface $userData, PrivateMessageServiceInterface $privateMessageService) {
$this->currentUser = $currentUser;
$this->entityTypeManager = $entityTypeManager;
$this->formBuilder = $formBuilder;
$this->userData = $userData;
$this->privateMessageService = $privateMessageService;
$this->userManager = $entityTypeManager
->getStorage('user');
}
public static function create(ContainerInterface $container) {
return new static($container
->get('current_user'), $container
->get('entity_type.manager'), $container
->get('form_builder'), $container
->get('user.data'), $container
->get('private_message.service'));
}
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->entityTypeManager
->getViewBuilder('private_message_thread');
$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;
}
public function pmSettingsPage() {
return [
'#markup' => $this
->t('Private Messages'),
];
}
public function pmThreadSettingsPage() {
return [
'#markup' => $this
->t('Private Message Threads'),
];
}
public function configPage() {
return [
'#prefix' => '<div id="private_message_configuration_page">',
'#suffix' => '</div>',
'form' => $this->formBuilder
->getForm('Drupal\\private_message\\Form\\ConfigForm'),
];
}
public function adminUninstallPage() {
return [
'#prefix' => '<div id="private_message_admin_uninstall_page">',
'#suffix' => '</div>',
'form' => $this->formBuilder
->getForm('Drupal\\private_message\\Form\\AdminUninstallForm'),
];
}
}