FormatName.php 1.35 KB
Newer Older
1
2
3
4
<?php

/**
 * @file
5
 * Definition of Views\filter\Plugin\views\field\FormatName.
6
7
 */

8
namespace Views\filter\Plugin\views\field;
9

10
use Drupal\views\Plugin\views\field\FieldPluginBase;
11
use Drupal\Core\Annotation\Plugin;
12
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
13

14
15
16
17
/**
 * Field handler to output the name of an input format.
 *
 * @ingroup views_field_handlers
18
 *
19
 * @Plugin(
20
21
 *   id = "filter_format_name",
 *   module = "filter"
22
23
24
 * )
 */
class FormatName extends FieldPluginBase {
25

26
27
28
29
30
31
  /**
   * Constructs a FormatName object.
   */
  public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery) {
    parent::__construct($configuration, $plugin_id, $discovery);

32
33
34
35
    // Be explicit about the table we are using.
    $this->additional_fields['name'] = array('table' => 'filter_formats', 'field' => 'name');
  }

36
  public function query() {
37
    $this->ensureMyTable();
38
39
40
41
42
43
44
45
46
47
    $this->add_additional_fields();
  }

  function render($values) {
    $format_name = $this->get_value($values, 'name');
    if (!$format_name) {
      // Default or invalid input format.
      // filter_formats() will reliably return the default format even if the
      // current user is unprivileged.
      $format = filter_formats(filter_default_format());
48
      return $this->sanitizeValue($format->name);
49
    }
50
    return $this->sanitizeValue($format_name);
51
  }
52

53
}