function EntityField::multiple_options_form

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/field/EntityField.php \Drupal\views\Plugin\views\field\EntityField::multiple_options_form()
  2. 8.9.x core/modules/views/src/Plugin/views/field/EntityField.php \Drupal\views\Plugin\views\field\EntityField::multiple_options_form()
  3. 11.x core/modules/views/src/Plugin/views/field/EntityField.php \Drupal\views\Plugin\views\field\EntityField::multiple_options_form()

Provide options for multiple value fields.

1 call to EntityField::multiple_options_form()
EntityField::buildOptionsForm in core/modules/views/src/Plugin/views/field/EntityField.php
Default option form that provides label widget that all fields should have.

File

core/modules/views/src/Plugin/views/field/EntityField.php, line 562

Class

EntityField
A field that displays entity field data.

Namespace

Drupal\views\Plugin\views\field

Code

public function multiple_options_form(&$form, FormStateInterface $form_state) {
    $field = $this->getFieldDefinition();
    $form['multiple_field_settings'] = [
        '#type' => 'details',
        '#title' => $this->t('Multiple field settings'),
        '#weight' => 5,
    ];
    $form['group_rows'] = [
        '#title' => $this->t('Display all values in the same row'),
        '#type' => 'checkbox',
        '#default_value' => $this->options['group_rows'],
        '#description' => $this->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, 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.
    [
        $prefix,
        $suffix,
    ] = explode('@count', $this->t('Display @count value(s)'));
    if ($field->getCardinality() == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
        $type = 'textfield';
        $options = NULL;
        $size = 5;
    }
    else {
        $type = 'select';
        $range = range(1, $field->getCardinality());
        $options = array_combine($range, $range);
        $size = 1;
    }
    $form['multi_type'] = [
        '#type' => 'radios',
        '#title' => $this->t('Display type'),
        '#options' => [
            'ul' => $this->t('Unordered list'),
            'ol' => $this->t('Ordered list'),
            'separator' => $this->t('Simple separator'),
        ],
        '#states' => [
            'visible' => [
                ':input[name="options[group_rows]"]' => [
                    'checked' => TRUE,
                ],
            ],
        ],
        '#default_value' => $this->options['multi_type'],
        '#fieldset' => 'multiple_field_settings',
    ];
    $form['separator'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Separator'),
        '#default_value' => $this->options['separator'],
        '#states' => [
            'visible' => [
                ':input[name="options[group_rows]"]' => [
                    'checked' => TRUE,
                ],
                ':input[name="options[multi_type]"]' => [
                    'value' => 'separator',
                ],
            ],
        ],
        '#fieldset' => 'multiple_field_settings',
    ];
    $form['delta_limit'] = [
        '#type' => $type,
        '#size' => $size,
        '#field_prefix' => $prefix,
        '#field_suffix' => $suffix,
        '#options' => $options,
        '#default_value' => $this->options['delta_limit'],
        '#prefix' => '<div class="container-inline">',
        '#states' => [
            'visible' => [
                ':input[name="options[group_rows]"]' => [
                    'checked' => TRUE,
                ],
            ],
        ],
        '#fieldset' => 'multiple_field_settings',
    ];
    [
        $prefix,
        $suffix,
    ] = explode('@count', $this->t('starting from @count'));
    $form['delta_offset'] = [
        '#type' => 'textfield',
        '#size' => 5,
        '#field_prefix' => $prefix,
        '#field_suffix' => $suffix,
        '#default_value' => $this->options['delta_offset'],
        '#states' => [
            'visible' => [
                ':input[name="options[group_rows]"]' => [
                    'checked' => TRUE,
                ],
            ],
        ],
        '#description' => $this->t('(first item is 0)'),
        '#fieldset' => 'multiple_field_settings',
    ];
    $form['delta_reversed'] = [
        '#title' => $this->t('Reversed'),
        '#type' => 'checkbox',
        '#default_value' => $this->options['delta_reversed'],
        '#suffix' => $suffix,
        '#states' => [
            'visible' => [
                ':input[name="options[group_rows]"]' => [
                    'checked' => TRUE,
                ],
            ],
        ],
        '#description' => $this->t('(start from last values)'),
        '#fieldset' => 'multiple_field_settings',
    ];
    $form['delta_first_last'] = [
        '#title' => $this->t('First and last only'),
        '#type' => 'checkbox',
        '#default_value' => $this->options['delta_first_last'],
        '#suffix' => '</div>',
        '#states' => [
            'visible' => [
                ':input[name="options[group_rows]"]' => [
                    'checked' => TRUE,
                ],
            ],
        ],
        '#fieldset' => 'multiple_field_settings',
    ];
}

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