You are here

public static function WebformTableTrait::processTableSelectOptions in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformElement/WebformTableTrait.php \Drupal\webform\Plugin\WebformElement\WebformTableTrait::processTableSelectOptions()

Process table selected options.

Parameters

array $element: An associative array containing the properties and children of the tableselect element.

Return value

array The processed element.

See also

\Drupal\Core\Render\Element\Tableselect::processTableselect

File

src/Plugin/WebformElement/WebformTableTrait.php, line 162

Class

WebformTableTrait
Provides a 'table' trait.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public static function processTableSelectOptions(array $element) {
  foreach ($element['#options'] as $key => $choice) {
    if (!isset($element[$key])) {
      continue;
    }

    // Add #title to the table's options.
    if (empty($element[$key]['#title'])) {
      if ($title = static::getTableSelectOptionTitle($choice)) {
        $element[$key]['#title'] = $title;
        $element[$key]['#title_display'] = 'invisible';
      }
    }

    // Suppress inline error messages from appearing below
    // checkboxes and radios.
    $element[$key]['#error_no_message'] = TRUE;

    // Add required attribute to table select radios
    if (!empty($element['#required']) && empty($element['#multiple'])) {
      $element[$key]['#attributes']['required'] = TRUE;
    }
  }
  return $element;
}