You are here

public function FlexiformFormEntityManagerDefault::prepareEntity in Flexiform 7

Prepare an individual entity.

@todo: Put some infinite recursion checking in place.

Parameters

$namespace: The namespace of the entity to be prepared.

Overrides FlexiformFormEntityManagerInterface::prepareEntity

2 calls to FlexiformFormEntityManagerDefault::prepareEntity()
FlexiformFormEntityManagerDefault::getEntity in includes/flexiform.form_entity_manager.inc
Get an entity from the set.
FlexiformFormEntityManagerDefault::prepareEntities in includes/flexiform.form_entity_manager.inc
Prepare the entities needed for the form, either by creating or loading.

File

includes/flexiform.form_entity_manager.inc, line 158
Contains the default entity manager for flexiforms.

Class

FlexiformFormEntityManagerDefault
Class that manages entities in a flexiform.

Code

public function prepareEntity($namespace) {

  // Don't prepare again if and entity is already prepared.
  if (!empty($this->prepared[$namespace])) {
    return;
  }

  // If this is the base entity and its not prepared we must throw an error
  // as without a base entity set nothing is going to work.
  if (empty($this->entities[$this->base_entity_key])) {
    throw new Exception(t('Cannot Prepare Entities without the base entity being set, this must be set using setBaseEntity.'));
  }
  $info = $this
    ->getEntitySettings($namespace);

  // First make sure that any parameters have been prepared.
  if (!empty($info['parameters'])) {
    foreach ($info['parameters'] as $param_namespace) {
      if (empty($this->prepared[$param_namespace])) {
        $this
          ->prepareEntity($param_namespace);
      }
    }
  }

  // Prepare this entity.
  if ($handler = $this
    ->getEntityHandler($namespace)) {
    $this->entities[$namespace] = $handler
      ->getEntity();
    $this->prepared[$namespace] = TRUE;
  }
}