public function BackgroundImage::getTargetEntityBundle in Background Image 8
Same name and namespace in other branches
- 2.x src/Entity/BackgroundImage.php \Drupal\background_image\Entity\BackgroundImage::getTargetEntityBundle()
- 2.0.x src/Entity/BackgroundImage.php \Drupal\background_image\Entity\BackgroundImage::getTargetEntityBundle()
Retrieves the target entity bundle, if the type is supported and exists.
Parameters
int $type: The type. Defaults to the currently set type.
string $target: A target identifier split by a colon (:) where the entity type is on the left and the entity bundle identifier to load is on the right. Defaults to the currently set target.
Return value
\Drupal\Core\Entity\EntityTypeInterface|\Drupal\Core\Entity\EntityInterface|null The target EntityType object if it has bundle support or an Entity object if it does not. NULL if not a valid target.
Overrides BackgroundImageInterface::getTargetEntityBundle
1 call to BackgroundImage::getTargetEntityBundle()
- BackgroundImage::label in src/
Entity/ BackgroundImage.php - Gets the label of the entity.
File
- src/
Entity/ BackgroundImage.php, line 513
Class
- BackgroundImage
- Defines the Background Image entity.
Namespace
Drupal\background_image\EntityCode
public function getTargetEntityBundle($type = NULL, $target = NULL) {
if (!isset($type)) {
$type = $this
->getType();
}
if (!isset($target)) {
$target = $this
->getTarget();
}
$entity = NULL;
if ($type === self::TYPE_ENTITY_BUNDLE && $target) {
list($entity_type_id, $entity_bundle) = explode(':', $target);
if (isset($entity_type_id) && isset($entity_bundle) && ($entity_type = $this
->entityTypeManager()
->getDefinition($entity_type_id))) {
if ($bundle_entity_type = $entity_type
->getBundleEntityType()) {
$entity = $this
->entityTypeManager()
->getStorage($bundle_entity_type)
->load($entity_bundle);
}
else {
$entity = $entity_type;
}
}
}
return $entity;
}