You are here

public static function WebformExcludedColumns::getWebformExcludedOptions in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Element/WebformExcludedColumns.php \Drupal\webform\Element\WebformExcludedColumns::getWebformExcludedOptions()

Get options for excluded tableselect element.

Parameters

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

Return value

array An array of options containing title, name, and type of items for a tableselect element.

Overrides WebformExcludedBase::getWebformExcludedOptions

File

src/Element/WebformExcludedColumns.php, line 28

Class

WebformExcludedColumns
Provides a webform element for webform excluded columns (submission field and elements).

Namespace

Drupal\webform\Element

Code

public static function getWebformExcludedOptions(array $element) {

  /** @var \Drupal\webform\WebformInterface $webform */
  $webform = WebformEntity::load($element['#webform_id']) ?: \Drupal::service('webform.request')
    ->getCurrentWebform();
  if (!$webform) {
    return [];
  }
  $options = [];

  /** @var \Drupal\webform\WebformSubmissionStorageInterface $submission_storage */
  $submission_storage = \Drupal::entityTypeManager()
    ->getStorage('webform_submission');
  $field_definitions = $submission_storage
    ->getFieldDefinitions();
  $field_definitions = $submission_storage
    ->checkFieldDefinitionAccess($webform, $field_definitions);
  foreach ($field_definitions as $key => $field_definition) {
    $options[$key] = [
      'title' => $field_definition['title'],
      'name' => $key,
      'type' => $field_definition['type'],
    ];
  }
  $elements = $webform
    ->getElementsInitializedFlattenedAndHasValue('view');

  // Replace tokens which can be used in an element's #title.

  /** @var \Drupal\webform\WebformTokenManagerInterface $token_manager */
  $token_manager = \Drupal::service('webform.token_manager');
  $elements = $token_manager
    ->replace($elements, $webform);
  foreach ($elements as $key => $element) {
    $options[$key] = [
      'title' => $element['#admin_title'] ?: $element['#title'] ?: $key,
      'name' => $key,
      'type' => isset($element['#type']) ? $element['#type'] : '',
    ];
  }
  return $options;
}