PrivateMessageActionsBlock.php in Private Message 8
File
src/Plugin/Block/PrivateMessageActionsBlock.php
View source
<?php
namespace Drupal\private_message\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Routing\ResettableStackedRouteMatchInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PrivateMessageActionsBlock extends BlockBase implements BlockPluginInterface, ContainerFactoryPluginInterface {
protected $currentUser;
protected $currentRouteMatcher;
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountProxyInterface $currentUser, ResettableStackedRouteMatchInterface $currentRouteMatcher) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->currentUser = $currentUser;
$this->currentRouteMatcher = $currentRouteMatcher;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('current_user'), $container
->get('current_route_match'));
}
public function build() {
if ($this->currentUser
->hasPermission('use private messaging system') && $this->currentRouteMatcher
->getRouteName() == 'private_message.private_message_page') {
$url = Url::fromRoute('private_message.private_message_create');
$block['links'] = [
'#type' => 'link',
'#title' => $this
->t('Create Private Message'),
'#url' => $url,
];
$block['#attributes']['class'][] = 'block';
$block['#attributes']['class'][] = 'block-private-message';
$block['#attributes']['class'][] = 'block-private-message-actions-block';
return $block;
}
}
}