You are here

public function PartyDataBase::getEntity in Party 8.2

Get a particular attached entity

Parameters

int $delta: (optional) A delta to get. Defaults to 0.

bool $create: (optional) Create an entity if it doesn't exist. Defaults to FALSE.

Return value

mixed An entity object or one doesn't exist and we're not creating, FALSE.

1 call to PartyDataBase::getEntity()
PartyDataBase::saveEntity in lib/Drupal/party/Plugin/PartyDataBase.php
Save an entity.

File

lib/Drupal/party/Plugin/PartyDataBase.php, line 218
Contains \Drupal\party\Plugin\PartyDataBase.

Class

PartyDataBase
Class PartyDataBase

Namespace

Drupal\party\Plugin

Code

public function getEntity($delta = 0, $create = FALSE) {

  // If this delta exists, check it's loaded and return it.
  if (isset($this->entities[$delta])) {
    if (isset($this->entities[$delta]->is_stub)) {
      $this
        ->loadEntities(array(
        $delta,
      ));
    }
  }
  else {

    // Let's create an entity and attach it, but no saving happens unless
    // explicitly called. To maintain unsaved entities, this data controller
    // can be stored against forms etc.
    if ($create) {
      $entity = $this
        ->createEntity();
      $this
        ->attachEntity($entity, 'insert', FALSE, $delta);
    }
    else {

      // Nothing found and not creating; return false.
      return FALSE;
    }
  }
  return $this->entities[$delta];
}