diff --git a/core/includes/entity.api.php b/core/includes/entity.api.php index 08d0099..c95b42a 100644 --- a/core/includes/entity.api.php +++ b/core/includes/entity.api.php @@ -94,11 +94,6 @@ function hook_entity_view_mode_info_alter(&$view_modes) { * type in the EntityManager, but for the bundle only. When determining * the URI of an entity, if a 'uri_callback' is defined for both the * entity type and the bundle, the one for the bundle is used. - * - admin: An array of information that allows Field UI pages to attach - * themselves to the existing administration pages for the bundle. - * Elements: - * - real path: The actual path (no placeholder) of the bundle's main - * administration page. This will be used to generate links. * - translatable: (optional) A boolean value specifying whether this bundle * has translation support enabled. Defaults to FALSE. * diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index d998c50..1ad1495 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -200,4 +200,31 @@ public function getAccessController($entity_type) { return $this->controllers['access'][$entity_type]; } + /** + * Returns the administration path for an entity type's bundle. + * + * @param string $entity_type + * The entity type. + * @param string $bundle + * The name of the bundle. + * + * @return string + * The administration path for an entity type bundle, if it exists. + */ + public function getAdminPath($entity_type, $bundle) { + $admin_path = ''; + $entity_info = $this->getDefinition($entity_type); + // Check for an entity type's admin base path. + if (isset($entity_info['route_base_path'])) { + // If the entity type has a bundle prefix, strip it out of the path. + if (isset($entity_info['bundle_prefix'])) { + $bundle = str_replace($entity_info['bundle_prefix'], '', $bundle); + } + // Replace any dynamic 'bundle' portion of the path with the actual bundle. + $admin_path = str_replace('{bundle}', $bundle, $entity_info['route_base_path']); + } + + return $admin_path; + } + } diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index 1bcf414..e868860 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -186,9 +186,6 @@ function custom_block_entity_bundle_info() { $config = config($config_name); $bundles['custom_block'][$config->get('id')] = array( 'label' => $config->get('label'), - 'admin' => array( - 'real path' => 'admin/structure/custom-blocks/manage/' . $config->get('id'), - ), ); } return $bundles; diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 8466ce2..172018c 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -118,9 +118,6 @@ function comment_entity_bundle_info() { // Provide the node type/bundle name for other modules, so it does not // have to be extracted manually from the bundle name. 'node bundle' => $type, - 'admin' => array( - 'real path' => 'admin/structure/types/manage/' . $type . '/comment', - ), ); } return $bundles; diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index c3e6fae..d1acd64 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -178,10 +178,6 @@ function contact_entity_bundle_info() { $config = config($config_name); $bundles['contact_message'][$config->get('id')] = array( 'label' => $config->get('label'), - 'admin' => array( - 'real path' => 'admin/structure/contact/manage/' . $config->get('id'), - 'access arguments' => array('administer contact forms'), - ), ); } return $bundles; diff --git a/core/modules/field_ui/field_ui.admin.inc b/core/modules/field_ui/field_ui.admin.inc index eda59c8..313f3e3 100644 --- a/core/modules/field_ui/field_ui.admin.inc +++ b/core/modules/field_ui/field_ui.admin.inc @@ -14,6 +14,7 @@ function field_ui_fields_list() { $instances = field_info_instances(); $field_types = field_info_field_types(); $bundles = entity_get_bundles(); + $entity_manager = Drupal::service('plugin.manager.entity'); $modules = system_rebuild_module_data(); @@ -37,7 +38,7 @@ function field_ui_fields_list() { } // Add the current instance. - $admin_path = field_ui_bundle_admin_path($entity_type, $bundle); + $admin_path = $entity_manager->getAdminPath($entity_type, $bundle); $rows[$field_name]['data'][2][] = $admin_path ? l($bundles[$entity_type][$bundle]['label'], $admin_path . '/fields') : $bundles[$entity_type][$bundle]['label']; } } @@ -454,6 +455,6 @@ function field_ui_next_destination($entity_type, $bundle) { unset($_REQUEST['destinations']); return field_ui_get_destinations($destinations); } - $admin_path = field_ui_bundle_admin_path($entity_type, $bundle); + $admin_path = Drupal::service('plugin.manager.entity')->getAdminPath($entity_type, $bundle); return $admin_path . '/fields'; } diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index 2c50450..5457ac7 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -259,17 +259,6 @@ function field_ui_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) { } /** - * Determines the adminstration path for a bundle. - */ -function field_ui_bundle_admin_path($entity_type, $bundle_name) { - $bundles = entity_get_bundles($entity_type); - $bundle_info = $bundles[$bundle_name]; - if (isset($bundle_info['admin'])) { - return isset($bundle_info['admin']['real path']) ? $bundle_info['admin']['real path'] : $bundle_info['admin']['path']; - } -} - -/** * Identifies inactive fields within a bundle. */ function field_ui_inactive_instances($entity_type, $bundle_name = NULL) { @@ -330,7 +319,8 @@ function field_ui_form_node_type_form_alter(&$form, $form_state) { */ function field_ui_form_node_type_form_submit($form, &$form_state) { if ($form_state['triggering_element']['#parents'][0] === 'save_continue') { - $form_state['redirect'] = field_ui_bundle_admin_path('node', $form_state['values']['type']) .'/fields'; + $admin_path = Drupal::service('plugin.manager.entity')->getAdminPath('node', $form_state['values']['type']); + $form_state['redirect'] = "$admin_path/fields"; } } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php index 836cc88..cf4f6de 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php @@ -486,7 +486,7 @@ public function submitForm(array &$form, array &$form_state) { } $view_mode_label = $view_modes[$view_mode]['label']; - $path = field_ui_bundle_admin_path($this->entity_type, $this->bundle) . "/display/$view_mode"; + $path = $this->entityManager->getAdminPath($this->entity_type, $this->bundle) . "/display/$view_mode"; drupal_set_message(t('The %view_mode mode now uses custom display settings. You might want to configure them.', array('%view_mode' => $view_mode_label, '@url' => url($path)))); } $bundle_settings['view_modes'][$view_mode]['custom_settings'] = !empty($value); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php index f74ecb6..ec13c50 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php @@ -8,12 +8,15 @@ namespace Drupal\field_ui\Form; use Drupal\Core\Form\ConfirmFormBase; +use Drupal\Core\ControllerInterface; +use Drupal\Core\Entity\EntityManager; use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a form for removing a field instance from a bundle. */ -class FieldDeleteForm extends ConfirmFormBase { +class FieldDeleteForm extends ConfirmFormBase implements ControllerInterface { /** * The field instance being deleted. @@ -23,6 +26,32 @@ class FieldDeleteForm extends ConfirmFormBase { protected $instance; /** + * The entity manager. + * + * @var \Drupal\Core\Entity\EntityManager + */ + protected $entityManager; + + /** + * Constructs a new FieldDeleteForm object. + * + * @param \Drupal\Core\Entity\EntityManager $entity_manager + * The entity manager. + */ + public function __construct(EntityManager $entity_manager) { + $this->entityManager = $entity_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.entity') + ); + } + + /** * {@inheritdoc} */ public function getFormID() { @@ -47,7 +76,7 @@ protected function getConfirmText() { * {@inheritdoc} */ protected function getCancelPath() { - return field_ui_bundle_admin_path($this->instance->entity_type, $this->instance->bundle) . '/fields'; + return $this->entityManager->getAdminPath($this->instance->entity_type, $this->instance->bundle) . '/fields'; } /** @@ -77,7 +106,7 @@ public function submitForm(array &$form, array &$form_state) { drupal_set_message(t('There was a problem removing the %field from the %type content type.', array('%field' => $this->instance->label(), '%type' => $bundle_label)), 'error'); } - $admin_path = field_ui_bundle_admin_path($this->instance->entity_type, $this->instance->bundle); + $admin_path = $this->entityManager->getAdminPath($this->instance->entity_type, $this->instance->bundle); $form_state['redirect'] = field_ui_get_destinations(array($admin_path . '/fields')); // Fields are purged on cron. However field module prevents disabling modules diff --git a/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php b/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php index 8973d95..a8cd891 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php @@ -83,7 +83,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, form_load_include($form_state, 'inc', 'field_ui', 'field_ui.admin'); $this->entity_type = $entity_type; $this->bundle = $bundle; - $this->adminPath = field_ui_bundle_admin_path($this->entity_type, $this->bundle); + $this->adminPath = $this->entityManager->getAdminPath($this->entity_type, $this->bundle); } /** diff --git a/core/modules/node/node.module b/core/modules/node/node.module index f2d0ae9..f9cdf7e 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -218,9 +218,6 @@ function node_entity_bundle_info() { foreach (node_type_get_names() as $type => $name) { $bundles['node'][$type] = array( 'label' => $name, - 'admin' => array( - 'real path' => 'admin/structure/types/manage/' . $type, - ), ); } return $bundles; diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index e10e9ea..ee9f9d5 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -127,9 +127,6 @@ function taxonomy_entity_bundle_info() { $config = config('taxonomy.vocabulary.' . $id); $bundles['taxonomy_term'][$id] = array( 'label' => $config->get('name'), - 'admin' => array( - 'real path' => 'admin/structure/taxonomy/' . $id, - ), ); } return $bundles; diff --git a/core/modules/translation_entity/translation_entity.pages.inc b/core/modules/translation_entity/translation_entity.pages.inc index 6d743fb..190eca5 100644 --- a/core/modules/translation_entity/translation_entity.pages.inc +++ b/core/modules/translation_entity/translation_entity.pages.inc @@ -17,6 +17,7 @@ */ function translation_entity_overview(EntityInterface $entity) { $controller = translation_entity_controller($entity->entityType()); + $entity_manager = Drupal::service('plugin.manager.entity'); $languages = language_list(); $original = $entity->language()->langcode; $translations = $entity->getTranslationLanguages(); @@ -124,7 +125,7 @@ function translation_entity_overview(EntityInterface $entity) { $links['add']['title'] = t('Add'); } elseif ($field_ui) { - $entity_path = field_ui_bundle_admin_path($entity->entityType(), $entity->bundle()); + $entity_path = $entity_manager->getAdminPath($entity->entityType(), $entity->bundle()); // Link directly to the fields tab to make it easier to find the // setting to enable translation on fields. $path = $entity_path . '/fields';