Skip to content
Snippets Groups Projects
Commit 09b7d821 authored by catch's avatar catch
Browse files

Issue #2878211 by mfernea, bnjmnm, Lendude, Anchal_gupta, smustgrave, lauriii:...

Issue #2878211 by mfernea, bnjmnm, Lendude, Anchal_gupta, smustgrave, lauriii: Order local tasks for view modes and form modes on name rather than machine name
parent dc6c95f6
No related branches found
No related tags found
28 merge requests!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!4868Issue #1428520: Improve menu parent link selection,!4289Issue #1344552 by marcingy, Niklas Fiekas, Ravi.J, aleevas, Eduardo Morales...,!4114Issue #2707291: Disable body-level scrolling when a dialog is open as a modal,!4100Issue #3249600: Add support for PHP 8.1 Enums as allowed values for list_* data types,!3630Issue #2815301 by Chi, DanielVeza, kostyashupenko, smustgrave: Allow to create...,!3600Issue #3344629: Passing null to parameter #1 ($haystack) of type string is deprecated,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1591Issue #3199697: Add JSON:API Translation experimental module,!1484Exposed filters get values from URL when Ajax is on,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1162Issue #3100350: Unable to save '/' root path alias,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!925Issue #2339235: Remove taxonomy hard dependency on node module,!877Issue #2708101: Default value for link text is not saved,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!844Resolve #3036010 "Updaters",!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer,!23Issue #2879087: Use comment access handler instead of hardcoding permissions
......@@ -135,8 +135,11 @@ public function getDerivativeDefinitions($base_plugin_definition) {
];
// One local task for each form mode.
$weight = 0;
foreach ($this->entityDisplayRepository->getFormModes($entity_type_id) as $form_mode => $form_mode_info) {
$form_modes = $this->entityDisplayRepository->getFormModes($entity_type_id);
// Sort all form modes by title.
$form_modes_titles = array_values(array_map(fn($item) => (string) $item['label'], $form_modes));
sort($form_modes_titles, SORT_NATURAL);
foreach ($form_modes as $form_mode => $form_mode_info) {
$this->derivatives['field_form_display_' . $form_mode . '_' . $entity_type_id] = [
'title' => $form_mode_info['label'],
'route_name' => "entity.entity_form_display.$entity_type_id.form_mode",
......@@ -144,14 +147,17 @@ public function getDerivativeDefinitions($base_plugin_definition) {
'form_mode_name' => $form_mode,
],
'parent_id' => "field_ui.fields:form_display_overview_$entity_type_id",
'weight' => $weight++,
'weight' => array_flip($form_modes_titles)[(string) $form_mode_info['label']],
'cache_tags' => $this->entityTypeManager->getDefinition('entity_form_display')->getListCacheTags(),
];
}
// One local task for each view mode.
$weight = 0;
foreach ($this->entityDisplayRepository->getViewModes($entity_type_id) as $view_mode => $form_mode_info) {
$view_modes = $this->entityDisplayRepository->getViewModes($entity_type_id);
// Sort all view modes by title.
$view_modes_titles = array_values(array_map(fn($item) => (string) $item['label'], $view_modes));
sort($view_modes_titles, SORT_NATURAL);
foreach ($view_modes as $view_mode => $form_mode_info) {
$this->derivatives['field_display_' . $view_mode . '_' . $entity_type_id] = [
'title' => $form_mode_info['label'],
'route_name' => "entity.entity_view_display.$entity_type_id.view_mode",
......@@ -159,7 +165,7 @@ public function getDerivativeDefinitions($base_plugin_definition) {
'view_mode_name' => $view_mode,
],
'parent_id' => "field_ui.fields:display_overview_$entity_type_id",
'weight' => $weight++,
'weight' => array_flip($view_modes_titles)[(string) $form_mode_info['label']],
'cache_tags' => $this->entityTypeManager->getDefinition('entity_view_display')->getListCacheTags(),
];
}
......
......@@ -2,6 +2,8 @@
namespace Drupal\Tests\field_ui\Functional;
use Behat\Mink\Exception\ExpectationException;
use Drupal\Core\Entity\Entity\EntityFormMode;
use Drupal\Core\Url;
use Behat\Mink\Element\NodeElement;
use Drupal\Core\Entity\EntityInterface;
......@@ -62,6 +64,7 @@ protected function setUp(): void {
$admin_user = $this->drupalCreateUser([
'access content',
'administer content types',
'administer display modes',
'administer node fields',
'administer node form display',
'administer node display',
......@@ -225,6 +228,57 @@ public function testNoFieldsDisplayOverview() {
$this->assertSession()->linkByHrefExists(Url::fromRoute('entity.node.field_ui_fields', ['node_type' => 'no_fields'])->toString());
}
/**
* Tests if display mode local tasks appear in alphabetical order by label.
*/
public function testViewModeLocalTasksOrder() {
$manage_display = 'admin/structure/types/manage/' . $this->type . '/display';
// Specify the 'rss' mode, check that the field is displayed the same.
$edit = [
'display_modes_custom[rss]' => TRUE,
'display_modes_custom[teaser]' => TRUE,
];
$this->drupalGet($manage_display);
$this->submitForm($edit, 'Save');
$this->assertOrderInPage(['RSS', 'Teaser']);
$edit = [
'label' => 'Breezer',
];
$this->drupalGet('admin/structure/display-modes/view/manage/node.teaser');
$this->submitForm($edit, 'Save');
$this->assertOrderInPage(['Breezer', 'RSS']);
}
/**
* Tests if form mode local tasks appear in alphabetical order by label.
*/
public function testFormModeLocalTasksOrder() {
EntityFormMode::create([
'id' => 'node.big',
'label' => 'Big Form',
'targetEntityType' => 'node',
])->save();
EntityFormMode::create([
'id' => 'node.little',
'label' => 'Little Form',
'targetEntityType' => 'node',
])->save();
$manage_form = 'admin/structure/types/manage/' . $this->type . '/form-display';
$this->drupalGet($manage_form);
$this->assertOrderInPage(['Big Form', 'Little Form']);
$edit = [
'label' => 'Ultimate Form',
];
$this->drupalGet('admin/structure/display-modes/form/manage/node.big');
$this->submitForm($edit, 'Save');
$this->drupalGet($manage_form);
$this->assertOrderInPage(['Little Form', 'Ultimate Form']);
}
/**
* Asserts that a string is found in the rendered node in a view mode.
*
......@@ -351,4 +405,34 @@ protected function getAllOptionsList(NodeElement $element) {
return $options;
}
/**
* Asserts that several pieces of markup are in a given order in the page.
*
* @param string[] $items
* An ordered list of strings.
*
* @throws \Behat\Mink\Exception\ExpectationException
* When any of the given string is not found.
*
* @internal
*
* @todo Remove this once https://www.drupal.org/node/2817657 is committed.
*/
protected function assertOrderInPage(array $items): void {
$session = $this->getSession();
$text = $session->getPage()->getHtml();
$strings = [];
foreach ($items as $item) {
if (($pos = strpos($text, $item)) === FALSE) {
throw new ExpectationException("Cannot find '$item' in the page", $session->getDriver());
}
$strings[$pos] = $item;
}
ksort($strings);
$ordered = implode(', ', array_map(function ($item) {
return "'$item'";
}, $items));
$this->assertSame($items, array_values($strings), "Found strings, ordered as: $ordered.");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment