/** * Process the form and options array before random entities are created. The * main purpose here is for taxonomy term reference and entity reference * fields to create entities that can be attached to fields. * * @param array $options * Options array. */ protected static function processBeforeCreateRandom(&$options) { // We need to use "static" here and not "self" since "getFormClass" needs to // be called from individual Entity class to get the correct value. $formClass = static::getFormClassName(); // Instantiate the form class. $classForm = new $formClass(); // First get all field instances. $field_instances = $classForm->getEntityObject()->getFieldInstances(); // Iterate over all the field instances and if the field is to be filled, // then process it. foreach ($field_instances as $field_name => $field_instance) { if (Field::isToBeFilled($classForm, $field_name, $options)) { // Check if the field is a taxonomy term field or an entity reference field. list($field_class, $widget_type) = Field::getFieldClass($classForm, $field_name); $field_class::processBeforeCreateRandom($classForm, $field_name, $options); } } }
/** * Fill specified field with the provided values. * * @param string|array $field_name * Field name if it is present at top-level form element. If it is not at * the top-level form element, then provide an array. * @param string|int|array $values * Value that needs to be filled. * * @return Response * Response object. */ public function fillFieldValues($field_name, $values) { list($field_class, $widget_type) = Field::getFieldClass($this, $field_name); if ($field_class) { return $field_class::fillValues($this, $field_name, $values); } $response = $this->getTreeKeys($field_name); if (!$response->getSuccess()) { return $this->fillValues($field_name, $values); } return $this->fillValues($response->getVar(), $values); }
/** * Fills values in the specified field. Internally it calls the class of the * individual field type to fill the values. * * @param Form $formObject * Form object. * @param string $field_name * Field name. * @param string|array $values * Values to be filled. * * @return mixed * An array with 2 values: * (1) $success: Whether default values could be filled in the field. * (2) $msg: Message in case there is an error. This will be empty if * $success is TRUE. */ public static function fillValues(Form $formObject, $field_name, $values) { list($field_class, $widget_type) = Field::getFieldClass($formObject, $field_name); if (!empty($field_class)) { $function = 'fill' . $widget_type . 'Values'; return $field_class::$function($formObject, $field_name, $values); } // $field_name is a property. return $formObject->fillValues($field_name, $values); }
public function processAfterSubmit() { // First get all field instances. $field_instances = $this->getEntityObject()->getFieldInstances(); // Iterate over all the field instances and if the field is to be filled, // then process it. foreach ($field_instances as $field_name => $field_instance) { list($field_class, $widget_type) = Field::getFieldClass($this, $field_name); $field_class::processAfterSubmit($this, $field_name); } }