Node.php 878 Bytes
Newer Older
1
2
3
4
<?php

/**
 * @file
5
 * Definition of Drupal\node\Plugin\views\argument_default\Node.
6
7
 */

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

10
use Drupal\views\Annotation\ViewsArgumentDefault;
11
use Drupal\Core\Annotation\Translation;
12
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
13
14
15
16
17

/**
 * Default argument plugin to extract a node via menu_get_object
 *
 * This plugin actually has no options so it odes not need to do a great deal.
18
 *
19
 * @ViewsArgumentDefault(
aspilicious's avatar
aspilicious committed
20
 *   id = "node",
21
22
23
24
 *   title = @Translation("Content ID from URL")
 * )
 */
class Node extends ArgumentDefaultPluginBase {
25

26
  public function getArgument() {
27
28
29
    foreach (range(1, 3) as $i) {
      $node = menu_get_object('node', $i);
      if (!empty($node)) {
30
        return $node->id();
31
32
33
34
35
36
37
      }
    }

    if (arg(0) == 'node' && is_numeric(arg(1))) {
      return arg(1);
    }
  }
38

39
}