public function SimilarTermsArgument::validateArgument in Similar By Terms 8
Validate this argument works. By default, all arguments are valid.
Overrides ArgumentPluginBase::validateArgument
File
- src/
Plugin/ views/ argument/ SimilarTermsArgument.php, line 107
Class
- SimilarTermsArgument
- Argument handler to accept a node id.
Namespace
Drupal\similarterms\Plugin\views\argumentCode
public function validateArgument($arg) {
if (isset($this->argument_validated)) {
return $this->argument_validated;
}
$this->value = [
$arg => $arg,
];
$vocabulary_vids = empty($this->options['vocabularies']) ? [] : $this->options['vocabularies'];
foreach ($vocabulary_vids as $key => $val) {
if ($val === 0) {
unset($vocabulary_vids[$key]);
}
}
$select = $this->connection
->select('taxonomy_index', 'ti')
->fields('ti', [
'tid',
]);
if (count($vocabulary_vids)) {
$select
->join('taxonomy_term_data', 'td', 'ti.tid = td.tid');
$select
->condition('td.vid', $vocabulary_vids, 'IN');
}
$select
->condition('ti.nid', $this->value, 'IN');
$result = $select
->execute();
$this->tids = [];
foreach ($result as $row) {
$this->tids[$row->tid] = $row->tid;
}
$this->view->tids = $this->tids;
if (count($this->tids) == 0) {
return FALSE;
}
return TRUE;
}