diff --git a/core/modules/field_ui/src/FieldUI.php b/core/modules/field_ui/src/FieldUI.php index d751235a..4cd51a4 100644 --- a/core/modules/field_ui/src/FieldUI.php +++ b/core/modules/field_ui/src/FieldUI.php @@ -8,6 +8,7 @@ namespace Drupal\field_ui; use Drupal\Component\Utility\UrlHelper; +use Drupal\Core\Entity\EntityType; use Drupal\Core\Url; /** @@ -29,7 +30,7 @@ class FieldUI { public static function getOverviewRouteInfo($entity_type_id, $bundle) { $entity_type = \Drupal::entityManager()->getDefinition($entity_type_id); if ($entity_type->get('field_ui_base_route')) { - $bundle_entity_type = $entity_type->getBundleEntityType() != 'bundle' ? $entity_type->getBundleEntityType() : $entity_type->id(); + $bundle_entity_type = static::getRouteBundleEntityType($entity_type); return new Url("entity.{$bundle_entity_type}.field_ui_fields", array( $entity_type->getBundleEntityType() => $bundle, )); @@ -67,4 +68,18 @@ public static function getNextDestination(array $destinations) { return $next_destination; } + /** + * Gets the bundle entity type used for route names. + * + * This method returns the bundle entity type, in case there is one. + * + * @param \Drupal\Core\Entity\EntityType $entity_type + * The actual entity type, not the bundle. + * + * @return string + * The used entity type in the route name. + */ + public static function getRouteBundleEntityType(EntityType $entity_type) { + return $entity_type->getBundleEntityType() != 'bundle' ? $entity_type->getBundleEntityType() : $entity_type->id(); + } } diff --git a/core/modules/field_ui/src/Plugin/Derivative/FieldUiLocalTask.php b/core/modules/field_ui/src/Plugin/Derivative/FieldUiLocalTask.php index fa68862..f73e982 100644 --- a/core/modules/field_ui/src/Plugin/Derivative/FieldUiLocalTask.php +++ b/core/modules/field_ui/src/Plugin/Derivative/FieldUiLocalTask.php @@ -13,6 +13,7 @@ use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\field_ui\FieldUI; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -70,10 +71,8 @@ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) { if ($entity_type->get('field_ui_base_route')) { - $field_entity_type = $entity_type->getBundleEntityType(); - if ($field_entity_type == 'bundle') { - $field_entity_type = $entity_type_id; - } + + $field_entity_type = FieldUI::getRouteBundleEntityType($entity_type); $this->derivatives["overview_$field_entity_type"] = array( 'route_name' => "entity.$field_entity_type.field_ui_fields", @@ -177,10 +176,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { */ public function alterLocalTasks(&$local_tasks) { foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) { - $field_entity_type = $entity_type->getBundleEntityType(); - if ($field_entity_type == 'bundle') { - $field_entity_type = $entity_type_id; - } + $field_entity_type = FieldUI::getRouteBundleEntityType($entity_type); if ($route_name = $entity_type->get('field_ui_base_route')) { $local_tasks["field_ui.fields:overview_$field_entity_type"]['base_route'] = $route_name;