PrivateMessageActionsBlock.php in Private Message 8.2
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\Config\ConfigFactory;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PrivateMessageActionsBlock extends BlockBase implements BlockPluginInterface, ContainerFactoryPluginInterface {
protected $currentUser;
protected $configFactory;
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountProxyInterface $currentUser, ConfigFactory $configFactory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->currentUser = $currentUser;
$this->configFactory = $configFactory;
}
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('config.factory'));
}
public function build() {
if ($this->currentUser
->hasPermission('use private messaging system')) {
$config = $config = $this->configFactory
->get('private_message.settings');
$url = Url::fromRoute('private_message.private_message_create');
$block['links'] = [
'#type' => 'link',
'#title' => $config
->get("create_message_label"),
'#url' => $url,
];
$block['#attributes']['class'][] = 'block';
$block['#attributes']['class'][] = 'block-private-message';
$block['#attributes']['class'][] = 'block-private-message-actions-block';
return $block;
}
}
}