public function __construct(ICms $cms, Language $language, FormBase $form = null, FormRenderer $form_renderer = null, FieldFactory $field_factory = null) { $this->cms = $cms; $this->language = $language; $this->field_factory = $field_factory; if ($form) { $this->form = $form; $this->form->setRenderer($form_renderer); if ($this->field_factory) { $this->form->filter_fields = $this->field_factory->createFieldSet($this->form, '', 'filters'); $this->form->filter_fields->fieldset_tag = 'div'; } } $this->initialise(); }
protected function mapEntityValueToField($field_name, $entity_value) { $field = $this->form->getField($field_name); if ($field !== null) { switch ($field->type) { case 'label': $field->setValueRaw($entity_value); break; case 'date': if ($entity_value instanceof \DateTime) { $field->setValue($entity_value->format('Y-m-d')); } else { $field->setValue($entity_value); } break; case 'datetime-local': if ($entity_value instanceof \DateTime) { $field->setValue($entity_value->format('Y-m-d\\TH:i')); } else { $field->setValue($entity_value); } break; default: $field->setValue($entity_value); break; } } }
/** * Maps data from the form to the entity where the field name matches the name of an entity's property. * Optionally specify a prefix if the form fields have one. * @param FormBase $form Form containing the values to map * @param DomainObjectBase $entity Entity to map the values to * @param string $name_prefix Field name prefix that may be applied to form field names * @param boolean $strict Where a name prefix is supplied, set this to true if you ONLY want to map fields that have a matching prefix (otherwise it will map fields that have the prefix or no prefix) * @return DomainObjectBase */ protected function mapScalarFormElements(FormBase $form, DomainObjectBase $entity, $name_prefix = '', $strict = false) { $properties = $entity->getProperties(true); foreach ($properties as $property) { if ($form->fieldExists($name_prefix . $property)) { $entity->{$property} = $form->getField($name_prefix . $property)->value; } else { if (strlen($name_prefix) > 0 && !$strict) { if ($form->fieldExists($property)) { $entity->{$property} = $form->getField($property)->value; } } } } return $entity; }
public function renderMandatoryKey() { foreach ($this->form->field_sets as $field_set) { foreach ($field_set->fields as $field) { if ($field->required) { ?> <div class="<?php echo $this->form->css_class; ?> -mandatory-key"> <?php echo $this->form->getString('mandatory', 'form'); ?> </div> <?php break 2; } } } }