public function BackgroundImage::associateEntity in Background Image 8
Same name and namespace in other branches
- 2.x src/Entity/BackgroundImage.php \Drupal\background_image\Entity\BackgroundImage::associateEntity()
- 2.0.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 127
Class
- BackgroundImage
- Defines the Background Image entity.
Namespace
Drupal\background_image\EntityCode
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();
}
}