Create the JsFormElement for all the children of specified element

@param null|Form $form

@return array
485158
protected function processChildren($form)
    {
        $result = array();
        // If this field has children - process them
        foreach ($form as $name => $child) {
            if ($this->isProcessableElement($child)) {
                $childModel = $this->createJsModel($child);
                if (null !== $childModel) {
                    $result[$name] = $childModel;
                }
            }
        }

        return $result;
    }
1122923
public function renderForm(Form $form)
	{
		$content = '';
		foreach ($form as $element)
		{
			$content .= $this->render($element);
		}

		$form->setAttribute('role', 'form');

		return Html::tag('form', $form->getAttributes(), $content);
	}
397427
private function getFormInterface(FormInterface $form, $id): FormInterface
    {
        $name = $form->getName();
        if ($id === $name)
            return $form;
        if (mb_strpos($id, $name.'_') === 0) {
            $id = mb_substr($id, mb_strlen($name . '_'));
            foreach ($form->all() as $name => $child) {
                if ($id === $name)
                    return $child;
                if (mb_strpos($id, $name.'_') === 0)
                    return $this->getFormInterface($child, $id);
            }
        }
        return $form;
    }
893322
public function createForm()
    {
        $this->collapse->childNodes->push(new Navbar\Form());

        return $this->form = $this->collapse->childNodes->last();
    }
958727
protected function getElementId(Form $form)
    {
        /** @var Form $parent */
        $parent = $form->getParent();
        if (null !== $parent) {
            return $this->getElementId($parent) . '_' . $form->getName();
        } else {
            return $form->getName();
        }
    }
976204
public static function el(array &$form, FormStateInterface $form_state) {
    $trigger = $form_state->getTriggeringElement();
    return NestedArray::getValue($form, array_slice($trigger['#array_parents'], 0, -1));
  }
1349379
protected function getValidationData(Form $form)
    {
        // If parent has metadata
        $parent = $form->getParent();
        if ($parent && null !== $parent->getConfig()->getDataClass()) {
            $classMetadata = $metadata = $this->getMetadataFor($parent->getConfig()->getDataClass());
            if ($classMetadata->hasPropertyMetadata($form->getName())) {
                $metadata = $classMetadata->getPropertyMetadata($form->getName());
                /** @var PropertyMetadata $item */
                foreach ($metadata as $item) {
                    $this->composeValidationData(
                        $parentData,
                        $item->getConstraints(),
                        $getters = !empty($item->getters) ? (array)$item->getters : array()
                    );
                }
            }
        }
        // If has own metadata
        if (null !== $form->getConfig()->getDataClass()) {
            $metadata = $this->getMetadataFor($form->getConfig()->getDataClass());
            $this->composeValidationData(
                $ownData,
                $metadata->getConstraints(),
                $getters = !empty($metadata->getters) ? (array)$metadata->getters : array()
            );
        }
        // If has constraints in a form element
        $this->composeValidationData(
            $formData,
            (array)$form->getConfig()->getOption('constraints'),
            array()
        );

        $result = array();
        $groups = $this->getValidationGroups($form);

        if (!empty($parentData)) {
            $parentData['groups'] = $this->getValidationGroups($parent);
            $result['parent']     = $parentData;
        }
        if (!empty($ownData)) {
            $ownData['groups'] = $groups;
            $result['entity']  = $ownData;
        }
        if (!empty($formData)) {
            $formData['groups'] = $groups;
            $result['form']     = $formData;
        }

        return $result;
    }
1022078
public static function configurableAjaxCallback(array $form, FormStateInterface $form_state) {
    $dynamic_parts = &$form['ajax'];

    $configurables = $form_state->getValue('configurables');

    /** @var \Drupal\acm_sku\CartFormHelper $helper */
    $helper = \Drupal::service('acm_sku.cart_form_helper');

    $tree = $form_state->get('tree');
    $tree_pointer = &$tree['options'];

    foreach ($configurables as $key => $value) {
      if (empty($value)) {
        continue;
      }

      // Move the tree pointer if the selection is valid.
      if (isset($tree_pointer["$key:$value"])) {
        $tree_pointer = &$tree_pointer["$key:$value"];
      }
    }

    if ($tree_pointer instanceof SKU) {
      $view_builder = \Drupal::entityTypeManager()->getViewBuilder('acm_sku');

      $view = $view_builder->view($tree_pointer);

      // Block add to cart render because Form API won't allow AJAX Formception.
      $view['#no_add_to_cart'] = TRUE;

      $dynamic_parts['add_to_cart'] = [
        'entity_render' => ['#markup' => render($view)],
      ];
    }
    else {
      $available_config = $tree_pointer['#available_config'];

      foreach ($available_config as $key => $config) {
        $options = [
          '' => $dynamic_parts['configurables']['color']['#options'][''],
        ];

        foreach ($config['values'] as $value) {
          $options[$value['value_id']] = $value['label'];
        }

        // Sort config options before pushing them to the select list based on
        // the config.
        if ($helper->isAttributeSortable($key)) {
          // Make sure the first element in the list is the empty option.
          $sorted_options = [
            '' => $dynamic_parts['configurables'][$key]['#options'][''],
          ];
          $sorted_options += self::sortConfigOptions($options, $key);
        }
        else {
          // Use this in case the attribute is not sortable as per the config.
          $sorted_options = $options;
        }

        $dynamic_parts['configurables'][$key]['#options'] = $sorted_options;
      }
    }

    return $dynamic_parts;
  }
895105
protected function buildCheckboxes($form, $prefix)
    {
        $return = array();
        foreach ($form as $element) {
            /* @var $element \Zend\Form\ElementInterface|DisableElementsCapableInterface|DisableCapableInterface */
            $name = $element->getName();
            $elementName = $prefix . '[' . $element->getName() . ']';
            $options = $element->getOption('disable_capable');
            $boxOptions = array(
                'long_label'  => isset($options['label']) ? $options['label'] : ($element->getLabel() ? : $name),
                'description' => isset($options['description']) ? $options['description']
                        : 'Toggle availability of this element in the form.',
            );

            if ($element instanceof DisableElementsCapableInterface) {
                if ($element->isDisableElementsCapable()) {
                    $return[$name] = $this->buildCheckboxes($element, $elementName);
                }
                if ($element->isDisableCapable()) {
                    $box = $this->createCheckbox($elementName . '[__all__]', $boxOptions);
                    $box->setAttribute('checked', true);
                    $return[$name]['__all__'] = $box;
                }
                continue;
            }
            if (($element instanceof DisableCapableInterface && $element->isDisableCapable())
                || false !== $element->getOption('is_disable_capable')
            ) {
                $box = $this->createCheckbox($elementName, $boxOptions);
                $box->setAttribute('checked', true);
                $return[$name] = $box;
            }
        }

        return $return;
    }
432120
protected function getAllErrors(FormInterface $form)
    {
        $errors = $form->getErrors();
        $children = $form->all();
        if (!count($errors) && !count($children)) {
            return null;
        }

        $section = [
            'field' => $form->getName()
        ];

        if (count($errors)) {
            $section['errors'] = array_map(
                function (FormError $error) {
                    return [
                        'message' => $error->getMessage(),
                        'parameters' => $error->getMessageParameters()
                    ];
                },
                iterator_to_array($form->getErrors())
            );
        }

        if (count($children)) {
            $section['children'] = array_values(
                array_filter(
                    array_map(
                        function (FormInterface $field) {
                            return $this->getAllErrors($field);
                        },
                        $form->all()
                    )
                )
            );

            if (!count($errors) && !count($section['children'])) {
                return null;
            }
        }

        return $section;
    }
1002231
public static function fromJson($config, Form_Elements_FieldsetModel $form=null)
	{
		$contextProfile = AgaviConfig::get('core.default_context');
		if(is_null($contextProfile))
		{
			$contextProfile = md5(microtime());
			AgaviConfig::set('core.default_context', $contextProfile);
		}
		$context = AgaviContext::getInstance();
		$_form = $context->getModel('Form', 'Form', array($config, $form));
		self::parseChildren($config, $_form);
		return $_form;
	}
722629
protected function prepare_fields( Form $form ) {
		foreach ( $form->all() as $field ) {
			/* @var $field \WPLibs\Form\Field */
			if ( ! $field->should_show() ) {
				return;
			}

			$_section = $field->get_option( 'section' );

			if ( ! $_section || ! isset( $this->sections[ $_section ] ) ) {
				continue;
			}

			$this->sections[ $_section ]->fields[] = $field;
		}
	}
231623
public function setForm($form)
    {
        foreach ($this->namedLinkCompositeField->compositeDatabaseFields() as $field => $spec) {
            $fieldHandle = 'field' . $field;
            $this->{$fieldHandle}->setForm($form);
        }
//		$this->fieldPageID->setForm($form);
//		$this->fieldPageAnchor->setForm($form);
//		$this->fieldFileID->setForm($form);
//		$this->fieldCustomURL->setForm($form);
//		$this->fieldShortcode->setForm($form);
//		$this->fieldTitle->setForm($form);
//		$this->fieldLinkmode->setForm($form);

		parent::setForm($form);

        return $this;
	}
1049877
protected function getConditionBuilder(Form $form)
    {
        $builderClosure = $form->getConfig()->getAttribute('filter_condition_builder');

        $builder = new ConditionBuilder();

        if ($builderClosure instanceof \Closure) {
            $builderClosure($builder);
        } else {
            $this->buildDefaultConditionNode($form, $builder->root('AND'));
        }

        return $builder;
    }
887116
public function tabBuilder(\samsoncms\app\material\form\Form & $form)
    {
        // If we have related structures
        if (count($form->navigationIDs)) {
            // Get all gallery additional field for material form structures
            $galleryFields = $this->query->entity(\samsoncms\api\Field::class)
                ->where('Type', 9)
                ->join('structurefield')
                ->where('structurefield_StructureID', $form->navigationIDs)
                ->exec();

            // Create tab for each additional gallery field
            foreach ($galleryFields as $field) {
                $form->tabs[] = new Gallery($this, $this->query, $form->entity, $field);
            }
        }
    }
566080
public function buildForm(array $form, FormStateInterface $form_state) {
    $form['#attributes']['class'][] = 'form--default';
    $form['group_settings'] = [
      '#type' => 'fieldset',
      '#title' => $this->t('Settings'),
    ];
    $form['group_settings']['group_type'] = $this->getGroupTypeElement();
    $form['actions']['submit'] = [
      '#prefix' => '<div class="form-actions">',
      '#suffix' => '</div>',
      '#type' => 'submit',
      '#value' => $this->t('Continue'),
      '#button_type' => 'primary',
    ];

    $form['#cache']['contexts'][] = 'user';

    return $form;
  }
1103893
private function addFormElements(array &$form, array $values) {
    $form['filter_controls'] = [
      '#markup' => '
          <div class="container controls-wrapper hidden-sm hidden-md hidden-lg">
          <a href="#" class="btn btn-link transparent-blue add-filters">' . $this->t('Add filters') . '</a>
          <a href="#" class="btn btn-link transparent-blue close-filters hidden">' . $this->t('Close filters') . '</a>
          </div>',
    ];

    $form['selects'] = [
      '#type' => 'container',
      '#attributes' => [
        'class' => [
          'container',
          'selects-container',
          'hidden-xs',
        ],
      ],
    ];

    $form['selects']['location'] = [
      '#type' => 'select',
      '#title' => $this->t('Location'),
      '#options' => $this->getLocationOptions(),
      '#prefix' => '<hr/>',
      '#default_value' => isset($values['location']) ? $values['location'] : 'All',
      '#ajax' => [
        'callback' => [$this, 'rebuildAjaxCallback'],
        'wrapper' => 'schedules-search-form-wrapper',
        'event' => 'change',
        'method' => 'replace',
        'effect' => 'fade',
        'progress' => [
          'type' => 'throbber',
        ],
      ],
    ];

    $form['selects']['program'] = [
      '#type' => 'select',
      '#title' => $this->t('Program'),
      '#options' => $this->getProgramOptions(),
      '#default_value' => isset($values['program']) ? $values['program'] : 'all',
      '#ajax' => [
        'callback' => [$this, 'rebuildAjaxCallback'],
        'wrapper' => 'schedules-search-form-wrapper',
        'event' => 'change',
        'method' => 'replace',
        'effect' => 'fade',
        'progress' => [
          'type' => 'throbber',
        ],
      ],
    ];

    $form['selects']['category'] = [
      '#type' => 'select',
      '#title' => $this->t('Sub-Program'),
      '#options' => $this->getCategoryOptions(),
      '#default_value' => isset($values['category']) ? $values['category'] : 'all',
      '#ajax' => [
        'callback' => [$this, 'rebuildAjaxCallback'],
        'wrapper' => 'schedules-search-form-wrapper',
        'event' => 'change',
        'method' => 'replace',
        'effect' => 'fade',
        'progress' => [
          'type' => 'throbber',
        ],
      ],
    ];

    $form['selects']['class'] = [
      '#type' => 'select',
      '#title' => $this->t('Class'),
      '#options' => $this->getClassOptions(),
      '#default_value' => isset($values['class']) ? $values['class'] : 'all',
      '#ajax' => [
        'callback' => [$this, 'rebuildAjaxCallback'],
        'wrapper' => 'schedules-search-form-wrapper',
        'event' => 'change',
        'method' => 'replace',
        'effect' => 'fade',
        'progress' => [
          'type' => 'throbber',
        ],
      ],
    ];

    $form['selects']['date'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Date'),
      '#default_value' => isset($values['date']) ? $values['date'] : '',
      '#attributes' => [
        'class' => ['openy-schedule-datepicker'],
      ],
      '#ajax' => [
        'callback' => [$this, 'rebuildAjaxCallback'],
        'wrapper' => 'schedules-search-form-wrapper',
        'event' => 'change',
        'method' => 'replace',
        'effect' => 'fade',
        'progress' => [
          'type' => 'throbber',
        ],
        // Do not focus current input element after ajax finish.
        'disable-refocus' => TRUE,
      ],
    ];

    $form['selects']['time'] = [
      '#type' => 'select',
      '#title' => $this->t('Start Time:'),
      '#options' => $this->getTimeOptions(),
      '#default_value' => isset($values['time']) ? $values['time'] : 'all',
      '#ajax' => [
        'callback' => [$this, 'rebuildAjaxCallback'],
        'wrapper' => 'schedules-search-form-wrapper',
        'event' => 'change',
        'method' => 'replace',
        'effect' => 'fade',
        'progress' => [
          'type' => 'throbber',
        ],
      ],
    ];

    $form['selects']['display'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Weekly View'),
      '#default_value' => isset($values['display']) ? $values['display'] : 0,
      '#title_display' => 'before',
      '#ajax' => [
        'callback' => [$this, 'rebuildAjaxCallback'],
        'wrapper' => 'schedules-search-form-wrapper',
        'event' => 'change',
        'method' => 'replace',
        'effect' => 'fade',
        'progress' => [
          'type' => 'throbber',
        ],
      ],
    ];

    // If on Weekly View, default and disable time field.
    if (isset($values['display']) && $values['display']) {
      $form['selects']['time']['#disabled'] = TRUE;
      $form['selects']['time']['#default_value'] = 'all';
    }

    $form['selects']['button'] = [
      '#type' => 'button',
      '#prefix' => '<div class="actions-wrapper hidden-xs hidden-sm hidden-md hidden-lg">',
      '#suffix' => '</div>',
      '#attributes' => [
        'class' => [
          'btn',
          'blue',
        ]
      ],
      '#value' => $this->t('Apply filters'),
      '#ajax' => [
        'callback' => [$this, 'rebuildAjaxCallback'],
        'method' => 'replace',
        'event' => 'click',
      ],
    ];

    $form['filters'] = [
      '#type' => 'container',
      '#prefix' => '<div class="filters-main-wrapper hidden-sm"><div class="container filters-container">',
      '#suffix' => '</div></div>',
      '#attributes' => [
        'class' => [
          'container',
          'filters-container',
        ],
      ],
      '#markup' => '',
      '#weight' => 99,
      'filters' => self::buildFilters($values),
    ];

    $form['alerts'] = [
      views_embed_view('header_alerts', 'specific_alerts_block', $values['location']),
    ];
    $form['alerts']['#prefix'] = '<div class="alerts-wrapper cleafix"><div class="container"><div class="row"><div class="col-xs-12">';
    $form['alerts']['#suffix'] = '</div></div></div></div>';
    $form['alerts']['#weight'] = 100;
  }