public function FlexiformFormEntityEntityReference::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/ entityreference.form_entity.inc, line 15 - Contains class for a basic entity getter.
Class
- FlexiformFormEntityEntityReference
- Form Entity Class for Managing the Entity Reference fields
Code
public function getEntity() {
parent::getEntity();
$settings = $this->settings;
// Get the base entity.
$base_entity = $this
->getParam('base');
// Get the delta.
$delta = 0;
if (!empty($settings['delta'])) {
$delta = $settings['delta'];
}
// Check we have enough information to load the entity.
if (!$base_entity || empty($base_entity->{$this->getter['field_name']}[LANGUAGE_NONE][$delta]['target_id'])) {
return empty($base_entity) ? FALSE : $this
->createEntity();
}
// Load the entity;
$target_id = $base_entity->{$this->getter['field_name']}[LANGUAGE_NONE][$delta]['target_id'];
$target_entity = entity_load_single($this->entity_type, $target_id);
if (!$target_entity) {
return FALSE;
}
return $this
->checkBundle($target_entity) ? $target_entity : FALSE;
}