Skip to content
Snippets Groups Projects

Issue #2265487: ConfigEntity based lists with items containing non-ascii...

Open Issue #2265487: ConfigEntity based lists with items containing non-ascii...
2 unresolved threads
Open sleitner requested to merge issue/drupal-2265487:2265487-configentity-based-lists into 11.x
2 unresolved threads

Issue #2265487: ConfigEntity based lists with items containing non-ascii characters are not sorted correctly

Closes #2265487

Merge request reports

Members who can merge are allowed to add commits.
Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Adam Bramley
  • 239 $collator = \Collator::create((!extension_loaded('intl')) ? ('en') : (\Drupal::service('language_manager')->getCurrentLanguage()->getId()));
    240 return uasort($entities, function ($a, $b) use ($collator) {
    241 return static::compare($a, $b, $collator);
    242 });
    243 }
    244
    245 /**
    246 * Callback for uasort() to compare configuration entities.
    247 */
    248 public static function compare(ConfigEntityInterface $a, ConfigEntityInterface $b, \Collator $collator): int {
    249 $a_weight = $a->weight ?? 0;
    250 $b_weight = $b->weight ?? 0;
    251 if ($a_weight == $b_weight) {
    252 $a_label = $a->label() ?? '';
    253 $b_label = $b->label() ?? '';
    254 if (!extension_loaded('intl')) {
  • sleitner added 7 commits

    added 7 commits

    Compare with previous version

  • sleitner added 1 commit

    added 1 commit

    • 1d09c674 - Comment on hardcoded language en

    Compare with previous version

  • sleitner added 1 commit

    added 1 commit

    Compare with previous version

  • sleitner added 1 commit

    added 1 commit

    Compare with previous version

  • sleitner added 1 commit

    added 1 commit

    Compare with previous version

  • sleitner added 1 commit

    added 1 commit

    • 3ede1de7 - readd sortEntities with comment

    Compare with previous version

  • sleitner added 1 commit

    added 1 commit

    Compare with previous version

  • sleitner added 1 commit

    added 1 commit

    Compare with previous version

  • 259 }
    260 return $collator->compare($a_label, $b_label);
    261 }
    262 return $a_weight <=> $b_weight;
    263 }
    264
    235 265 /**
    236 266 * Callback for uasort() to sort configuration entities by weight and label.
    267 *
    268 * @deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use
    269 * \Drupal\Core\Config\Entity\ConfigEntityBase::sortEntities() instead.
    270 *
    271 * @see https://www.drupal.org/project/drupal/issues/2265487
    237 272 */
    238 273 public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
    274 @trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use ' . __CLASS__ . '::sortEntities() instead. See https://www.drupal.org/project/drupal/issues/2265487', E_USER_DEPRECATED);
    • If we move the Collator creation to this method, we don't need to deprecate anything nor add a new API? I'm fine having public static function sortEntities(array &$entities) as an API addition for adding consistency, but not sure why we can't just keep using this method.

    • The idea of doing everything in sort() was criticized due to poor performance caused by too many service calls in the sort function, when hundreds of items are sort, see #31, #65 and #67.

      Edited by sleitner
    • Please register or sign in to reply
  • sleitner added 34 commits

    added 34 commits

    Compare with previous version

  • sleitner added 28 commits

    added 28 commits

    Compare with previous version

  • Please register or sign in to reply
    Loading