You are here

protected function WebformEntityHandler::getElements in Webform Entity Handler 8

Same name and namespace in other branches
  1. 2.x src/Plugin/WebformHandler/WebformEntityHandler.php \Drupal\webform_entity_handler\Plugin\WebformHandler\WebformEntityHandler::getElements()

Prepare #options array of webform elements.

Return value

array Prepared array of webform elements.

2 calls to WebformEntityHandler::getElements()
WebformEntityHandler::buildConfigurationForm in src/Plugin/WebformHandler/WebformEntityHandler.php
Form constructor.
WebformEntityHandler::getEntityFieldsForm in src/Plugin/WebformHandler/WebformEntityHandler.php
Compose the form with the entity type fields.

File

src/Plugin/WebformHandler/WebformEntityHandler.php, line 449

Class

WebformEntityHandler
Create or update an entity with a webform submission values.

Namespace

Drupal\webform_entity_handler\Plugin\WebformHandler

Code

protected function getElements() {
  $elements_options =& drupal_static(__FUNCTION__);
  if (is_null($elements_options)) {
    $elements_options = [];
    foreach ($this
      ->getWebform()
      ->getElementsInitializedAndFlattened() as $element) {
      try {
        $element_plugin = $this->webformElementManager
          ->getElementInstance($element);
        if (!$element_plugin instanceof WebformCompositeBase) {
          $t_args = [
            '@title' => $element['#title'],
            '@type' => $element_plugin
              ->getPluginLabel(),
          ];
          $elements_options['input:' . $element['#webform_key']] = $this
            ->t('@title [@type]', $t_args);
        }
        else {
          $element_group = $element_plugin
            ->getElementSelectorOptions($element);
          foreach ($element_group as $group_key => $group) {
            foreach ($group as $sub_element_key => $sub_element) {
              if (preg_match('/^:input\\[name=\\"(.*?)\\"]$/', $sub_element_key, $match) == TRUE) {
                $sub_element_key = array_map(function ($item) {
                  return rtrim($item, ']');
                }, explode('[', $match[1]));

                // Manged file add a non-existent first key.
                if ($element['#webform_composite_elements'][end($sub_element_key)]['#type'] == 'managed_file') {
                  array_shift($sub_element_key);
                }
                $elements_options[$group_key]['input:' . implode('|', $sub_element_key)] = $sub_element;
              }
            }
          }
        }
      } catch (\Exception $exception) {

        // Nothing to do.
      }
    }
  }
  return $elements_options;
}