private function createFieldType($contentType, $parent, $type, $name, $label, $deleted, $orderKey, $many, $editOptions) { $fieldType = new FieldType(); if ($parent != '') { $fieldType->setParent($this->getReference($parent)); } else { $fieldType->setContentType($this->getReference($contentType)); $this->getReference($contentType)->setFieldType($fieldType); } $fieldType->setType('AppBundle\\Form\\DataField\\' . $type . 'Type'); $fieldType->setName($name); $fieldType->setLabel($label); $fieldType->setDeleted($deleted); $fieldType->setOrderKey($orderKey); $fieldType->setMany($many); $fieldType->setEditOptions($editOptions); return $fieldType; }
/** * Try to find (recursively) if there is a new field to add to the content type * * @param array $formArray * @param FieldType $fieldType */ private function addNewSubfield(array $formArray, FieldType $fieldType) { if (array_key_exists('subfield', $formArray)) { if (isset($formArray['ems:internal:add:subfield:name']) && strcmp($formArray['ems:internal:add:subfield:name'], '') !== 0) { if ($this->isValidName($formArray['ems:internal:add:subfield:name'])) { $child = new FieldType(); $child->setName($formArray['ems:internal:add:subfield:name']); $child->setType(SubfieldType::class); $child->setParent($fieldType); $fieldType->addChild($child); $this->addFlash('notice', 'The subfield ' . $child->getName() . ' has been prepared to be added'); return '_ems_' . $child->getName() . '_modal_options'; } else { $this->addFlash('error', 'The subfield\'s name is not valid (format: [a-z][a-z0-9_-]*)'); } } else { $this->addFlash('notice', 'The subfield name is mandatory'); } return true; } else { /** @var FieldType $child */ foreach ($fieldType->getChildren() as $child) { if (!$child->getDeleted()) { $out = $this->addNewSubfield($formArray['ems_' . $child->getName()], $child); if ($out !== false) { return '_ems_' . $child->getName() . $out; } } } } return false; }