You are here

function flexiform_get_base_entity in Flexiform 7

Get the base entity for a flexible form.

If an id is passed, load the entity and return it. Otherwise create a new entity with the correct type and bundle.

Parameters

Flexiform $flexiform: A flexiform object.

int $base_entity_id: (optional) The id of the base entity if it already exists.

Return value

stdClass|Entity The base entity for the form.

File

includes/flexiform.flexiform.inc, line 21
flexiform.flexiform.inc Helper function for embedding the fields into the flexiform in an arbitrary order

Code

function flexiform_get_base_entity($flexiform, $base_entity_id = FALSE) {
  if ($base_entity_id) {
    $base_entity = entity_load_single($flexiform->base_entity, $base_entity_id);

    //@todo: Check the entity is the right bundle.
    return $base_entity;
  }
  $info = entity_get_info($flexiform->base_entity);
  $values = array();
  if (!empty($info['entity keys']['bundle'])) {
    $values[$info['entity keys']['bundle']] = $flexiform->base_entity_bundle;
  }
  $base_entity = entity_create($flexiform->base_entity, $values);
  return $base_entity;
}