You are here

public function FlexiformFormEntityEntityReference::saveEntity in Flexiform 7

Save the entity upon submission of the form.

Parameters

$entity: The entity object being saved.

Overrides FlexiformFormEntityBase::saveEntity

File

includes/form_entity/entityreference.form_entity.inc, line 65
Contains class for a basic entity getter.

Class

FlexiformFormEntityEntityReference
Form Entity Class for Managing the Entity Reference fields

Code

public function saveEntity($entity) {

  // If the entity is still false do not save it!
  if ($entity === FALSE) {
    return;
  }

  // Save the entity.
  entity_save($this->entity_type, $entity);
  list($id, , ) = entity_extract_ids($this->entity_type, $entity);

  // Get Settings for this Getter/Setter.
  $settings = $this->settings;

  // Get the delta.
  $delta = 0;
  if (!empty($settings['delta'])) {
    $delta = $settings['delta'];
  }

  // Get the base entity and save the reference back.
  $base_entity = $this
    ->getParam('base');
  if (empty($base_entity->{$this->getter['field_name']}[LANGUAGE_NONE][$delta]['target_id']) || $base_entity->{$this->getter['field_name']}[LANGUAGE_NONE][$delta]['target_id'] != $id) {
    $base_entity->{$this->getter['field_name']}[LANGUAGE_NONE][$delta]['target_id'] = $id;
    $base_entity_type = $this
      ->getParamType('base');
    entity_save($base_entity_type, $base_entity);
  }
}