You are here

public static function FieldsProcessorPluginBase::preRenderFieldsCheckboxes in Search API 8

Preprocesses the "fields" checkboxes before rendering.

Adds "#states" settings to disable the checkboxes when "all_fields" is checked.

Parameters

array $element: The form element to process.

Return value

array The processed form element.

File

src/Processor/FieldsProcessorPluginBase.php, line 252

Class

FieldsProcessorPluginBase
Provides a base class for processors that work on individual fields.

Namespace

Drupal\search_api\Processor

Code

public static function preRenderFieldsCheckboxes(array $element) {
  $parents = $element['#parents'];
  array_pop($parents);
  $parents[] = 'all_fields';
  $name = array_shift($parents);
  if ($parents) {
    $name .= '[' . implode('][', $parents) . ']';
  }
  $selector = ":input[name=\"{$name}\"]";
  $element['#states'] = [
    'invisible' => [
      $selector => [
        'checked' => TRUE,
      ],
    ],
  ];
  return $element;
}