diff --git a/core/modules/field/src/Entity/FieldConfig.php b/core/modules/field/src/Entity/FieldConfig.php index ee84c71..75ee1be 100644 --- a/core/modules/field/src/Entity/FieldConfig.php +++ b/core/modules/field/src/Entity/FieldConfig.php @@ -278,8 +278,14 @@ protected function linkTemplates() { protected function urlRouteParameters($rel) { $parameters = parent::urlRouteParameters($rel); $entity_type = \Drupal::entityManager()->getDefinition($this->entity_type); - if (($bundle_entity_type_id = $entity_type->getBundleEntityType()) && !empty($this->bundle)) { - $parameters[$bundle_entity_type_id] = $this->bundle; + if ($entity_type->hasKey('bundle')) { + if ($bundle_entity_type_id = $entity_type->getBundleEntityType()) { + $parameters[$bundle_entity_type_id] = $this->bundle; + } + else { + // Fallback for entities with custom bundles. + $parameters['bundle'] = $this->bundle; + } } return $parameters; } diff --git a/core/modules/field_ui/src/Access/FormModeAccessCheck.php b/core/modules/field_ui/src/Access/FormModeAccessCheck.php index 0df80cf..c740bbb 100644 --- a/core/modules/field_ui/src/Access/FormModeAccessCheck.php +++ b/core/modules/field_ui/src/Access/FormModeAccessCheck.php @@ -64,12 +64,16 @@ public function __construct(EntityManagerInterface $entity_manager) { public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, $form_mode_name = 'default', $bundle = NULL) { $access = AccessResult::neutral(); if ($entity_type_id = $route->getDefault('entity_type_id')) { - // Bundle will be empty for entities which has actual bundle and should - // be fetched from route params - // @see Drupal\field_ui\Routing\RouteSubscriber:alterRoutes(). - if (!isset($bundle) && $bundle_entity_type_id = $this->entityManager->getDefinition($entity_type_id)->getBundleEntityType()) { + if (!isset($bundle)) { + // Find bundle after determining parameter name. $entity_type = $this->entityManager->getDefinition($entity_type_id); - $bundle = $route_match->getRawParameter($bundle_entity_type_id); + if ($bundle_entity_type_id = $entity_type->getBundleEntityType()) { + $bundle = $route_match->getRawParameter($bundle_entity_type_id); + } + elseif ($entity_type->hasKey('bundle')) { + // Add support for custom bundles. + $bundle = $route_match->getRawParameter('bundle'); + } } $visibility = FALSE; diff --git a/core/modules/field_ui/src/Access/ViewModeAccessCheck.php b/core/modules/field_ui/src/Access/ViewModeAccessCheck.php index 4e323f2..b659294 100644 --- a/core/modules/field_ui/src/Access/ViewModeAccessCheck.php +++ b/core/modules/field_ui/src/Access/ViewModeAccessCheck.php @@ -64,12 +64,16 @@ public function __construct(EntityManagerInterface $entity_manager) { public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, $view_mode_name = 'default', $bundle = NULL) { $access = AccessResult::neutral(); if ($entity_type_id = $route->getDefault('entity_type_id')) { - // Bundle will be empty for entities which has actual bundle and should - // be fetched from route params - // @see Drupal\field_ui\Routing\RouteSubscriber:alterRoutes(). if (!isset($bundle)) { + // Find bundle after determining parameter name. $entity_type = $this->entityManager->getDefinition($entity_type_id); - $bundle = $route_match->getRawParameter($entity_type->getBundleEntityType()); + if ($bundle_entity_type_id = $entity_type->getBundleEntityType()) { + $bundle = $route_match->getRawParameter($bundle_entity_type_id); + } + elseif ($entity_type->hasKey('bundle')) { + // Add support for custom bundles. + $bundle = $route_match->getRawParameter('bundle'); + } } $visibility = FALSE; diff --git a/core/modules/field_ui/src/DisplayOverview.php b/core/modules/field_ui/src/DisplayOverview.php index 96d6a9f..d135804 100644 --- a/core/modules/field_ui/src/DisplayOverview.php +++ b/core/modules/field_ui/src/DisplayOverview.php @@ -203,10 +203,15 @@ protected function getTableHeader() { * {@inheritdoc} */ protected function getOverviewRoute($mode) { - return Url::fromRoute('field_ui.display_overview_view_mode_' . $this->entity_type, [ - $this->bundleEntityType => $this->bundle, - 'view_mode_name' => $mode, - ]); + $route_parameters = ['view_mode_name' => $mode]; + if ($this->bundleEntityType) { + $route_parameters[$this->bundleEntityType] = $this->bundle; + } + elseif ($this->entityManager->getDefinition($this->entity_type)->hasKey('bundle')) { + // Add support for custom bundles. + $route_parameters['bundle'] = $this->bundle; + } + return Url::fromRoute('field_ui.display_overview_view_mode_' . $this->entity_type, $route_parameters); } /** diff --git a/core/modules/field_ui/src/FieldOverview.php b/core/modules/field_ui/src/FieldOverview.php index c780936..c239f54 100644 --- a/core/modules/field_ui/src/FieldOverview.php +++ b/core/modules/field_ui/src/FieldOverview.php @@ -125,6 +125,13 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t $this->bundleEntityType => $this->bundle, 'field_config' => $field->id(), ); + if ($this->bundleEntityType) { + $route_parameters[$this->bundleEntityType] = $this->bundle; + } + elseif ($this->entityManager->getDefinition($entity_type_id)->hasKey('bundle')) { + // Add support for custom bundles. + $route_parameters['bundle'] = $this->bundle; + } $table[$name] = array( '#attributes' => array( 'id' => drupal_html_class($name), diff --git a/core/modules/field_ui/src/FieldUI.php b/core/modules/field_ui/src/FieldUI.php index d85702c..49e0d81 100644 --- a/core/modules/field_ui/src/FieldUI.php +++ b/core/modules/field_ui/src/FieldUI.php @@ -28,10 +28,16 @@ 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_id = $entity_type->getBundleEntityType()) { - return new Url("field_ui.overview_$entity_type_id", array( - $bundle_entity_type_id => $bundle, - )); + if ($entity_type->get('field_ui_base_route')) { + $route_parameters = array(); + if ($bundle_entity_type_id = $entity_type->getBundleEntityType()) { + $route_parameters[$bundle_entity_type_id] = $bundle; + } + elseif ($entity_type->hasKey('bundle')) { + // Add support for custom bundles. + $route_parameters['bundle'] = $bundle; + } + return new Url("field_ui.overview_$entity_type_id", $route_parameters); } } diff --git a/core/modules/field_ui/src/FormDisplayOverview.php b/core/modules/field_ui/src/FormDisplayOverview.php index 05db56b..2295319 100644 --- a/core/modules/field_ui/src/FormDisplayOverview.php +++ b/core/modules/field_ui/src/FormDisplayOverview.php @@ -168,10 +168,15 @@ protected function getTableHeader() { * {@inheritdoc} */ protected function getOverviewRoute($mode) { - return Url::fromRoute('field_ui.form_display_overview_form_mode_' . $this->entity_type, [ - $this->bundleEntityType => $this->bundle, - 'form_mode_name' => $mode, - ]); + $route_parameters = ['form_mode_name' => $mode]; + if ($this->bundleEntityType) { + $route_parameters[$this->bundleEntityType] = $this->bundle; + } + elseif ($this->entityManager->getDefinition($this->entity_type)->hasKey('bundle')) { + // Add support for custom bundles. + $route_parameters['bundle'] = $this->bundle; + } + return Url::fromRoute('field_ui.form_display_overview_form_mode_' . $this->entity_type, $route_parameters); } /** diff --git a/core/modules/field_ui/src/OverviewBase.php b/core/modules/field_ui/src/OverviewBase.php index 211f214..68fcd55 100644 --- a/core/modules/field_ui/src/OverviewBase.php +++ b/core/modules/field_ui/src/OverviewBase.php @@ -77,15 +77,20 @@ public static function create(ContainerInterface $container) { */ public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL) { $entity_type = $this->entityManager->getDefinition($entity_type_id); - - if (!($this->bundleEntityType = $entity_type->getBundleEntityType())) { - $this->bundleEntityType = $entity_type; - } - + $this->bundleEntityType = $entity_type->getBundleEntityType(); $stored_bundle = $form_state->get('bundle'); if (!$stored_bundle) { if (!$bundle) { - $bundle = $this->getRequest()->attributes->get('_raw_variables')->get($this->bundleEntityType); + if ($this->bundleEntityType) { + $bundle = $this->getRequest()->attributes->get('_raw_variables')->get($this->bundleEntityType); + } + elseif ($entity_type->hasKey('bundle')) { + // Add support for custom bundles. + $bundle = $this->getRequest()->attributes->get('_raw_variables')->get('bundle'); + } + else { + $bundle = $entity_type_id; + } } $stored_bundle = $bundle; $form_state->set('bundle', $bundle);