You are here

public function PartyDataBase::createEntity in Party 8.2

Create a new entity

This method provides a helper to create a new attached entity for the data set without having to figure out the entity type and bundle.

Return value

object A newly created unsaved entity of the correct type and bundle.

1 call to PartyDataBase::createEntity()
PartyDataBase::getEntity in lib/Drupal/party/Plugin/PartyDataBase.php
Get a particular attached entity

File

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

Class

PartyDataBase
Class PartyDataBase

Namespace

Drupal\party\Plugin

Code

public function createEntity() {

  // Create a placeholder entity
  $values = array();
  if ($this
    ->getDataInfo('bundle key')) {
    $values[$this
      ->getDataInfo('bundle key')] = $this
      ->getDataInfo('entity bundle');
  }

  // Create the entity, set our data set and return
  $entity = drupal_container()
    ->get('plugin.manager.entity')
    ->getStorageController($this
    ->getDataInfo('entity type'))
    ->create($values);

  // Add the other properties party needs.
  $entity->data_set_name = $this->data_set;
  if (isset($this->party->pid)) {
    $entity->party_attaching_party = $this->party
      ->id();
  }
  return $entity;
}