route_ui-1.0.0-alpha2/src/Plugin/views/area/CustomActionLinks.php
src/Plugin/views/area/CustomActionLinks.php
<?php
namespace Drupal\route_ui\Plugin\views\area;
use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\route_ui\CustomActionLinkPluginTrait;
use Drupal\views\Plugin\views\area\AreaPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Views area custom action links handler.
*
* @ingroup views_area_handlers
*
* @ViewsArea("custom_action_links")
*/
class CustomActionLinks extends AreaPluginBase {
use CustomActionLinkPluginTrait;
/**
* The access manager.
*
* @var \Drupal\Core\Access\AccessManagerInterface
*/
protected $accessManager;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $account;
/**
* CustomActionLinksBlock constructor.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Access\AccessManagerInterface $access_manager
* The access manager.
* @param \Drupal\Core\Session\AccountInterface $account
* The current user.
*/
public function __construct(array $configuration, string $plugin_id, array $plugin_definition, AccessManagerInterface $access_manager, AccountInterface $account) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->accessManager = $access_manager;
$this->account = $account;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('access_manager'),
$container->get('current_user')
);
}
/**
* {@inheritdoc}
*/
protected function defineOptions(): array {
$options = parent::defineOptions();
$options['custom_action_links'] = ['default' => []];
return $options;
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form = $this->buildRouteConfigureForm($form, $this->options);
}
/**
* {@inheritdoc}
*/
public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = []) {
parent::submitOptionsForm($form, $form_state);
$custom_action_links = $this->massageCustomActionLinksValue($form_state->getValue(['options', 'custom_action_links']));
$form_state->setValue(['options', 'custom_action_links'], $custom_action_links);
}
/**
* {@inheritdoc}
*/
public function render($empty = FALSE): array {
if ($empty && empty($this->options['empty'])) {
return [];
}
return $this->toRenderArray($this->options, $this->accessManager, $this->account);
}
}
