4fc03d3341caaa6e069ac5da8184c07a2bf3fc87
[yaffs-website] / src / Plugin / views / field / Language.php
1 <?php
2
3 namespace Drupal\redirect_404\Plugin\views\field;
4
5 use Drupal\Core\Language\LanguageManagerInterface;
6 use Drupal\Core\Session\AccountInterface;
7 use Drupal\views\Plugin\views\field\LanguageField;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9
10 /**
11  * Provides a views field for the 404 error language.
12  *
13  * @ingroup views_field_handlers
14  *
15  * @ViewsField("redirect_404_langcode")
16  */
17 class Language extends LanguageField {
18
19   /**
20    * The language manager.
21    *
22    * @var \Drupal\Core\Language\LanguageManagerInterface
23    */
24   protected $languageManager;
25
26   /**
27    * Constructs a Language object.
28    *
29    * @param array $configuration
30    *   A configuration array containing information about the plugin instance.
31    * @param string $plugin_id
32    *   The plugin_id for the plugin instance.
33    * @param mixed $plugin_definition
34    *   The plugin implementation definition.
35    * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
36    *   The language manager.
37    */
38   public function __construct(array $configuration, $plugin_id, $plugin_definition, LanguageManagerInterface $language_manager) {
39     parent::__construct($configuration, $plugin_id, $plugin_definition);
40
41     $this->languageManager = $language_manager;
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
48     return new static(
49       $configuration,
50       $plugin_id,
51       $plugin_definition,
52       $container->get('language_manager')
53     );
54   }
55
56   /**
57    * {@inheritdoc}
58    */
59   public function access(AccountInterface $account) {
60     return $this->languageManager->isMultilingual();
61   }
62
63 }