You are here

public function ViewsPhp::buildOptionsForm in Views PHP 8

Same name in this branch
  1. 8 src/Plugin/views/area/ViewsPhp.php \Drupal\views_php\Plugin\views\area\ViewsPhp::buildOptionsForm()
  2. 8 src/Plugin/views/filter/ViewsPhp.php \Drupal\views_php\Plugin\views\filter\ViewsPhp::buildOptionsForm()
  3. 8 src/Plugin/views/sort/ViewsPhp.php \Drupal\views_php\Plugin\views\sort\ViewsPhp::buildOptionsForm()
  4. 8 src/Plugin/views/access/ViewsPhp.php \Drupal\views_php\Plugin\views\access\ViewsPhp::buildOptionsForm()
  5. 8 src/Plugin/views/cache/ViewsPhp.php \Drupal\views_php\Plugin\views\cache\ViewsPhp::buildOptionsForm()
  6. 8 src/Plugin/views/field/ViewsPhp.php \Drupal\views_php\Plugin\views\field\ViewsPhp::buildOptionsForm()

Default options form that provides the label widget that all fields should have.

Overrides FieldPluginBase::buildOptionsForm

File

src/Plugin/views/field/ViewsPhp.php, line 56
Contains \Drupal\views_php\Plugin\views\field\ViewsPhp.

Class

ViewsPhp
A handler to provide a field that is constructed by the administrator using PHP.

Namespace

Drupal\views_php\Plugin\views\field

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $form += views_php_form_element($this, array(
    'use_php_setup',
    t('Use setup code'),
    t('If checked, you can provide PHP code to be run once right before execution of the view. This may be useful to define functions to be re-used in the value and/or output code.'),
  ), array(
    'php_setup',
    t('Setup code'),
    t('Code to run right before execution of the view.'),
    FALSE,
  ), array(
    '$view',
    '$handler',
    '$static',
  ));
  $form += views_php_form_element($this, FALSE, array(
    'php_value',
    t('Value code'),
    t('Code to construct the value of this field.'),
    FALSE,
  ), array(
    '$view',
    '$handler',
    '$static',
    '$row',
  ));
  $form += views_php_form_element($this, array(
    'use_php_click_sortable',
    t('Enable click sort'),
    t('If checked, you can use PHP code to enable click sort on the field.'),
  ), array(
    'php_click_sortable',
    t('Click sort code'),
    t('The comparison code must return an integer less than, equal to, or greater than zero if the first row should respectively appear before, stay where it was compared to, or appear after the second row.'),
    FALSE,
  ), array(
    '$view',
    '$handler',
    '$static',
    '$row1' => t('Data of row.'),
    '$row2' => t('Data of row to compare against.'),
  ));
  $form['use_php_click_sortable']['#type'] = 'select';
  $form['use_php_click_sortable']['#options'] = array(
    self::CLICK_SORT_DISABLED => t('No'),
    self::CLICK_SORT_NUMERIC => t('Sort numerically'),
    self::CLICK_SORT_ALPHA => t('Sort alphabetically'),
    self::CLICK_SORT_ALPHA_CASE => t('Sort alphabetically (case insensitive)'),
    self::CLICK_SORT_NAT => t('Sort using a "natural order" algorithm'),
    self::CLICK_SORT_NAT_CASE => t('Sort using a "natural order" algorithm (case insensitive)'),
    self::CLICK_SORT_PHP => t('Sort using custom PHP code'),
  );
  $form['use_php_click_sortable']['#default_value'] = $this->options['use_php_click_sortable'];
  $form['php_click_sortable']['#states'] = array(
    'visible' => array(
      ':input[name="options[use_php_click_sortable]"]' => array(
        'value' => (string) self::CLICK_SORT_PHP,
      ),
    ),
  );
  $form += views_php_form_element($this, FALSE, array(
    'php_output',
    t('Output code'),
    t('Code to construct the output of this field.'),
    TRUE,
  ), array(
    '$view',
    '$handler',
    '$static',
    '$row',
    '$data',
    '$value' => t('Value of this field.'),
  ));
  $form['#attached']['library'][] = 'views_php/drupal.views_php';
}