You are here

public function PartyDataBase::__construct in Party 8.2

Constructor

Parameters

party $party: The party object.

string $plugin_id: The data set name.

array $configuration: The data set info.

File

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

Class

PartyDataBase
Class PartyDataBase

Namespace

Drupal\party\Plugin

Code

public function __construct(Party $party, $plugin_id, $configuration) {
  $this->dataName = $plugin_id;
  $this->dataConfig = $configuration;
  $this->party = $party;
  if (!empty($this->party
    ->id())) {

    // Without attached entities, this controller is pretty useless, so let's
    // assume anyone wants them loaded, but we'll do so using stubs to save a
    // full entity load.
    $query = db_select('party_attached_entity', 'ae')
      ->fields('ae', array(
      'delta',
      'entity_id',
    ))
      ->condition('pid', $this->party
      ->id(), '=')
      ->condition('data_set_name', $this->dataName);
    $result = $query
      ->execute()
      ->fetchAllAssoc('delta');

    // Stub entities no longer exist in drupal 8. So we create a stdClass for now.
    foreach ($result as $delta => $entity) {
      $stub = new stdClass();
      $stub->id = $entity->entity_id;
      $stub->bundle = $this
        ->getDataInfo('entity bundle');
      $stub->is_stub = TRUE;
      $this->entities[$delta] = $stub;
    }
  }
}