Example #1
0
 /**
  * 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);
         }
     }
 }