Manager/FormManager.php
protected function updateFields($data, $form, $locale)
    {
        $reservedKeys = array_column(self::getValue($data, 'fields', []), 'key');

        $counter = 0;

        foreach (self::getValue($data, 'fields', []) as $fieldData) {
            ++$counter;
            $fieldType = self::getValue($fieldData, 'type');
            $fieldKey = self::getValue($fieldData, 'key');
            $field = $form->getField($fieldKey);
            $uniqueKey = $this->getUniqueKey($fieldType, $reservedKeys);

            if (!$field) {
                $field = $form->getField($uniqueKey);
            }

            if (!$field) {
                $field = new FormField();
                $field->setKey($uniqueKey);
                $reservedKeys[] = $uniqueKey;
            } elseif ($field->getType() !== $fieldType || !$field->getKey()) {
                $field->setKey($uniqueKey);
                $reservedKeys[] = $uniqueKey;
            }

            $field->setOrder($counter);
            $field->setType($fieldType);
            $field->setWidth(self::getValue($fieldData, 'width', 'full'));
            $field->setRequired(self::getValue($fieldData, 'required', false));

            // Field Translation
            $fieldTranslation = $field->getTranslation($locale, true);
            $fieldTranslation->setTitle(self::getValue($fieldData, 'title'));
            $fieldTranslation->setPlaceholder(self::getValue($fieldData, 'placeholder'));
            $fieldTranslation->setDefaultValue(self::getValue($fieldData, 'defaultValue'));
            $fieldTranslation->setShortTitle(self::getValue($fieldData, 'shortTitle'));

            // Field Options
            $prefix = 'options[';

            $keys = array_filter(array_keys($fieldData), function ($key) use ($prefix) {
                return 0 === strpos($key, $prefix);
            });

            $options = array_intersect_key($fieldData, array_flip($keys));

            foreach ($options as $key => $value) {
                unset($options[$key]);
                $options[trim(substr($key, strlen($prefix)), ']')] = $value;
            }

            $fieldTranslation->setOptions($options);

            // Add Translation to Field
            if (!$fieldTranslation->getId()) {
                $fieldTranslation->setField($field);
                $field->addTranslation($fieldTranslation);
            }

            // Add Field to Form
            if (!$field->getId()) {
                $field->setDefaultLocale($locale);
                $field->setForm($form);
                $form->addField($field);
            }
        }

        // Remove Fields
        foreach ($form->getFieldsNotInArray($reservedKeys) as $deletedField) {
            $form->removeField($deletedField);
            $this->entityManager->remove($deletedField);
        }
    }
protected function updateFields($data, $form, $locale)
    {
        $reservedKeys = array_column(self::getValue($data, 'fields', []), 'key');

        $counter = 0;

        foreach (self::getValue($data, 'fields', []) as $fieldData) {
            ++$counter;
            $fieldType = self::getValue($fieldData, 'type');
            $fieldKey = self::getValue($fieldData, 'key');
            $field = $form->getField($fieldKey);
            $uniqueKey = $this->getUniqueKey($fieldType, $reservedKeys);

            if (!$field) {
                $field = $form->getField($uniqueKey);
            }

            if (!$field) {
                $field = new FormField();
                $field->setKey($uniqueKey);
                $reservedKeys[] = $uniqueKey;
            } elseif ($field->getType() !== $fieldType || !$field->getKey()) {
                $field->setKey($uniqueKey);
                $reservedKeys[] = $uniqueKey;
            }

            $field->setOrder($counter);
            $field->setType($fieldType);
            $field->setWidth(self::getValue($fieldData, 'width', 'full'));
            $field->setRequired(self::getValue($fieldData, 'required', false));

            // Field Translation
            $fieldTranslation = $field->getTranslation($locale, true);
            $fieldTranslation->setTitle(self::getValue($fieldData, 'title'));
            $fieldTranslation->setPlaceholder(self::getValue($fieldData, 'placeholder'));
            $fieldTranslation->setDefaultValue(self::getValue($fieldData, 'defaultValue'));
            $fieldTranslation->setShortTitle(self::getValue($fieldData, 'shortTitle'));

            // Field Options
            $prefix = 'options[';

            $keys = array_filter(array_keys($fieldData), function ($key) use ($prefix) {
                return 0 === strpos($key, $prefix);
            });

            $options = array_intersect_key($fieldData, array_flip($keys));

            foreach ($options as $key => $value) {
                unset($options[$key]);
                $options[trim(substr($key, strlen($prefix)), ']')] = $value;
            }

            $fieldTranslation->setOptions($options);

            // Add Translation to Field
            if (!$fieldTranslation->getId()) {
                $fieldTranslation->setField($field);
                $field->addTranslation($fieldTranslation);
            }

            // Add Field to Form
            if (!$field->getId()) {
                $field->setDefaultLocale($locale);
                $field->setForm($form);
                $form->addField($field);
            }
        }

        // Remove Fields
        foreach ($form->getFieldsNotInArray($reservedKeys) as $deletedField) {
            $form->removeField($deletedField);
            $this->entityManager->remove($deletedField);
        }
    }
Updates the contained fields in the form.

@param array $data
@param Form $form
@param string $locale