3 namespace Drupal\redirect_404\Plugin\views\field;
5 use Drupal\Core\Entity\EntityTypeManagerInterface;
6 use Drupal\Core\Render\RendererInterface;
7 use Drupal\Core\Session\AccountInterface;
9 use Drupal\views\Plugin\views\field\FieldPluginBase;
10 use Drupal\views\ResultRow;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
14 * Provides a views field for the redirect operation buttons.
16 * @ingroup views_field_handlers
18 * @ViewsField("redirect_404_operations")
20 class Redirect404Operations extends FieldPluginBase {
23 * The entity type manager.
25 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
27 protected $entityTypeManager;
30 * The renderer service.
32 * @var \Drupal\Core\Render\RendererInterface
37 * Constructor for the redirect operations view field.
39 * @param array $configuration
40 * A configuration array containing information about the plugin instance.
41 * @param string $plugin_id
42 * The plugin_id for the plugin instance.
43 * @param mixed $plugin_definition
44 * The plugin implementation definition.
45 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
46 * The entity type manager.
47 * @param \Drupal\Core\Render\RendererInterface $renderer
48 * The renderer service.
49 * @param \Drupal\Core\Session\AccountInterface $current_user
52 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer, AccountInterface $current_user) {
53 parent::__construct($configuration, $plugin_id, $plugin_definition);
54 $this->entityTypeManager = $entity_type_manager;
55 $this->renderer = $renderer;
56 $this->currentUser = $current_user;
62 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
67 $container->get('entity_type.manager'),
68 $container->get('renderer'),
69 $container->get('current_user')
76 public function clickSortable() {
83 public function render(ResultRow $values) {
88 'source' => ltrim($this->getValue($values, 'path'), '/'),
89 'language' => $this->getValue($values, 'langcode'),
90 'destination' => $this->view->getPath(),
94 'title' => $this->t('Add redirect'),
95 'url' => Url::fromRoute('redirect.add', [], $query),
98 if ($this->currentUser->hasPermission('administer redirect settings')) {
100 'title' => $this->t('Ignore'),
101 'url' => Url::fromRoute('redirect_404.ignore_404', [
102 'path' => $this->getValue($values, 'path'),
103 'langcode' => $this->getValue($values, 'langcode'),
108 $operations['data'] = [
109 '#type' => 'operations',
113 return $this->renderer->render($operations);
119 public function access(AccountInterface $account) {
120 return $this->entityTypeManager->getAccessControlHandler('redirect')->createAccess();