Example #1
0
 function __construct()
 {
     $this->templates = new \Doctrine\Common\Collections\ArrayCollection();
     $this->views = new \Doctrine\Common\Collections\ArrayCollection();
     $this->dirty = true;
     $this->editTwigWithWysiwyg = true;
     $fieldType = new FieldType();
     $fieldType->setName('source');
     //      	$fieldType->setDeleted ( false );
     //      	$fieldType->setOrderKey( false );
     $fieldType->setType(ContainerFieldType::class);
     $fieldType->setContentType($this);
     $this->setFieldType($fieldType);
     $this->setAskForOuuid(true);
 }
 /**
  * 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;
 }