You are here

class NullArgument in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/argument/NullArgument.php \Drupal\views\Plugin\views\argument\NullArgument
  2. 9 core/modules/views/src/Plugin/views/argument/NullArgument.php \Drupal\views\Plugin\views\argument\NullArgument

Argument handler that ignores the argument.

Plugin annotation

@ViewsArgument("null");

Hierarchy

  • class \Drupal\views\Plugin\views\argument\NullArgument extends \Drupal\views\Plugin\views\argument\ArgumentPluginBase

Expanded class hierarchy of NullArgument

File

core/modules/views/src/Plugin/views/argument/NullArgument.php, line 14

Namespace

Drupal\views\Plugin\views\argument
View source
class NullArgument extends ArgumentPluginBase {
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['must_not_be'] = [
      'default' => FALSE,
    ];
    return $options;
  }

  /**
   * Override buildOptionsForm() so that only the relevant options
   * are displayed to the user.
   */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);
    $form['must_not_be'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Fail basic validation if any argument is given'),
      '#default_value' => !empty($this->options['must_not_be']),
      '#description' => $this
        ->t('By checking this field, you can use this to make sure views with more arguments than necessary fail validation.'),
      '#group' => 'options][more',
    ];
    unset($form['exception']);
  }

  /**
   * Override defaultActions() to remove actions that don't
   * make sense for a null argument.
   */
  protected function defaultActions($which = NULL) {
    if ($which) {
      if (in_array($which, [
        'ignore',
        'not found',
        'empty',
        'default',
      ])) {
        return parent::defaultActions($which);
      }
      return;
    }
    $actions = parent::defaultActions();
    unset($actions['summary asc']);
    unset($actions['summary desc']);
    return $actions;
  }

  /**
   * Override the behavior of query() to prevent the query
   * from being changed in any way.
   */
  public function query($group_by = FALSE) {
  }

}

Members

Namesort descending Modifiers Type Description Overrides
NullArgument::buildOptionsForm public function Override buildOptionsForm() so that only the relevant options are displayed to the user.
NullArgument::defaultActions protected function Override defaultActions() to remove actions that don't make sense for a null argument.
NullArgument::defineOptions protected function
NullArgument::query public function Override the behavior of query() to prevent the query from being changed in any way.