Type.php 936 Bytes
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Definition of Drupal\node\Plugin\views\argument\Type.
6 7
 */

8
namespace Drupal\node\Plugin\views\argument;
9

10
use Drupal\Component\Utility\String as UtilityString;
11
use Drupal\views\Plugin\views\argument\String;
12

13 14
/**
 * Argument handler to accept a node type.
15
 *
16
 * @ViewsArgument("node_type")
17 18
 */
class Type extends String {
19

20
  /**
21
   * Override the behavior of summaryName(). Get the user friendly version
22 23
   * of the node type.
   */
24
  public function summaryName($data) {
25 26 27 28 29 30 31 32 33 34 35
    return $this->node_type($data->{$this->name_alias});
  }

  /**
   * Override the behavior of title(). Get the user friendly version of the
   * node type.
   */
  function title() {
    return $this->node_type($this->argument);
  }

36 37 38
  function node_type($type_name) {
    $type = entity_load('node_type', $type_name);
    $output = $type ? $type->label() : t('Unknown content type');
39
    return UtilityString::checkPlain($output);
40
  }
41

42
}