Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The text field types are not in the correct order.
The code responsible for this is this in CategorizingPluginManagerTrait:
public function getSortedDefinitions(array $definitions = NULL, $label_key = 'label') {
// Sort the plugins first by category, then by label.
/** @var \Drupal\Core\Plugin\CategorizingPluginManagerTrait|\Drupal\Component\Plugin\PluginManagerInterface $this */
$definitions = isset($definitions) ? $definitions : $this->getDefinitions();
uasort($definitions, function ($a, $b) use ($label_key) {
if ($a['category'] != $b['category']) {
return strnatcasecmp($a['category'], $b['category']);
}
return strnatcasecmp($a[$label_key], $b[$label_key]);
});
return $definitions;
}
I've not yet managed to figure out why the sorting is incorrect.
Comment | File | Size | Author |
---|---|---|---|
#28 | FieldList_1.png | 38.92 KB | quietone |
#28 | FieldList_0.png | 33.66 KB | quietone |
#17 | 2701867-test-only.patch | 1.71 KB | mpdonadio |
#16 | Screen Shot 2017-07-07 at 5.36.32 PM.png | 73.13 KB | mpdonadio |
#13 | 2701867-13.png | 58.78 KB | aj2r |
Comments
Comment #2
rosinegrean CreditAttribution: rosinegrean at PitechPlus commentedComment #3
joachim CreditAttribution: joachim commentedVery odd, this is working for me now.
Anyone else able to reproduce this?
Comment #4
rosinegrean CreditAttribution: rosinegrean at PitechPlus commentedThis is still the case for me, but was not able to work on it.
Comment #7
yoroy CreditAttribution: yoroy at Roy Scholten commentedRunning into this in another part of this list. I missed the "Date range" field because it was not right below "Date".
Comment #8
nesta_ CreditAttribution: nesta_ at La Drupalera by Emergya for La Drupalera by Emergya commentedComment #9
aj2r CreditAttribution: aj2r at La Drupalera by Emergya commentedComment #10
aj2r CreditAttribution: aj2r at La Drupalera by Emergya commentedHi, I cannot reproduce. It's OK for me in 8.4.x.
Comment #11
yoroy CreditAttribution: yoroy at Roy Scholten commentedDid you check the top "General" section?
There's a specific case I'd like to see work better:
- Enable daterange experimental module
- Add a daterange field to a content type: where is daterange listed within the "General" section?
Comment #12
aj2r CreditAttribution: aj2r at La Drupalera by Emergya commentedComment #13
aj2r CreditAttribution: aj2r at La Drupalera by Emergya commented@yoroy, yep, It's OK with Date range enabled:
Comment #14
_Archy_ CreditAttribution: _Archy_ at PitechPlus commentedComment #15
mpdonadioIf this is CNR, what issue fixed it?
Comment #16
mpdonadioFresh install of 8.4.x w/ datetime_range installed from drush and UI:
However, this only happens when I am on PHP 7.0. With PHP 5.6, the sort order is correct.
Comment #17
mpdonadioA little crude, but passes locally with PHP 5.6 and fails in PHP 7.0.
Comment #18
mpdonadioo.O
Test is in https://dispatcher.drupalci.org/job/drupal_patches/21376/consoleFull showing a pass
But locally (PHP from my MAMP).
$ ../vendor/bin/phpunit --debug --verbose ../core/tests/Drupal/FunctionalTests/Field/FieldTypeSortTest.php
PHPUnit 4.8.35 by Sebastian Bergmann and contributors.
Runtime: PHP 7.0.12
Configuration: /Users/matt/Documents/PhpStorm/drupal-8.4.x/core/phpunit.xml
Starting test 'Drupal\FunctionalTests\Field\FieldTypeSortTest::testSortOrder'.
F
Time: 12.84 seconds, Memory: 6.00MB
There was 1 failure:
1) Drupal\FunctionalTests\Field\FieldTypeSortTest::testSortOrder
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
- 0 => 'Boolean'
- 1 => 'Comments'
+ 0 => 'Comments'
+ 1 => 'Boolean'
2 => 'Date'
- 3 => 'Date range'
+ 3 => 'Timestamp'
4 => 'Email'
- 5 => 'Link'
- 6 => 'Timestamp'
+ 5 => 'Date range'
+ 6 => 'Link'
)
/Users/matt/Documents/PhpStorm/drupal-8.4.x/core/tests/Drupal/Tests/BrowserTestBase.php:1366
/Users/matt/Documents/PhpStorm/drupal-8.4.x/core/tests/Drupal/FunctionalTests/Field/FieldTypeSortTest.php:52
FAILURES!
Tests: 1, Assertions: 7, Failures: 1.
Comment #19
mpdonadioThis is a wild theory, but I am wondering if CategorizingPluginManagerTrait::getSortedDefinitions() isn't running in some instances, and we are accidentally getting alphabetical results. I have seen similar things happen because of a filesystem quirk.
I forget the precise details, but the problem happens when files are written out in a different order on different system. When the system scans the directory, it picks them up in inode order. So, if a git clone is writing everything out alphabetically, then it will be read back that way. Locally, I have had this 8.4.x clone for ages, so file order b/c pulls may be different.
I'll test this out later with a fresh clone, just like testbot would.
Comment #28
quietone CreditAttribution: quietone as a volunteer commentedI tested this on 9.3.x and was not able to reproduce this error, see screenshots.
Therefore, closing as cannot reproduce. If you are experiencing this problem reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core").