defineOptions example

/** * Argument handler that ignores the argument. * * @ingroup views_argument_handlers * * @ViewsArgument("null") */
class NullArgument extends ArgumentPluginBase {

  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['must_not_be'] = ['default' => FALSE];
    return $options;
  }

  /** * {@inheritdoc} */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);
    $form['must_not_be'] = [
      '#type' => 'checkbox',
      
/** * A string which will be output when the view is rendered. * * @var string */
  public $output;

  /** * {@inheritdoc} */
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['test_option'] = ['default' => ''];

    return $options;
  }

  /** * {@inheritdoc} */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);

    
public static function create(ContainerInterface $container, array $configuration$plugin_id$plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('pager.manager'),
      $container->get('pager.parameters')
    );
  }

  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['items_per_page'] = ['default' => 10];
    $options['offset'] = ['default' => 0];
    $options['id'] = ['default' => 0];
    $options['total_pages'] = ['default' => ''];
    $options['expose'] = [
      'contains' => [
        'items_per_page' => ['default' => FALSE],
        'items_per_page_label' => ['default' => $this->t('Items per page')],
        'items_per_page_options' => ['default' => '5, 10, 25, 50'],
        'items_per_page_options_all' => ['default' => FALSE],
        'items_per_page_options_all_label' => ['default' => $this->t('- All -')],

        
$configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('date.formatter')
    );
  }

  /** * {@inheritdoc} */
  protected function defineOptions() {
    $options = parent::defineOptions();

    $options['granularity'] = ['default' => 2];

    return $options;
  }

  /** * {@inheritdoc} */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);

    
// Don't add the additional fields to groupby     if (!empty($this->options['link_to_node'])) {
      $this->additional_fields['nid'] = ['table' => 'node_field_data', 'field' => 'nid'];
    }
  }

  /** * {@inheritdoc} */
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['link_to_node'] = ['default' => $this->definition['link_to_node default'] ?? FALSE];
    return $options;
  }

  /** * Provide link to node option. */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    $form['link_to_node'] = [
      '#title' => $this->t('Link this field to the original piece of content'),
      '#description' => $this->t("Enable to override this field's links."),
      

class NumericArgument extends ArgumentPluginBase {

  /** * The actual value which is used for querying. * @var array */
  public $value;

  protected function defineOptions() {
    $options = parent::defineOptions();

    $options['break_phrase'] = ['default' => FALSE];
    $options['not'] = ['default' => FALSE];

    return $options;
  }

  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);

    // allow + for or, , for and

class InputRequired extends ExposedFormPluginBase {

  protected function defineOptions() {
    $options = parent::defineOptions();

    $options['text_input_required'] = ['default' => $this->t('Select any filter and click on Apply to see results')];
    $options['text_input_required_format'] = ['default' => NULL];
    return $options;
  }

  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);

    $form['text_input_required'] = [
      '#type' => 'text_format',
      

  public static function create(ContainerInterface $container, array $configuration$plugin_id$plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('date.formatter')
    );
  }

  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['results_lifespan'] = ['default' => 3600];
    $options['results_lifespan_custom'] = ['default' => 0];
    $options['output_lifespan'] = ['default' => 3600];
    $options['output_lifespan_custom'] = ['default' => 0];

    return $options;
  }

  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);
    $options = [60, 300, 1800, 3600, 21600, 518400];
    
/** * {@inheritdoc} */
  protected function getDefaultLabel() {
    return $this->t('view');
  }

  /** * {@inheritdoc} */
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['output_url_as_text'] = ['default' => FALSE];
    $options['absolute'] = ['default' => FALSE];
    return $options;
  }

  /** * {@inheritdoc} */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    $form['output_url_as_text'] = [
      '#type' => 'checkbox',
      

  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
    parent::init($view$display$options);
    $this->entityType = $this->definition['entity_type'];
  }

  /** * {@inheritdoc} */
  protected function defineOptions() {
    $options = parent::defineOptions();

    // Per default we enable tokenize, as this is the most common use case for     // this handler.     $options['tokenize']['default'] = TRUE;

    // Contains the config target identifier for the entity.     $options['target'] = ['default' => ''];
    $options['view_mode'] = ['default' => 'default'];
    $options['bypass_access'] = ['default' => FALSE];

    return $options;
  }
$plugin_id,
      $plugin_definition,
      $container->get('path_alias.manager'),
      $container->get('path.current')
    );
  }

  /** * {@inheritdoc} */
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['index'] = ['default' => ''];
    $options['use_alias'] = ['default' => FALSE];

    return $options;
  }

  /** * {@inheritdoc} */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);
    
// Attach a link to the RSS feed, which is an alternate representation.     $build['#attached']['html_head_link'][][] = [
      'rel' => 'alternate',
      'type' => 'application/rss+xml',
      'title' => $title,
      'href' => $url,
    ];
  }

  protected function defineOptions() {
    $options = parent::defineOptions();

    $options['description'] = ['default' => ''];

    return $options;
  }

  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);

    $form['description'] = [
      '#type' => 'textfield',
      
$plugin_id,
      $plugin_definition,
      $container->get('entity_type.manager'),
      $container->get('plugin.manager.block')
    );
  }

  /** * {@inheritdoc} */
  protected function defineOptions() {
    $options = parent::defineOptions();

    $options['block_description'] = ['default' => ''];
    $options['block_category'] = ['default' => $this->t('Lists (Views)')];
    $options['block_hide_empty'] = ['default' => FALSE];

    $options['allow'] = [
      'contains' => [
        'items_per_page' => ['default' => 'items_per_page'],
      ],
    ];

    

class UserRow extends EntityRow {

  /** * {@inheritdoc} */
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['view_mode']['default'] = 'full';

    return $options;
  }

}

class Url extends FieldPluginBase {

  /** * {@inheritdoc} */
  protected function defineOptions() {
    $options = parent::defineOptions();

    $options['display_as_link'] = ['default' => TRUE];

    return $options;
  }

  /** * Provide link to the page being visited. */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    $form['display_as_link'] = [
      
Home | Imprint | This part of the site doesn't use cookies.