Hello,

I have an annoying warning in Features UI.

Warning: uasort(): Array was modified by the user comparison function in Drupal\features\FeaturesManager->listConfigTypes() (line 942 of modules/contrib/features/src/FeaturesManager.php).

I found that $definition->getLabel() returns a TranslatableMarkup object so the call to uasort($entity_types, 'strnatcasecmp') triggers warning.

$definition->getLabel()->render()

Fix the problem.

I will attach a patch.

Comments

Grimreaper created an issue. See original summary.

grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Active » Needs review
StatusFileSize
new914 bytes

Here is the patch.

Thanks for the review.

grimreaper’s picture

StatusFileSize
new1.97 KB

I have found other places where ->render() is required to avoid the warning.

nedjo’s picture

Status: Needs review » Reviewed & tested by the community

Looks right to me.

  • mpotter committed f12924a on 8.x-3.x authored by Grimreaper
    Issue #2672470 by Grimreaper: Warning uasort in Features UI
    
mpotter’s picture

Status: Reviewed & tested by the community » Fixed

Committed to ceb2f3f.

grimreaper’s picture

Thanks!

  • mpotter committed 6d23d8e on 8.x-3.x
    Revert "Issue #2672470 by Grimreaper: Warning uasort in Features UI"...
mpotter’s picture

Status: Fixed » Needs work

Actually, needed to revert this patch because it caused the error in #2745287: Features UI Error: Call to a member function render() on string in Drupal\features\FeaturesManager. Also, when this patch is applied, expanding the details of the features in the main listing page shows empty component categories.

Certainly the addition of ->render() to the EntityTypeInterface->getLabel in FeaturesManager is incorrect because looking at the documentation for that, getLabel returns a string not a render array.

It's possible there were core changes since the original patch was created.

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new2.45 KB

Hello,

Here is a new patch that should fix the issue and the fatal error.

On a Drupal 8.1.x (after 8.1.3) from git, and features on 8.3.x with git I still have the issue and the patch fix it.

The original patch was made against Drupal 8.0.x (I don't remember the exact version).

I think the problem comes from a config entity that does not declare properly its label because I don't have the problem. I am curious to know for which entity the fatal error was triggered on #2745287: Features UI Error: Call to a member function render() on string in Drupal\features\FeaturesManager. Also you mention empty component categories for which categories is the label empty?

Yes the documentation says that "->getLabel()" returns a string but when inspecting for debug it is a TranslatableMarkup that is returned so I don't know what to follow.

grimreaper’s picture

Hello,

I am currently testing varnish_purge and I am finally able to reproduce the fatal error as I was applying my first patch.

The problem comes from config entity types not declaring label.

As you can see on http://cgit.drupalcode.org/varnish_purge/tree/src/Entity/VarnishPurgerSe..., in the @ConfigEntityType annotation there is

 *   label = @Translation("Varnish Purger Settings"),

(I will make a patch on varnish_purge for that)

And on the admin/config/development/configuration/single/export, in the select list "Configuration type", there is an empty option.

mpotter’s picture

Status: Needs review » Closed (won't fix)

I'm not seeing this error. You need to test in the latest release of Drupal core, so I cannot fix something from the old 8.1.3. You need to use 8.1.8 as of this writing. If getLabel is returning an object instead of string then that should be investigated as a core or contrib bug since that violates the interface definition. This isn't something to fix in Features. Adding a bunch of ::render() calls is not good practice.