You are here

function Field::multiple_options_form in Views (for Drupal 7) 8.3

Provide options for multiple value fields.

1 call to Field::multiple_options_form()
Field::buildOptionsForm in lib/Views/field/Plugin/views/field/Field.php
Default options form that provides the label widget that all fields should have.

File

lib/Views/field/Plugin/views/field/Field.php, line 450
Definition of Views\field\Plugin\views\field\Field.

Class

Field
A field that displays fieldapi fields.

Namespace

Views\field\Plugin\views\field

Code

function multiple_options_form(&$form, &$form_state) {
  $field = $this->field_info;
  $form['multiple_field_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Multiple field settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => 5,
  );
  $form['group_rows'] = array(
    '#title' => t('Display all values in the same row'),
    '#type' => 'checkbox',
    '#default_value' => $this->options['group_rows'],
    '#description' => t('If checked, multiple values for this field will be shown in the same row. If not checked, each value in this field will create a new row. If using group by, please make sure to group by "Entity ID" for this setting to have any effect.'),
    '#fieldset' => 'multiple_field_settings',
  );

  // Make the string translatable by keeping it as a whole rather than
  // translating prefix and suffix separately.
  list($prefix, $suffix) = explode('@count', t('Display @count value(s)'));
  if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) {
    $type = 'textfield';
    $options = NULL;
    $size = 5;
  }
  else {
    $type = 'select';
    $options = drupal_map_assoc(range(1, $field['cardinality']));
    $size = 1;
  }
  $form['multi_type'] = array(
    '#type' => 'radios',
    '#title' => t('Display type'),
    '#options' => array(
      'ul' => t('Unordered list'),
      'ol' => t('Ordered list'),
      'separator' => t('Simple separator'),
    ),
    '#states' => array(
      'visible' => array(
        ':input[name="options[group_rows]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
    '#default_value' => $this->options['multi_type'],
    '#fieldset' => 'multiple_field_settings',
  );
  $form['separator'] = array(
    '#type' => 'textfield',
    '#title' => t('Separator'),
    '#default_value' => $this->options['separator'],
    '#states' => array(
      'visible' => array(
        ':input[name="options[group_rows]"]' => array(
          'checked' => TRUE,
        ),
        ':input[name="options[multi_type]"]' => array(
          'value' => 'separator',
        ),
      ),
    ),
    '#fieldset' => 'multiple_field_settings',
  );
  $form['delta_limit'] = array(
    '#type' => $type,
    '#size' => $size,
    '#field_prefix' => $prefix,
    '#field_suffix' => $suffix,
    '#options' => $options,
    '#default_value' => $this->options['delta_limit'],
    '#prefix' => '<div class="container-inline">',
    '#states' => array(
      'visible' => array(
        ':input[name="options[group_rows]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
    '#fieldset' => 'multiple_field_settings',
  );
  list($prefix, $suffix) = explode('@count', t('starting from @count'));
  $form['delta_offset'] = array(
    '#type' => 'textfield',
    '#size' => 5,
    '#field_prefix' => $prefix,
    '#field_suffix' => $suffix,
    '#default_value' => $this->options['delta_offset'],
    '#states' => array(
      'visible' => array(
        ':input[name="options[group_rows]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
    '#description' => t('(first item is 0)'),
    '#fieldset' => 'multiple_field_settings',
  );
  $form['delta_reversed'] = array(
    '#title' => t('Reversed'),
    '#type' => 'checkbox',
    '#default_value' => $this->options['delta_reversed'],
    '#suffix' => $suffix,
    '#states' => array(
      'visible' => array(
        ':input[name="options[group_rows]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
    '#description' => t('(start from last values)'),
    '#fieldset' => 'multiple_field_settings',
  );
  $form['delta_first_last'] = array(
    '#title' => t('First and last only'),
    '#type' => 'checkbox',
    '#default_value' => $this->options['delta_first_last'],
    '#suffix' => '</div>',
    '#states' => array(
      'visible' => array(
        ':input[name="options[group_rows]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
    '#fieldset' => 'multiple_field_settings',
  );
}