Sort bundle labels in Field list report

Created on 6 September 2017, over 7 years ago
Updated 24 September 2024, 3 months ago

Problem/Motivation

If you go to the Field List page (admin/reports/fields) you will see that the USED IN column don't have the bundles labels in alphabetical order, so sometimes is a little difficult to find an information if we have a field shared between many bundles.

Proposed resolution

Sort the USED IN column using the sort() function.

Remaining tasks

Ensure the patches still apply and reroll (against 11.x) if necessary
Create a change record

User interface changes

The USED IN column will have the bundle labels in an alphabetical order.

API changes

Added function getFieldStorageBundles

Data model changes

None.

๐Ÿ“Œ Task
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component

entity system

Created by

๐Ÿ‡จ๐Ÿ‡ฆCanada adriancid Montreal, Canada

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom rachel_norfolk UK

    Updating remaining tasks.

    Removing Novice tag as it I just a bit of a long issue now.

  • Merge request !9602MR from the Patch โ†’ (Open) created by arunkumark
  • Pipeline finished with Failed
    3 months ago
    Total: 448s
    #292184
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia arunkumark Coimbatore

    Created MR from the patch.

  • Pipeline finished with Success
    3 months ago
    Total: 457s
    #292253
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia arunkumark Coimbatore
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Left some comments on the MR.

    Before moving to review please take a look at the tags. Like the 12th issue today where something was skipped.

  • Pipeline finished with Failed
    3 months ago
    Total: 365s
    #292645
  • Pipeline finished with Failed
    3 months ago
    Total: 8600s
    #292947
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia arunkumark Coimbatore
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Before moving to review please take a look at the tags

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom rachel_norfolk UK

    Just to be absolutely clear, what we are looking for before setting the issue to โ€œNeeds reviewโ€ is a change record. You can read about creating change records at https://www.drupal.org/community/contributor-guide/task/write-a-change-r... โ†’

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia arunkumark Coimbatore

    Created draft Change Request for the Field label sorting.

    https://www.drupal.org/node/3477218 โ†’
    [#3477218]

    Update the Change Request if any corrections are needed.

  • The Needs Review Queue Bot โ†’ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom rachel_norfolk UK

    added some alt text to the draft change record screenshots.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom rachel_norfolk UK

    Removed Needs Change Record tag.

    Ran the MR in simplytest.me and it is applying the sort order to fields, as expected.

    I think we are finally good to go...

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance nod_ Lille

    I think we can make this simpler.

    Adding a sort in \Drupal\Core\Entity\EntityFieldManager::getFieldMap fixes the issue

            // In the second step, the per-bundle fields are added, based on the
            // persistent bundle field map stored in a key value collection. This
            // data is managed in the
            // FieldDefinitionListener::onFieldDefinitionCreate() and
            // FieldDefinitionListener::onFieldDefinitionDelete() methods.
            // Rebuilding this information in the same way as base fields would not
            // scale, as the time to query would grow exponentially with more fields
            // and bundles. A cache would be deleted during cache clears, which is
            // the only time it is needed, so a key value collection is used.
            $bundle_field_maps = $this->keyValueFactory->get('entity.definitions.bundle_field_map')->getAll();
            foreach ($bundle_field_maps as $entity_type_id => $bundle_field_map) {
              foreach ($bundle_field_map as $field_name => $map_entry) {
                // SORT HERE
                ksort($map_entry['bundles']);
                if (!isset($this->fieldMap[$entity_type_id][$field_name])) {
                  $this->fieldMap[$entity_type_id][$field_name] = $map_entry;
                }
                else {
                  $this->fieldMap[$entity_type_id][$field_name]['bundles'] += $map_entry['bundles'];
                }
              }
            }
    

    The result is cached so performance impact should be minimal. If we're worried we can also wrap this in a count() to sort only arrays with more than one item.

    I don't think increasing the API surface for this is worth it.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance nod_ Lille

    oh but that would sort the machine names, not the labels...

Production build 0.71.5 2024