function ArgumentPluginBase::processContainerRadios

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

Custom form radios process function.

Roll out a single radios element to a list of radios, using the options array as index. While doing that, create a container element underneath each option, which contains the settings related to that option.

See also

\Drupal\Core\Render\Element\Radios::processRadios()

File

core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php, line 1206

Class

ArgumentPluginBase
Base class for argument (contextual filter) handler plugins.

Namespace

Drupal\views\Plugin\views\argument

Code

public static function processContainerRadios($element) {
    if (count($element['#options']) > 0) {
        foreach ($element['#options'] as $key => $choice) {
            $element += [
                $key => [],
            ];
            // Generate the parents as the autogenerator does, so we will have a
            // unique id for each radio button.
            $parents_for_id = array_merge($element['#parents'], [
                $key,
            ]);
            $element[$key] += [
                '#type' => 'radio',
                '#title' => $choice,
                // The key is sanitized in drupal_attributes() during output from the
                // theme function.
'#return_value' => $key,
                '#default_value' => $element['#default_value'] ?? NULL,
                '#attributes' => $element['#attributes'],
                '#parents' => $element['#parents'],
                '#id' => Html::getUniqueId('edit-' . implode('-', $parents_for_id)),
                '#ajax' => $element['#ajax'] ?? NULL,
            ];
            $element[$key . '_options'] = [
                '#type' => 'container',
                '#attributes' => [
                    'class' => [
                        'views-admin-dependent',
                    ],
                ],
            ];
        }
    }
    return $element;
}

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