You are here

public function SyncIntent::setEntity in CMS Content Sync 8

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

Set the entity when pulling (may not be saved yet then).

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity you just created

Return value

$this|EntityInterface|TranslatableInterface

Throws

\Drupal\cms_content_sync\Exception\SyncException

1 call to SyncIntent::setEntity()
SyncIntent::getEntity in src/SyncIntent.php

File

src/SyncIntent.php, line 209

Class

SyncIntent
Class SyncIntent.

Namespace

Drupal\cms_content_sync

Code

public function setEntity(EntityInterface $entity) {
  if ($entity == $this->entity) {
    return $this->entity;
  }
  if ($this->entity) {
    throw new SyncException(SyncException::CODE_INTERNAL_ERROR, null, 'Attempting to re-set existing entity.');
  }

  /**
   * @var \Drupal\Core\Entity\EntityInterface       $entity
   * @var \Drupal\Core\Entity\TranslatableInterface $entity
   */
  $this->entity = $entity;
  if ($this->entity) {
    if ($this->activeLanguage) {
      $this->entity = $this->entity
        ->getTranslation($this->activeLanguage);
    }
  }
  return $this->entity;
}