protected function PreviewEnabledAccessCheck::entityTypeAndBundleEnabled in Preview Link 8
Same name and namespace in other branches
- 2.x src/Access/PreviewEnabledAccessCheck.php \Drupal\preview_link\Access\PreviewEnabledAccessCheck::entityTypeAndBundleEnabled()
- 2.0.x src/Access/PreviewEnabledAccessCheck.php \Drupal\preview_link\Access\PreviewEnabledAccessCheck::entityTypeAndBundleEnabled()
Check if the entity type and bundle are enabled.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity.
Return value
bool TRUE if enabled, FALSE otherwise.
File
- src/
Access/ PreviewEnabledAccessCheck.php, line 59
Class
- PreviewEnabledAccessCheck
- Preview link access check.
Namespace
Drupal\preview_link\AccessCode
protected function entityTypeAndBundleEnabled(EntityInterface $entity) {
$enabled_entity_types = $this->config
->get('enabled_entity_types');
// If no entity types are specified, fallback to allowing all.
if (empty($enabled_entity_types)) {
return TRUE;
}
// If the entity type exists in the configuration object.
if (isset($enabled_entity_types[$entity
->getEntityTypeId()])) {
$enabled_bundles = $enabled_entity_types[$entity
->getEntityTypeId()];
// If no bundles were specified, assume all bundles are enabled.
if (empty($enabled_bundles)) {
return TRUE;
}
// Otherwise fallback to requiring the specific bundle.
if (in_array($entity
->bundle(), $enabled_bundles)) {
return TRUE;
}
}
return FALSE;
}