Commit 50ae3296 authored by alexpott's avatar alexpott

Issue #1982088 by tim.plunkett: Remove hook_entity_bundle_info()'s need for 'real path'.

parent 5838ea9a
......@@ -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.
*
......@@ -106,12 +101,7 @@ function hook_entity_view_mode_info_alter(&$view_modes) {
* @see hook_entity_bundle_info_alter()
*/
function hook_entity_bundle_info() {
$bundles['user']['user'] = array(
'label' => t('User'),
'admin' => array(
'path' => 'admin/config/people/accounts',
),
);
$bundles['user']['user']['label'] = t('User');
return $bundles;
}
......
......@@ -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;
}
}
......@@ -184,12 +184,7 @@ function custom_block_entity_bundle_info() {
$bundles = array();
foreach (config_get_storage_names_with_prefix('custom_block.type.') as $config_name) {
$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'),
),
);
$bundles['custom_block'][$config->get('id')]['label'] = $config->get('label');
}
return $bundles;
}
......
......@@ -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;
......
......@@ -176,13 +176,7 @@ function contact_entity_bundle_info() {
$bundles = array();
foreach (config_get_storage_names_with_prefix('contact.category.') as $config_name) {
$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'),
),
);
$bundles['contact_message'][$config->get('id')]['label'] = $config->get('label');
}
return $bundles;
}
......
......@@ -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::entityManager();
$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::entityManager()->getAdminPath($entity_type, $bundle);
return $admin_path . '/fields';
}
......@@ -258,17 +258,6 @@ function field_ui_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) {
state()->set('menu_rebuild_needed', TRUE);
}
/**
* 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.
*/
......@@ -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::entityManager()->getAdminPath('node', $form_state['values']['type']);
$form_state['redirect'] = "$admin_path/fields";
}
}
......
......@@ -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 <a href="@url">configure them</a>.', array('%view_mode' => $view_mode_label, '@url' => url($path))));
}
$bundle_settings['view_modes'][$view_mode]['custom_settings'] = !empty($value);
......
......@@ -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.
......@@ -22,6 +25,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}
*/
......@@ -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
......
......@@ -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);
}
/**
......
......@@ -213,15 +213,10 @@ function node_entity_view_mode_info() {
function node_entity_bundle_info() {
$bundles = array();
// Bundles must provide a human readable name so we can create help and error
// messages, and the path to attach Field admin pages to.
// messages.
node_type_cache_reset();
foreach (node_type_get_names() as $type => $name) {
$bundles['node'][$type] = array(
'label' => $name,
'admin' => array(
'real path' => 'admin/structure/types/manage/' . $type,
),
);
$bundles['node'][$type]['label'] = $name;
}
return $bundles;
}
......
......@@ -125,12 +125,7 @@ function taxonomy_entity_bundle_info() {
$bundles = array();
foreach (taxonomy_vocabulary_get_names() as $id) {
$config = config('taxonomy.vocabulary.' . $id);
$bundles['taxonomy_term'][$id] = array(
'label' => $config->get('name'),
'admin' => array(
'real path' => 'admin/structure/taxonomy/manage/' . $id,
),
);
$bundles['taxonomy_term'][$id]['label'] = $config->get('name');
}
return $bundles;
}
......
......@@ -17,6 +17,7 @@
*/
function translation_entity_overview(EntityInterface $entity) {
$controller = translation_entity_controller($entity->entityType());
$entity_manager = Drupal::entityManager();
$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';
......
......@@ -143,12 +143,7 @@ function user_entity_view_mode_info() {
* Implements hook_entity_bundle_info().
*/
function user_entity_bundle_info() {
$bundles['user']['user'] = array(
'label' => t('User'),
'admin' => array(
'path' => 'admin/config/people/accounts',
),
);
$bundles['user']['user']['label'] = t('User');
return $bundles;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment