StringContainsArgument.php in Media Directories 2.x
File
modules/media_directories_ui/src/Plugin/views/argument/StringContainsArgument.php
View source
<?php
namespace Drupal\media_directories_ui\Plugin\views\argument;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
class StringContainsArgument extends ArgumentPluginBase {
public $operator;
public $value;
public function title() {
if (!$this->argument) {
return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : $this
->t('Uncategorized');
}
if (!empty($this->options['break_phrase'])) {
$break = static::breakString($this->argument, FALSE);
$this->value = $break->value;
$this->operator = $break->operator;
}
else {
$this->value = [
$this->argument,
];
$this->operator = 'or';
}
if (empty($this->value)) {
return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : $this
->t('Uncategorized');
}
if ($this->value === [
'',
]) {
return !empty($this->definition['invalid input']) ? $this->definition['invalid input'] : $this
->t('Invalid input');
}
return implode($this->operator == 'or' ? ' + ' : ', ', $this
->titleQuery());
}
public function titleQuery() {
return $this->value;
}
public function query($group_by = FALSE) {
$this
->ensureMyTable();
$this->value = $this->argument;
$placeholder = $this
->placeholder();
$null_check = '';
if (!empty($this->value)) {
$operator = empty($this->options['not']) ? 'LIKE' : 'NOT LIKE';
$new_group = $this->query
->setWhereGroup();
$this->query
->addWhereExpression($new_group, "{$this->tableAlias}.{$this->realField} {$operator} {$placeholder}" . $null_check, [
$placeholder => '%' . $this->argument . '%',
]);
}
}
public function getSortName() {
return $this
->t('Alphabetical', [], [
'context' => 'Sort order',
]);
}
public function getContextDefinition() {
if ($context_definition = parent::getContextDefinition()) {
return $context_definition;
}
return new ContextDefinition('string', $this
->adminLabel(), FALSE);
}
}