992e8e252f54a77b1c42f0e7278fbb950202f88e
[yaffs-website] / web / core / modules / views / src / Plugin / views / BrokenHandlerTrait.php
1 <?php
2
3 namespace Drupal\views\Plugin\views;
4
5 use Drupal\Component\Render\FormattableMarkup;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * A Trait for Views broken handlers.
10  */
11 trait BrokenHandlerTrait {
12
13   /**
14    * Returns this handlers name in the UI.
15    *
16    * @see \Drupal\views\Plugin\views\PluginBase::defineOptions()
17    */
18   public function adminLabel($short = FALSE) {
19     return t('Broken/missing handler');
20   }
21
22   /**
23    * The option definition for this handler.
24    *
25    * @see \Drupal\views\Plugin\views\PluginBase::defineOptions()
26    */
27   public function defineOptions() {
28     return [];
29   }
30
31   /**
32    * Ensure the main table for this handler is in the query. This is used
33    * a lot.
34    *
35    * @see \Drupal\views\Plugin\views\HandlerBase::ensureMyTable()
36    */
37   public function ensureMyTable() {
38     // No table to ensure.
39   }
40
41   /**
42    * Modify the views query.
43    */
44   public function query($group_by = FALSE) {
45     /* No query to run */
46   }
47
48   /**
49    * Provides a form to edit options for this plugin.
50    *
51    * @see \Drupal\views\Plugin\views\PluginBase::defineOptions()
52    */
53   public function buildOptionsForm(&$form, FormStateInterface $form_state) {
54     $description_top = t('The handler for this item is broken or missing. The following details are available:');
55
56     foreach ($this->definition['original_configuration'] as $key => $value) {
57       if (is_scalar($value)) {
58         $items[] = new FormattableMarkup('@key: @value', ['@key' => $key, '@value' => $value]);
59       }
60     }
61
62     $description_bottom = t('Enabling the appropriate module may solve this issue. Otherwise, check to see if there is a module update available.');
63
64     $form['description'] = [
65       '#type' => 'container',
66       '#attributes' => [
67         'class' => ['js-form-item', 'form-item', 'description'],
68       ],
69       'description_top' => [
70         '#markup' => '<p>' . $description_top . '</p>',
71       ],
72       'detail_list' => [
73         '#theme' => 'item_list',
74         '#items' => $items,
75       ],
76       'description_bottom' => [
77         '#markup' => '<p>' . $description_bottom . '</p>',
78       ],
79     ];
80   }
81
82   /**
83    * Determines if the handler is considered 'broken'.
84    *
85    * This means it's a placeholder used when a handler can't be found.
86    *
87    * @see \Drupal\views\Plugin\views\HandlerBase::broken()
88    */
89   public function broken() {
90     return TRUE;
91   }
92
93   /**
94    * Gets dependencies for a broken handler.
95    *
96    * @return array
97    *
98    * @see \Drupal\views\Plugin\views\PluginBase::calculateDependencies()
99    */
100   public function calculateDependencies() {
101     return [];
102   }
103
104 }