You are here

protected function YamlFormUiEntityForm::getOrderableElements in YAML Form 8

Get form's elements as an associative array of orderable elements.

Return value

array An associative array of orderable elements.

1 call to YamlFormUiEntityForm::getOrderableElements()
YamlFormUiEntityForm::editForm in modules/yamlform_ui/src/YamlFormUiEntityForm.php
Edit form element's source code form.

File

modules/yamlform_ui/src/YamlFormUiEntityForm.php, line 393

Class

YamlFormUiEntityForm
Base for controller for form UI.

Namespace

Drupal\yamlform_ui

Code

protected function getOrderableElements() {

  /** @var \Drupal\yamlform\YamlFormInterface $yamlform */
  $yamlform = $this
    ->getEntity();
  $elements = $yamlform
    ->getElementsInitializedAndFlattened();
  $weights = [];
  foreach ($elements as &$element) {
    $parent_key = $element['#yamlform_parent_key'];
    if (!isset($weights[$parent_key])) {
      $element['#weight'] = $weights[$parent_key] = 0;
    }
    else {
      $element['#weight'] = ++$weights[$parent_key];
    }
    if (empty($element['#type'])) {
      if (isset($element['#theme'])) {
        $element['#type'] = $element['#theme'];
      }
      elseif (isset($element['#markup'])) {
        $element['#type'] = 'markup';
      }
      else {
        $element['#type'] = '';
      }
    }
    if (empty($element['#title'])) {
      if (!empty($element['#markup'])) {
        $element['#title'] = Unicode::truncate(strip_tags($element['#markup']), 100, TRUE, TRUE);
      }
      else {
        $element['#title'] = '[' . t('blank') . ']';
      }
    }
  }
  return $elements;
}