Overrides ArgumentValidatorPluginBase::validateArgument
public function validateArgument($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
->label());
if (empty($types)) {
return TRUE;
}
return isset($types[$node->type]);
case 'nids':
$nids = new stdClass();
$nids->value = array(
$argument,
);
$nids = $this
->breakPhrase($argument, $nids);
if ($nids->value == array(
-1,
)) {
return FALSE;
}
$test = drupal_map_assoc($nids->value);
$titles = array();
$nodes = node_load_multiple($nids->value);
foreach ($nodes 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
->label());
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);
}
}