You are here

public function FlexiformFormEntityLoad::getEntity in Flexiform 7

Get the entity for the form.

Return value

A loaded or created entity object ready for use in the form.

Overrides FlexiformFormEntityBase::getEntity

File

includes/form_entity/load.form_entity.inc, line 15
Contains class for a basic entity getter.

Class

FlexiformFormEntityLoad
Form Entity that loads an entity from an id stored in config.

Code

public function getEntity() {
  parent::getEntity();
  $id = $this->settings['entity_id'];

  // Don't do anything if the $id is empty.
  if (empty($id)) {
    return FALSE;
  }

  // Handle path arguments.
  if (stripos($id, '%') === 0 && is_numeric(ltrim($id, '%'))) {

    // Try to use the standard drupal menu handling. This allows the use
    // of paths with load wildcards in them.
    $position = ltrim($id, '%');
    $menu_object = menu_get_object($this->entity_type, $position);
    if ($menu_object && $this
      ->checkBundle($menu_object)) {
      return $menu_object;
    }
    else {
      if ($menu_object) {
        return FALSE;
      }
    }

    // If the menu system hasn't yielded a result use the arg function.
    $id = arg($position);
  }
  $entity = entity_load_single($this->entity_type, $id);
  return $this
    ->checkBundle($entity) ? $entity : FALSE;
}