function Sql::buildOptionsForm

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::buildOptionsForm()
  2. 8.9.x core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::buildOptionsForm()
  3. 11.x core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::buildOptionsForm()

Add settings for the ui.

Overrides PluginBase::buildOptionsForm

File

core/modules/views/src/Plugin/views/query/Sql.php, line 295

Class

Sql
Views query plugin for an SQL query.

Namespace

Drupal\views\Plugin\views\query

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);
    $form['disable_sql_rewrite'] = [
        '#title' => $this->t('Disable SQL rewriting'),
        '#description' => $this->t('Disabling SQL rewriting will omit all query tags, i. e. disable node access checks as well as override hook_query_alter() implementations in other modules.'),
        '#type' => 'checkbox',
        '#default_value' => !empty($this->options['disable_sql_rewrite']),
        '#suffix' => '<div class="messages messages--warning sql-rewrite-warning js-hide">' . $this->t('WARNING: Disabling SQL rewriting means that node access security is disabled. This may allow users to see data they should not be able to see if your view is misconfigured. Use this option only if you understand and accept this security risk.') . '</div>',
    ];
    $form['distinct'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Distinct'),
        '#description' => $this->t('This will make the view display only distinct items. If there are multiple identical items, each will be displayed only once. You can use this to try and remove duplicates from a view, though it does not always work. Note that this can slow queries down, so use it with caution.'),
        '#default_value' => !empty($this->options['distinct']),
    ];
    $form['replica'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Use Secondary Server'),
        '#description' => $this->t('This will make the query attempt to connect to a replica server if available.  If no replica server is defined or available, it will fall back to the default server.'),
        '#default_value' => !empty($this->options['replica']),
    ];
    $form['query_comment'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Query Comment'),
        '#description' => $this->t('If set, this comment will be embedded in the query and passed to the SQL server. This can be helpful for logging or debugging.'),
        '#default_value' => $this->options['query_comment'],
    ];
    $form['query_tags'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Query Tags'),
        '#description' => $this->t('If set, these tags will be appended to the query and can be used to identify the query in a module. This can be helpful for altering queries.'),
        '#default_value' => implode(', ', $this->options['query_tags']),
        '#element_validate' => [
            'views_element_validate_tags',
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.