You are here

public static function EntityStatus::preCreate in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x src/Entity/EntityStatus.php \Drupal\cms_content_sync\Entity\EntityStatus::preCreate()
  2. 2.0.x src/Entity/EntityStatus.php \Drupal\cms_content_sync\Entity\EntityStatus::preCreate()

Changes the values of an entity before it is created.

Load defaults for example.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

mixed[] $values: An array of values to set, keyed by property name. If the entity type has bundles the bundle key has to be specified.

Overrides EntityBase::preCreate

File

src/Entity/EntityStatus.php, line 68

Class

EntityStatus
Defines the "Content Sync - Entity Status" entity type.

Namespace

Drupal\cms_content_sync\Entity

Code

public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {

  // Set Entity ID or UUID by default one or the other is not set.
  if (!isset($values['entity_type'])) {
    throw new \Exception(t('The type of the entity is required.'));
  }
  if (!isset($values['flow'])) {
    throw new \Exception(t('The flow is required.'));
  }
  if (!isset($values['pool'])) {
    throw new \Exception(t('The pool is required.'));
  }

  /**
   * @var \Drupal\Core\Entity\EntityInterface $entity
   */
  $entity = \Drupal::service('entity.repository')
    ->loadEntityByUuid($values['entity_type'], $values['entity_uuid']);
  if (!isset($values['entity_type_version'])) {
    $values['entity_type_version'] = Flow::getEntityTypeVersion($entity
      ->getEntityType()
      ->id(), $entity
      ->bundle());
    return;
  }
}