Commit 77725b60 authored by alexpott's avatar alexpott

Issue #2281645 by dawehner, andypost: Make entity annotations use link...

Issue #2281645 by dawehner, andypost: Make entity annotations use link templates instead of route names
parent e298180f
......@@ -164,8 +164,9 @@ public function urlInfo($rel = 'canonical', array $options = []) {
$link_templates = $this->linkTemplates();
if (isset($link_templates[$rel])) {
// If there is a template for the given relationship type, generate the path.
$uri = new Url($link_templates[$rel], $this->urlRouteParameters($rel));
$route_parameters = $this->urlRouteParameters($rel);
$route_name = "entity.{$this->entityTypeId}." . str_replace(array('-', 'drupal:'), array('_', ''), $rel);
$uri = new Url($route_name, $route_parameters);
}
else {
$bundle = $this->bundle();
......@@ -224,7 +225,7 @@ public function hasLinkTemplate($rel) {
* Returns an array link templates.
*
* @return array
* An array of link templates containing route names.
* An array of link templates containing paths.
*/
protected function linkTemplates() {
return $this->getEntityType()->getLinkTemplates();
......
......@@ -105,9 +105,9 @@ public function label();
* example:
* @code
* links = {
* "canonical" = "entity.node.canonical",
* "edit-form" = "entity.node.edit_form",
* "version-history" = "entity.node.version_history"
* "canonical" = "/node/{node}",
* "edit-form" = "/node/{node}/edit",
* "version-history" = "/node/{node}/revisions"
* }
* @endcode
* or specified in a callback function set like:
......
......@@ -546,8 +546,12 @@ public function hasLinkTemplate($key) {
/**
* {@inheritdoc}
*/
public function setLinkTemplate($key, $route_name) {
$this->links[$key] = $route_name;
public function setLinkTemplate($key, $path) {
if ($path[0] !== '/') {
throw new \InvalidArgumentException('Link templates accepts paths, which have to start with a leading slash.');
}
$this->links[$key] = $path;
return $this;
}
......
......@@ -455,7 +455,7 @@ public function getLinkTemplates();
* The link type.
*
* @return string|bool
* The route name for this link, or FALSE if it doesn't exist.
* The path for this link, or FALSE if it doesn't exist.
*/
public function getLinkTemplate($key);
......@@ -475,12 +475,15 @@ public function hasLinkTemplate($key);
*
* @param string $key
* The name of a link.
* @param string $route_name
* The route name to use for the link.
* @param string $path
* The route path to use for the link.
*
* @return $this
*
* @throws \InvalidArgumentException
* Thrown when the path does not start with a leading slash.
*/
public function setLinkTemplate($key, $route_name);
public function setLinkTemplate($key, $path);
/**
* Gets the callback for the label of the entity.
......
......@@ -44,6 +44,6 @@ function action_entity_type_build(array &$entity_types) {
->setFormClass('edit', 'Drupal\action\ActionEditForm')
->setFormClass('delete', 'Drupal\action\Form\ActionDeleteForm')
->setListBuilderClass('Drupal\action\ActionListBuilder')
->setLinkTemplate('delete-form', 'entity.action.delete_form')
->setLinkTemplate('edit-form', 'entity.action.edit_form');
->setLinkTemplate('delete-form', '/admin/config/system/actions/configure/{action}/delete')
->setLinkTemplate('edit-form', '/admin/config/system/actions/configure/{action}');
}
......@@ -33,9 +33,9 @@
* }
* },
* links = {
* "canonical" = "entity.aggregator_feed.canonical",
* "edit-form" = "entity.aggregator_feed.edit_form",
* "delete-form" = "entity.aggregator_feed.delete_form",
* "canonical" = "/aggregator/sources/{aggregator_feed}",
* "edit-form" = "/aggregator/sources/{aggregator_feed}/configure",
* "delete-form" = "/aggregator/sources/{aggregator_feed}/delete",
* },
* field_ui_base_route = "aggregator.admin_overview",
* base_table = "aggregator_feed",
......
......@@ -36,8 +36,8 @@
* "id" = "id"
* },
* links = {
* "delete-form" = "entity.block.delete_form",
* "edit-form" = "entity.block.edit_form"
* "delete-form" = "/admin/structure/block/manage/{block}/delete",
* "edit-form" = "/admin/structure/block/manage/{block}"
* }
* )
*/
......
......@@ -45,6 +45,15 @@ entity.block_content.canonical:
requirements:
_entity_access: 'block_content.update'
entity.block_content.edit_form:
path: '/block/{block_content}'
defaults:
_entity_form: 'block_content.edit'
options:
_admin_route: TRUE
requirements:
_entity_access: 'block_content.update'
entity.block_content.delete_form:
path: '/block/{block_content}/delete'
defaults:
......
......@@ -39,9 +39,9 @@
* revision_table = "block_content_revision",
* data_table = "block_content_field_data",
* links = {
* "canonical" = "entity.block_content.canonical",
* "delete-form" = "entity.block_content.delete_form",
* "edit-form" = "entity.block_content.canonical",
* "canonical" = "/block/{block_content}",
* "delete-form" = "/block/{block_content}/delete",
* "edit-form" = "/block/{block_content}",
* },
* translatable = TRUE,
* entity_keys = {
......
......@@ -35,8 +35,8 @@
* "label" = "label"
* },
* links = {
* "delete-form" = "entity.block_content_type.delete_form",
* "edit-form" = "entity.block_content_type.edit_form"
* "delete-form" = "/admin/structure/block/block-content/manage/{block_content_type}/delete",
* "edit-form" = "/admin/structure/block/block-content/manage/{block_content_type}"
* }
* )
*/
......
......@@ -89,8 +89,8 @@ function book_entity_type_build(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_types['node']
->setFormClass('book_outline', 'Drupal\book\Form\BookOutlineForm')
->setLinkTemplate('book-outline-form', 'entity.node.book_outline_form')
->setLinkTemplate('book-remove-form', 'entity.node.book_remove_form');
->setLinkTemplate('book-outline-form', '/node/{node}/outline')
->setLinkTemplate('book-remove-form', '/node/{node}/outline/remove');
}
/**
......
......@@ -47,9 +47,9 @@
* "uuid" = "uuid"
* },
* links = {
* "canonical" = "entity.comment.canonical",
* "delete-form" = "entity.comment.delete_form",
* "edit-form" = "entity.comment.edit_form",
* "canonical" = "/comment/{comment}",
* "delete-form" = "/comment/{comment}/delete",
* "edit-form" = "/comment/{comment}/edit",
* },
* bundle_entity_type = "comment_type",
* field_ui_base_route = "entity.comment_type.edit_form",
......
......@@ -34,9 +34,9 @@
* "label" = "label"
* },
* links = {
* "delete-form" = "entity.comment_type.delete_form",
* "edit-form" = "entity.comment_type.edit_form",
* "add-form" = "entity.comment_type.add_form"
* "delete-form" = "/admin/structure/comment/manage/{comment_type}/delete",
* "edit-form" = "/admin/structure/comment/manage/{comment_type}",
* "add-form" = "/admin/structure/comment/types/add"
* }
* )
*/
......
......@@ -224,7 +224,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $type = '
if ($this->moduleHandler->moduleExists('content_translation') && $this->moduleHandler->invoke('content_translation', 'translate_access', array($comment))->isAllowed()) {
$links['translate'] = array(
'title' => $this->t('Translate'),
'url' => Url::fromRoute('content_translation.translation_overview_comment', ['comment' => $comment->id()], $comment_uri_options + ['query' => $destination]),
'url' => Url::fromRoute('entity.comment.content_translation_overview', ['comment' => $comment->id()], $comment_uri_options + ['query' => $destination]),
);
}
$options[$comment->id()]['operations']['data'] = array(
......
......@@ -108,7 +108,7 @@ public function testCommentTypeEditing() {
$this->drupalGet('admin/structure/comment');
$this->assertRaw('Bar', 'New name was displayed.');
$this->clickLink('Manage fields');
$this->assertUrl(\Drupal::url('field_ui.overview_comment', array('comment_type' => 'comment'), array('absolute' => TRUE)), [], 'Original machine name was used in URL.');
$this->assertUrl(\Drupal::url('entity.comment_type.field_ui_fields', ['comment_type' => 'comment'], ['absolute' => TRUE]), [], 'Original machine name was used in URL.');
$this->assertTrue($this->cssSelect('tr#comment-body'), 'Body field exists.');
// Remove the body field.
......
......@@ -50,8 +50,8 @@ function config_test_entity_type_alter(array &$entity_types) {
// Create a clone of config_test that does not have a status.
$entity_types['config_test_no_status'] = clone $entity_types['config_test'];
$config_test_no_status = &$entity_types['config_test_no_status'];
$config_test_no_status->setLinkTemplate('edit-form', 'entity.config_test.edit_form_config_test_no_status');
$config_test_no_status->setLinkTemplate('delete-form', 'entity.config_test.delete_form_config_test_no_status');
$config_test_no_status->setLinkTemplate('edit-form', '/admin/structure/config_test/manage/{config_test_no_status}');
$config_test_no_status->setLinkTemplate('delete-form', '/admin/structure/config_test/manage/{config_test_no_status}/delete');
$keys = $config_test_no_status->getKeys();
unset($keys['status']);
......
......@@ -34,10 +34,10 @@
* "status" = "status"
* },
* links = {
* "edit-form" = "entity.config_test.edit_form",
* "delete-form" = "entity.config_test.delete_form",
* "enable" = "entity.config_test.enable",
* "disable" = "entity.config_test.disable"
* "edit-form" = "/admin/structure/config_test/manage/{config_test}",
* "delete-form" = "/admin/structure/config_test/manage/{config_test}/delete",
* "enable" = "/admin/structure/config_test/manage/{config_test}/enable",
* "disable" = "/admin/structure/config_test/manage/{config_test}/disable"
* }
* )
*/
......
......@@ -36,13 +36,13 @@ function hook_config_translation_info(&$info) {
$route_provider = \Drupal::service('router.route_provider');
// If field UI is not enabled, the base routes of the type
// "field_ui.field_edit_$entity_type" are not defined.
// "entity.field_config.{$entity_type}_field_edit_form" are not defined.
if (\Drupal::moduleHandler()->moduleExists('field_ui')) {
// Add fields entity mappers to all fieldable entity types defined.
foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
$base_route = NULL;
try {
$base_route = $route_provider->getRouteByName('field_ui.field_edit_' . $entity_type_id);
$base_route = $route_provider->getRouteByName('entity.field_config.' . $entity_type_id . '_field_edit_form');
}
catch (RouteNotFoundException $e) {
// Ignore non-existent routes.
......@@ -51,7 +51,7 @@ function hook_config_translation_info(&$info) {
// Make sure entity type has field UI enabled and has a base route.
if ($entity_type->get('field_ui_base_route') && !empty($base_route)) {
$info[$entity_type_id . '_fields'] = array(
'base_route_name' => 'field_ui.field_edit_' . $entity_type_id,
'base_route_name' => 'entity.field_config.' . $entity_type_id . '_field_edit_form',
'entity_type' => 'field_config',
'title' => t('!label field'),
'class' => '\Drupal\config_translation\ConfigFieldMapper',
......
......@@ -8,6 +8,7 @@
use Drupal\config_translation\Plugin\Derivative\ConfigTranslationLocalTasks;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\field\FieldConfigInterface;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
/**
......@@ -83,7 +84,7 @@ function config_translation_entity_type_alter(array &$entity_types) {
elseif ($entity_type_id == 'field_config') {
$class = 'Drupal\config_translation\Controller\ConfigTranslationFieldListBuilder';
// Will be filled in dynamically, see \Drupal\field\Entity\FieldConfig::linkTemplates().
$entity_type->setLinkTemplate('drupal:config-translation-overview', 'config_translation.item.overview.');
$entity_type->setLinkTemplate('config-translation-overview', $entity_type->getLinkTemplate('edit-form') . '/translate');
}
else {
$class = 'Drupal\config_translation\Controller\ConfigTranslationEntityListBuilder';
......@@ -91,7 +92,7 @@ function config_translation_entity_type_alter(array &$entity_types) {
$entity_type->setHandlerClass('config_translation_list', $class);
if ($entity_type->hasLinkTemplate('edit-form')) {
$entity_type->setLinkTemplate('drupal:config-translation-overview', 'config_translation.item.overview.' . $entity_type->getLinkTemplate('edit-form'));
$entity_type->setLinkTemplate('config-translation-overview', $entity_type->getLinkTemplate('edit-form') . '/translate');
}
}
}
......@@ -105,14 +106,14 @@ function config_translation_config_translation_info(&$info) {
$route_provider = \Drupal::service('router.route_provider');
// If field UI is not enabled, the base routes of the type
// "field_ui.field_edit_$entity_type" are not defined.
// "entity.field_config.{$entity_type}_field_edit_form" are not defined.
if (\Drupal::moduleHandler()->moduleExists('field_ui')) {
// Add fields entity mappers to all fieldable entity types defined.
foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
// Make sure entity type has field UI enabled and has a base route.
if ($entity_type->get('field_ui_base_route')) {
$info[$entity_type_id . '_fields'] = array(
'base_route_name' => 'field_ui.field_edit_' . $entity_type_id,
'base_route_name' => "entity.field_config.{$entity_type_id}_field_edit_form",
'entity_type' => 'field_config',
'title' => '!label field',
'class' => '\Drupal\config_translation\ConfigFieldMapper',
......@@ -139,9 +140,10 @@ function config_translation_config_translation_info(&$info) {
}
// Use the entity type as the plugin ID.
$base_route_name = "entity.$entity_type_id.edit_form";
$info[$entity_type_id] = array(
'class' => '\Drupal\config_translation\ConfigEntityMapper',
'base_route_name' => $entity_type->getLinkTemplate('edit-form'),
'base_route_name' => $base_route_name,
'title' => '!label !entity_type',
'names' => array(),
'entity_type' => $entity_type_id,
......@@ -157,12 +159,18 @@ function config_translation_entity_operation(EntityInterface $entity) {
$operations = array();
$entity_type = $entity->getEntityType();
if ($entity_type->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface') &&
$entity->hasLinkTemplate('drupal:config-translation-overview') &&
$entity->hasLinkTemplate('config-translation-overview') &&
\Drupal::currentUser()->hasPermission('translate configuration')) {
$link_template = 'config-translation-overview';
if ($entity instanceof FieldConfigInterface) {
$link_template = "config-translation-overview.{$entity->getTargetEntityTypeId()}";
}
$operations['translate'] = array(
'title' => t('Translate'),
'weight' => 50,
'url' => $entity->urlInfo('drupal:config-translation-overview'),
'url' => $entity->urlInfo($link_template),
);
}
......
......@@ -242,6 +242,13 @@ public function getContextualLinkGroup() {
}
}
/**
* {@inheritdoc}
*/
public function getOverviewRouteName() {
return 'entity.' . $this->entityType . '.config_translation_overview';
}
/**
* {@inheritdoc}
*/
......
......@@ -34,6 +34,13 @@ public function getBaseRouteParameters() {
return $parameters;
}
/**
* {@inheritdoc}
*/
public function getOverviewRouteName() {
return 'entity.field_config.config_translation_overview.' . $this->pluginDefinition['base_entity_type'];
}
/**
* {@inheritdoc}
*/
......
......@@ -43,7 +43,7 @@ function contact_help($route_name, RouteMatchInterface $route_match) {
*/
function contact_entity_type_alter(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_types['user']->setLinkTemplate('contact-form', 'entity.user.contact_form');
$entity_types['user']->setLinkTemplate('contact-form', '/user/{user}/contact');
}
/**
......
......@@ -34,8 +34,8 @@
* "label" = "label"
* },
* links = {
* "delete-form" = "entity.contact_form.delete_form",
* "edit-form" = "entity.contact_form.edit_form"
* "delete-form" = "/admin/structure/contact/manage/{contact_form}/delete",
* "edit-form" = "/admin/structure/contact/manage/{contact_form}"
* }
* )
*/
......
......@@ -114,7 +114,7 @@ function content_translation_entity_type_alter(array &$entity_types) {
if ($entity_type->hasLinkTemplate('canonical')) {
// Provide default route names for the translation paths.
if (!$entity_type->hasLinkTemplate('drupal:content-translation-overview')) {
$entity_type->setLinkTemplate('drupal:content-translation-overview', "content_translation.translation_overview_" . $entity_type->id());
$entity_type->setLinkTemplate('drupal:content-translation-overview', $entity_type->getLinkTemplate('canonical') . '/translations');
}
// @todo Remove this as soon as menu access checks rely on the
// controller. See https://drupal.org/node/2155787.
......
......@@ -53,7 +53,7 @@ public function getDerivativeDefinitions($base_plugin_definition) {
// Create contextual links for translatable entity types.
foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
$this->derivatives[$entity_type_id]['title'] = t('Translate');
$this->derivatives[$entity_type_id]['route_name'] = $entity_type->getLinkTemplate('drupal:content-translation-overview');
$this->derivatives[$entity_type_id]['route_name'] = "entity.$entity_type_id.content_translation_overview";
$this->derivatives[$entity_type_id]['group'] = $entity_type_id;
}
return parent::getDerivativeDefinitions($base_plugin_definition);
......
......@@ -61,13 +61,14 @@ public function getDerivativeDefinitions($base_plugin_definition) {
// Create tabs for all possible entity types.
foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
// Find the route name for the translation overview.
$translation_route_name = $entity_type->getLinkTemplate('drupal:content-translation-overview');
$translation_route_name = "entity.$entity_type_id.content_translation_overview";
$base_route_name = "entity.$entity_type_id.canonical";
$this->derivatives[$translation_route_name] = array(
'entity_type' => $entity_type_id,
'title' => 'Translate',
'route_name' => $translation_route_name,
'base_route' => $entity_type->getLinkTemplate('canonical'),
'base_route' => $base_route_name,
) + $base_plugin_definition;
}
return parent::getDerivativeDefinitions($base_plugin_definition);
......
......@@ -42,17 +42,26 @@ public function __construct(ContentTranslationManagerInterface $content_translat
protected function alterRoutes(RouteCollection $collection) {
foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
// Try to get the route from the current collection.
if (!$entity_route = $collection->get($entity_type->getLinkTemplate('canonical'))) {
continue;
$link_template = $entity_type->getLinkTemplate('canonical');
if (strpos($link_template, '/') !== FALSE) {
$base_path = '/' . $link_template;
}
else {
if (!$entity_route = $collection->get("entity.$entity_type_id.canonical")) {
continue;
}
$base_path = $entity_route->getPath();
}
$path = $entity_route->getPath() . '/translations';
// Inherit admin route status from edit route, if exists.
$is_admin = FALSE;
if ($edit_route = $collection->get($entity_type->getLinkTemplate('edit-form'))) {
$route_name = "entity.$entity_type_id.edit_form";
if ($edit_route = $collection->get($route_name)) {
$is_admin = (bool) $edit_route->getOption('_admin_route');
}
$path = $base_path . '/translations';
$route = new Route(
$path,
array(
......@@ -71,7 +80,8 @@ protected function alterRoutes(RouteCollection $collection) {
'_admin_route' => $is_admin,
)
);
$collection->add($entity_type->getLinkTemplate('drupal:content-translation-overview'), $route);
$route_name = "entity.$entity_type_id.content_translation_overview";
$collection->add($route_name, $route);
$route = new Route(
$path . '/add/{source}/{target}',
......
......@@ -62,6 +62,7 @@ protected function setupEntity() {
// Create a translation.
$this->drupalLogin($this->translator);
$path = $this->entity->getSystemPath('drupal:content-translation-overview');
$add_translation_path = $path . "/add/$default_langcode/{$this->langcodes[2]}";
$this->drupalPostForm($add_translation_path, array(), t('Save'));
$this->rebuildContainer();
......
......@@ -28,7 +28,7 @@ protected function setUp() {
->method('getLinkTemplate')
->will($this->returnValueMap(array(
array('canonical', 'entity.node.canonical'),
array('drupal:content-translation-overview', 'content_translation.translation_overview_node'),
array('drupal:content-translation-overview', 'entity.node.content_translation_overview'),
)));
$content_translation_manager = $this->getMock('Drupal\content_translation\ContentTranslationManagerInterface');
$content_translation_manager->expects($this->any())
......@@ -54,14 +54,14 @@ public function testBlockAdminDisplay($route, $expected) {
public function providerTestBlockAdminDisplay() {
return array(
array('entity.node.canonical', array(array(
'content_translation.local_tasks:content_translation.translation_overview_node',
'content_translation.local_tasks:entity.node.content_translation_overview',
'entity.node.canonical',
'entity.node.edit_form',
'entity.node.delete_form',
'entity.node.version_history',
))),
array('content_translation.translation_overview_node', array(array(
'content_translation.local_tasks:content_translation.translation_overview_node',
array('entity.node.content_translation_overview', array(array(
'content_translation.local_tasks:entity.node.content_translation_overview',
'entity.node.canonical',
'entity.node.edit_form',
'entity.node.delete_form',
......
......@@ -261,12 +261,12 @@ public static function postDelete(EntityStorageInterface $storage, array $fields
protected function linkTemplates() {
$link_templates = parent::linkTemplates();
if (\Drupal::moduleHandler()->moduleExists('field_ui')) {
$link_templates['edit-form'] = 'field_ui.field_edit_' . $this->entity_type;
$link_templates['storage-edit-form'] = 'field_ui.storage_edit_' . $this->entity_type;
$link_templates['delete-form'] = 'field_ui.delete_' . $this->entity_type;
$link_templates["{$this->entity_type}-field-edit-form"] = 'entity.field_config.' . $this->entity_type . '_field_edit_form';
$link_templates["{$this->entity_type}-storage-edit-form"] = 'entity.field_config.' . $this->entity_type . '_storage_edit_form';
$link_templates["{$this->entity_type}-field-delete-form"] = 'entity.field_config.' . $this->entity_type . '_field_delete_form';
if (isset($link_templates['drupal:config-translation-overview'])) {
$link_templates['drupal:config-translation-overview'] .= $link_templates['edit-form'];
if (isset($link_templates['config-translation-overview'])) {
$link_templates["config-translation-overview.{$this->entity_type}"] = "entity.field_config.config_translation_overview.{$this->entity_type}";
}
}
return $link_templates;
......
......@@ -51,7 +51,7 @@ function field_ui_help($route_name, RouteMatchInterface $route_match) {
$output .= '<dd>' . t('Fields on taxonomy terms are defined at the taxonomy vocabulary level, on the <em>Manage fields</em> tab of the vocabulary edit page (which you can reach from the <a href="@taxonomy">Taxonomy page</a>). When you define a field for a vocabulary, each term in that vocabulary will have that field added to it. For example, you could define an image field for a vocabulary to store an icon with each term.', array('@taxonomy' => \Drupal::url('taxonomy.vocabulary_list'))) . '</dd>';
}
$output .= '<dt>' . t('Fields on user accounts') . '</dt>';
$output .= '<dd>' . t('Fields on user accounts are defined on a site-wide basis on the <a href="@fields">Manage fields tab</a> of the <a href="@accounts">Account settings</a> page. When you define a field for user accounts, each user account will have that field added to it. For example, you could add a long text field to allow users to include a biography.', array('@fields' => \Drupal::url('field_ui.overview_user'), '@accounts' => \Drupal::url('entity.user.admin_form'))) . '</dd>';
$output .= '<dd>' . t('Fields on user accounts are defined on a site-wide basis on the <a href="@fields">Manage fields tab</a> of the <a href="@accounts">Account settings</a> page. When you define a field for user accounts, each user account will have that field added to it. For example, you could add a long text field to allow users to include a biography.', array('@fields' => \Drupal::url('entity.user.field_ui_fields'), '@accounts' => \Drupal::url('entity.user.admin_form'))) . '</dd>';
if ($module_handler->moduleExists('comment')) {
$output .= '<dt>' . t('Fields on comments') . '</dt>';
$output .= '<dd>' . t('Fields on comments are defined at the comment entity level, on the <em>Manage fields</em> tab of the comment types edit page (which you can reach from the <a href="@types">Comment types page</a>). When you add a field for comments, each comment on an entity with that comment type will have that field added to it. For example, you could add a website field to the comments on forum posts, to allow forum commenters to add a link to their website.', array('@types' => \Drupal::url('comment.type_list'))) . '</dd>';
......@@ -91,10 +91,14 @@ function field_ui_entity_type_build(array &$entity_types) {
foreach ($entity_types as $entity_type) {
if ($bundle = $entity_type->getBundleOf()) {
// To generate links in the UI we use the route names, so we don't have to
// know the exact required routes.
// This allows us to not require route information inside this hook, which
// otherwise could result in circular dependencies.
$entity_type
->setLinkTemplate('field_ui-fields', "field_ui.overview_$bundle")
->setLinkTemplate('field_ui-form-display', "field_ui.form_display_overview_$bundle")
->setLinkTemplate('field_ui-display', "field_ui.display_overview_$bundle");
->setLinkTemplate('field_ui-fields', "/admin/{$entity_type->id()}/fields")
->setLinkTemplate('field_ui-form-display', "/admin/{$entity_type->id()}/fields-form-display")
->setLinkTemplate('field_ui-display', "/admin/{$entity_type->id()}/fields-display");
}
}
}
......@@ -300,8 +304,8 @@ function field_ui_entity_type_alter(array &$entity_types) {
$form_mode->setFormClass('edit', 'Drupal\field_ui\Form\EntityDisplayModeEditForm');
$form_mode->setFormClass('delete', 'Drupal\field_ui\Form\EntityDisplayModeDeleteForm');
$form_mode->set('admin_permission', 'administer display modes');
$form_mode->setLinkTemplate('delete-form', 'field_ui.entity_form_mode.delete_form');
$form_mode->setLinkTemplate('edit-form', 'field_ui.entity_form_mode.edit_form');
$form_mode->setLinkTemplate('delete-form', '/admin/structure/display-modes/form/manage/{entity_form_mode}/delete');
$form_mode->setLinkTemplate('edit-form', '/admin/structure/display-modes/form/manage/{entity_form_mode}');
$view_mode = $entity_types['entity_view_mode'];
$view_mode->setListBuilderClass('Drupal\field_ui\EntityDisplayModeListBuilder');
......@@ -309,6 +313,6 @@ function field_ui_entity_type_alter(array &$entity_types) {
$view_mode->setFormClass('edit', 'Drupal\field_ui\Form\EntityDisplayModeEditForm');
$view_mode->setFormClass('delete', 'Drupal\field_ui\Form\EntityDisplayModeDeleteForm');
$view_mode->set('admin_permission', 'administer display modes');
$view_mode->setLinkTemplate('delete-form', 'field_ui.entity_view_mode.delete_form');
$view_mode->setLinkTemplate('edit-form', 'field_ui.entity_view_mode.edit_form');
$view_mode->setLinkTemplate('delete-form', '/admin/structure/display-modes/view/manage/{entity_view_mode}/delete');
$view_mode->setLinkTemplate('edit-form', '/admin/structure/display-modes/view/manage/{entity_view_mode}');
}
......@@ -38,7 +38,7 @@ field_ui.entity_view_mode_add_type:
requirements:
_permission: 'administer display modes'
field_ui.entity_view_mode.edit_form:
entity.entity_view_mode.edit_form:
path: '/admin/structure/display-modes/view/manage/{entity_view_mode}'
defaults:
_entity_form: 'entity_view_mode.edit'
......@@ -46,7 +46,7 @@ field_ui.entity_view_mode.edit_form:
requirements:
_entity_access: 'entity_view_mode.update'
field_ui.entity_view_mode.delete_form:
entity.entity_view_mode.delete_form:
path: '/admin/structure/display-modes/view/manage/{entity_view_mode}/delete'
defaults:
_entity_form: 'entity_view_mode.delete'
......@@ -78,7 +78,7 @@ field_ui.entity_form_mode_add_type:
requirements:
_permission: 'administer display modes'
field_ui.entity_form_mode.edit_form:
entity.entity_form_mode.edit_form:
path: '/admin/structure/display-modes/form/manage/{entity_form_mode}'
defaults:
_entity_form: 'entity_form_mode.edit'
......@@ -86,7 +86,7 @@ field_ui.entity_form_mode.edit_form:
requirements:
_entity_access: 'entity_form_mode.update'
field_ui.entity_form_mode.delete_form:
entity.entity_form_mode.delete_form:
path: '/admin/structure/display-modes/form/manage/{entity_form_mode}/delete'
defaults:
_entity_form: 'entity_form_mode.delete'
......
......@@ -203,7 +203,9 @@ protected function getTableHeader() {
* {@inheritdoc}
*/
protected function getOverviewRoute($mode) {
return Url::fromRoute('field_ui.display_overview_view_mode_' . $this->entity_type, [
$entity_type = $this->entityManager->getDefinition($this->entity_type);
$field_entity_type = $entity_type->getBundleEntityType() != 'bundle'? $entity_type->getBundleEntityType() : $entity_type->id();
return Url::fromRoute('field_ui.display_overview_view_mode_' . $field_entity_type, [
$this->bundleEntityTypeId => $this->bundle,
'view_mode_name' => $mode,
]);
......
......@@ -139,7 +139,7 @@ public function buildRow(EntityInterface $field_config) {
'data' => array(
'#type' => 'link',
'#title' => $this->fieldTypeManager->getDefinitions()[$field_storage->getType()]['label'],
'#url' => Url::fromRoute('field_ui.storage_edit_' . $this->targetEntityTypeId, $route_parameters),
'#url' => Url::fromRoute("entity.field_config.{$this->targetEntityTypeId}_storage_edit_form", $route_parameters),
'#options' => array('attributes' => array('title' => $this->t('Edit field settings.'))),
),
),
......@@ -164,11 +164,24 @@ public function getDefaultOperations(EntityInterface $entity) {
/** @var \Drupal\field\FieldConfigInterface $entity */
$operations = parent::getDefaultOperations($entity);
if ($entity->access('update') && $entity->hasLinkTemplate("{$entity->entity_type}-field-edit-form")) {
$operations['edit'] = array(
'title' => $this->t('Edit'),
'weight' => 10,
) + $entity->urlInfo("{$entity->entity_type}-field-edit-form")->toArray();
}
if ($entity->access('delete') && $entity->hasLinkTemplate("{$entity->entity_type}-field-delete-form")) {
$operations['delete'] = array(
'title' => $this->t('Delete'),
'weight' => 100,
) + $entity->urlInfo("{$entity->entity_type}-field-delete-form")->toArray();
}
$operations['storage-settings'] = array(
'title' => $this->t('Storage settings'),
'weight' => 20,
'attributes' => array('title' => $this->t('Edit storage settings.')),
'url' => $entity->urlInfo('storage-edit-form'),
'url' => $entity->urlInfo("{$entity->entity_type}-storage-edit-form"),
);
$operations['edit']['attributes']['title'] = $this->t('Edit field settings.');
$operations['delete']['attributes']['title'] = $this->t('Delete field.');
......
......@@ -8,6 +8,7 @@
namespace Drupal\field_ui;