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.

Members fund testing for the Drupal project. Drupal Association Learn more

Comments

joachim created an issue. See original summary.

prics’s picture

Assigned: Unassigned » prics
Issue tags: +DCTransylvania
joachim’s picture

Very odd, this is working for me now.

Anyone else able to reproduce this?

prics’s picture

Assigned: prics » Unassigned

This is still the case for me, but was not able to work on it.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

yoroy’s picture

Running into this in another part of this list. I missed the "Date range" field because it was not right below "Date".

nesta_’s picture

Issue tags: +DevDaysSeville
aj2r’s picture

Assigned: Unassigned » aj2r
aj2r’s picture

Assigned: aj2r » Unassigned
Status: Active » Closed (cannot reproduce)
FileSize
67.61 KB

Hi, I cannot reproduce. It's OK for me in 8.4.x.

Issue is OK in 8.4.x

yoroy’s picture

Status: Closed (cannot reproduce) » Active

Did 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?

aj2r’s picture

Assigned: Unassigned » aj2r
aj2r’s picture

Assigned: aj2r » Unassigned
Status: Active » Closed (cannot reproduce)
FileSize
58.78 KB

@yoroy, yep, It's OK with Date range enabled:

2701867-13 OK

_Archy_’s picture

Issue tags: -DCTransylvania
mpdonadio’s picture

If this is CNR, what issue fixed it?

mpdonadio’s picture

Status: Closed (cannot reproduce) » Active
Issue tags: +Needs tests, +PHP 7
FileSize
73.13 KB

Fresh 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.

mpdonadio’s picture

A little crude, but passes locally with PHP 5.6 and fails in PHP 7.0.

mpdonadio’s picture

o.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.

mpdonadio’s picture

This 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.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.