You are here

protected function WebformEntityElementsForm::removeWebformTypePrefixRecursive in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/WebformEntityElementsForm.php \Drupal\webform\WebformEntityElementsForm::removeWebformTypePrefixRecursive()

Remove 'webform_' prefix from #type.

Parameters

array $element: A form element.

1 call to WebformEntityElementsForm::removeWebformTypePrefixRecursive()
WebformEntityElementsForm::getElementsWithoutWebformTypePrefix in src/WebformEntityElementsForm.php
Get elements without 'webform_' #type prefix.

File

src/WebformEntityElementsForm.php, line 189

Class

WebformEntityElementsForm
Webform manage elements YAML source form.

Namespace

Drupal\webform

Code

protected function removeWebformTypePrefixRecursive(array &$element) {
  if (isset($element['#type']) && strpos($element['#type'], 'webform_') === 0 && $this->elementManager
    ->hasDefinition($element['#type'])) {
    $type = str_replace('webform_', '', $element['#type']);
    if (!$this->elementInfo
      ->hasDefinition($type) && !$this->elementManager
      ->hasDefinition($type)) {
      $element['#type'] = $type;
    }
  }
  foreach (Element::children($element) as $key) {
    if (is_array($element[$key])) {
      $this
        ->removeWebformTypePrefixRecursive($element[$key]);
    }
  }
}