You are here

public function BackgroundImage::associateEntity in Background Image 2.0.x

Same name and namespace in other branches
  1. 8 src/Entity/BackgroundImage.php \Drupal\background_image\Entity\BackgroundImage::associateEntity()
  2. 2.x src/Entity/BackgroundImage.php \Drupal\background_image\Entity\BackgroundImage::associateEntity()

Associates a specific entity with the background image.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: An entity object.

bool $save: Flag indicating whether or not to save the background image entity after it has been associated with the entity.

Overrides BackgroundImageInterface::associateEntity

File

src/Entity/BackgroundImage.php, line 128

Class

BackgroundImage
Defines the Background Image entity.

Namespace

Drupal\background_image\Entity

Code

public function associateEntity(EntityInterface $entity = NULL, $save = TRUE) {

  // Immediately return if not a valid entity.
  if (!$this
    ->getBackgroundImageManager()
    ->validEntity($entity)) {
    return;
  }
  $this
    ->set('type', self::TYPE_ENTITY)
    ->set('target', $entity
    ->getEntityTypeId() . ':' . $entity
    ->uuid())
    ->set('label', NULL);
  if ($save) {
    $this
      ->save();
  }
}