BrokenHandlerTrait.php 2.53 KB
Newer Older
1 2 3 4
<?php

namespace Drupal\views\Plugin\views;

5
use Drupal\Component\Utility\SafeMarkup;
6 7
use Drupal\Core\Form\FormStateInterface;

8 9 10 11 12 13 14 15
/**
 * A Trait for Views broken handlers.
 */
trait BrokenHandlerTrait {

  /**
   * Returns this handlers name in the UI.
   *
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 24
  }

  /**
   * The option definition for this handler.
   *
25
   * @see \Drupal\views\Plugin\views\PluginBase::defineOptions()
26 27
   */
  public function defineOptions() {
28
    return [];
29 30 31 32 33 34
  }

  /**
   * Ensure the main table for this handler is in the query. This is used
   * a lot.
   *
35
   * @see \Drupal\views\Plugin\views\HandlerBase::ensureMyTable()
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
   */
  public function ensureMyTable() {
    // No table to ensure.
  }

  /**
   * Modify the views query.
   */
  public function query($group_by = FALSE) {
    /* No query to run */
  }

  /**
   * Provides a form to edit options for this plugin.
   *
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 57
    foreach ($this->definition['original_configuration'] as $key => $value) {
      if (is_scalar($value)) {
58
        $items[] = SafeMarkup::format('@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 67 68 69
      '#attributes' => [
        'class' => ['js-form-item', 'form-item', 'description'],
      ],
      'description_top' => [
70
        '#markup' => '<p>' . $description_top . '</p>',
71 72
      ],
      'detail_list' => [
73 74
        '#theme' => 'item_list',
        '#items' => $items,
75 76
      ],
      'description_bottom' => [
77
        '#markup' => '<p>' . $description_bottom . '</p>',
78 79
      ],
    ];
80 81 82 83 84 85 86
  }

  /**
   * Determines if the handler is considered 'broken'.
   *
   * This means it's a placeholder used when a handler can't be found.
   *
87
   * @see \Drupal\views\Plugin\views\HandlerBase::broken()
88 89 90 91 92
   */
  public function broken() {
    return TRUE;
  }

93 94 95 96 97
  /**
   * Gets dependencies for a broken handler.
   *
   * @return array
   *
98
   * @see \Drupal\views\Plugin\views\PluginBase::calculateDependencies()
99 100 101 102 103
   */
  public function calculateDependencies() {
    return [];
  }

104
}