You are here

public function FlexiformFormEntityNew::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/new.form_entity.inc, line 15
Contains class for a basic entity getter.

Class

FlexiformFormEntityNew
Form Entity that creates a new entity.

Code

public function getEntity() {
  parent::getEntity();
  $values = array();

  // Work out if there is a bundle key.
  $entity_info = entity_get_info($this->entity_type);
  if (!empty($entity_info['entity keys']['bundle'])) {
    $bundle_key = $entity_info['entity keys']['bundle'];
    $values[$bundle_key] = $this->settings['bundle'];
  }

  // Make a new entity.
  $entity = entity_create($this->entity_type, $values);
  return $this
    ->checkBundle($entity) ? $entity : FALSE;
}