1 views_plugin_argument_validate_node.inc views_plugin_argument_validate_node::validate_argument($argument)

Overrides views_plugin_argument_validate::validate_argument

File

core/modules/node/views/views_plugin_argument_validate_node.inc, line 79
Contains the 'node' argument validator plugin.

Class

views_plugin_argument_validate_node
Validate whether an argument is an acceptable node.

Code

function validate_argument($argument) {
  $types = $this->options['types'];

  switch ($this->options['nid_type']) {
    case 'nid':
      if (!is_numeric($argument)) {
        return FALSE;
      }
      $node = node_load($argument);
      if (!$node) {
        return FALSE;
      }

      if (!empty($this->options['access'])) {
        if (!node_access($this->options['access_op'], $node)) {
          return FALSE;
        }
      }

      // Save the title() handlers some work.
      $this->argument->validated_title = check_plain($node->title);

      if (empty($types)) {
        return TRUE;
      }

      return isset($types[$node->type]);
      break;
    case 'nids':
      $nids = new stdClass();
      $nids->value = array($argument);
      $nids = views_break_phrase($argument, $nids);
      if ($nids->value == array(-1)) {
        return FALSE;
      }

      $test = backdrop_map_assoc($nids->value);
      $titles = array();

      $result = db_query("SELECT * FROM {node} WHERE nid IN (:nids)", array(':nids' => $nids->value));
      foreach ($result as $node) {
        if ($types && empty($types[$node->type])) {
          return FALSE;
        }

        if (!empty($this->options['access'])) {
          if (!node_access($this->options['access_op'], $node)) {
            return FALSE;
          }
        }

        $titles[] = check_plain($node->title);
        unset($test[$node->nid]);
      }

      $this->argument->validated_title = implode($nids->operator == 'or' ? ' + ' : ', ', $titles);
      // If this is not empty, we did not find a nid.
      return empty($test);
  }
}