function _layout_builder_bundle_has_no_translations in Drupal 8
Determines if there are zero translations for the bundle.
Parameters
string $entity_type_id: The entity type ID.
string $bundle: The bundle name.
Return value
bool TRUE if there are zero translations for the bundle, otherwise FALSE.
1 call to _layout_builder_bundle_has_no_translations()
- layout_builder_post_update_make_layout_untranslatable in core/
modules/ layout_builder/ layout_builder.post_update.php - Set the layout builder field as non-translatable where possible.
File
- core/
modules/ layout_builder/ layout_builder.post_update.php, line 284 - Post update functions for Layout Builder.
Code
function _layout_builder_bundle_has_no_translations($entity_type_id, $bundle) {
$entity_update_manager = \Drupal::entityDefinitionUpdateManager();
$entity_type = $entity_update_manager
->getEntityType($entity_type_id);
if (!$entity_type
->isTranslatable()) {
return TRUE;
}
$query = \Drupal::entityTypeManager()
->getStorage($entity_type_id)
->getQuery();
$bundle_key = $entity_type
->getKey('bundle');
if ($entity_type
->hasKey('default_langcode')) {
if ($bundle_key) {
$query
->condition($bundle_key, $bundle);
}
if ($entity_type
->isRevisionable()) {
$query
->allRevisions();
}
$query
->condition($entity_type
->getKey('default_langcode'), 0)
->accessCheck(FALSE)
->range(0, 1);
$results = $query
->execute();
return empty($results);
}
// A translatable entity type should always have a default_langcode key. If it
// doesn't we have no way to determine if there are translations.
return FALSE;
}