You are here

public function EntityContext::save in Lightning Core 8.4

Same name and namespace in other branches
  1. 8.5 tests/contexts/EntityContext.behat.inc \Acquia\LightningExtension\Context\EntityContext::save()
  2. 8 tests/contexts/EntityContext.behat.inc \Acquia\LightningExtension\Context\EntityContext::save()
  3. 8.2 tests/contexts/EntityContext.behat.inc \Acquia\LightningExtension\Context\EntityContext::save()
  4. 8.3 tests/contexts/EntityContext.behat.inc \Acquia\LightningExtension\Context\EntityContext::save()

Saves an entity, ensuring automatic clean-up.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to save.

1 call to EntityContext::save()
EntityContext::createMultiple in tests/contexts/EntityContext.behat.inc
Creates a set of entities from tabular data.

File

tests/contexts/EntityContext.behat.inc, line 39

Class

EntityContext
Contains miscellaneous step definitions for working with Drupal entities.

Namespace

Acquia\LightningExtension\Context

Code

public function save(EntityInterface $entity) {
  $uid = $this
    ->getCurrentUserUid();
  if ($uid && $entity instanceof EntityOwnerInterface && $entity
    ->getOwnerId() == 0) {
    $entity
      ->setOwnerId($uid)
      ->save();
  }
  else {
    $entity
      ->save();
    $entity_type = $entity
      ->getEntityTypeId();
    $this->trash[$entity_type][] = $entity
      ->id();
  }
}