Getting a warking every time the cache is rebuilt.

The warning comes from ContentEntityDeriver ordering plugins by label, which are not strings but TranslatableMarkup objects. When these objects are rendered they're changed, and that is why uasort throws such warning.

Similar issue with token module, https://www.drupal.org/node/2670942

I think the solution would be not ordering at all these plug-ins, first of all because this is a backend operation, plug-ins are cached and they may be displayed in a different language, thus such ordering makes no sense.

I don't know if these labels are ever displayed, but if so, the ordering should be done when displaying them in a specific language, not here.

This is the offending line, which I would just remove from ContentEntityDeriver:

uasort($plugin_derivatives, array($this, 'compareDerivatives'));

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jose Reyero created an issue. See original summary.

kamalrajsahu21’s picture

Assigned: Unassigned » kamalrajsahu21
kamalrajsahu21’s picture

Here is a patch to remove uasort from ContentEntityDeriver.php

kamalrajsahu21’s picture

Status: Active » Needs review
Jose Reyero’s picture

Looks good to me, however I am not sure whether there was a reason for this ordering... if this plug-in list was being displayed somewhere (?) maybe there should be some other reordering somewhere else in the UI.

drunken monkey’s picture

Title: Warning: uasort(): Array was modified by the user comparison function in Drupal\search_api\Plugin\search_api\datasource\ContentEntityDeriver->getDerivativeDefinitions() » Clean up deriver code
Assigned: kamalrajsahu21 » Unassigned
FileSize
8.36 KB
8.44 KB

Thanks a lot for reporting this problem and thanks for the patch!

You're right, sorting the arrays there doesn't really make any sense.
I've tried it, and for some reason the order still stays the same in the index edit form even without that line. However, to be sure, we should still add an explicit sort there when setting the options in the form.

Also, we don't need the compareDerivatives() method then anymore.

Finally, I found some other weird stuff regarding our deriver classes, so I cleaned that up, too.

Status: Needs review » Needs work

The last submitted patch, 6: 2758321-6--clean_up_derivers.patch, failed testing.

drunken monkey’s picture

Status: Needs work » Needs review
FileSize
779 bytes
8.43 KB

This should work better.

Status: Needs review » Needs work

The last submitted patch, 8: 2758321-8--clean_up_derivers.patch, failed testing.

drunken monkey’s picture

Status: Needs work » Needs review

Same fix for the Views display deriver.

drunken monkey’s picture

borisson_’s picture

Status: Needs review » Reviewed & tested by the community
drunken monkey’s picture

Thanks a lot for reviewing!
Attached a re-roll – if the test bot doesn't object, I'll commit it.

  • drunken monkey committed 65743d3 on 8.x-1.x
    Issue #2758321 by drunken monkey, kamalrajsahu21: Cleaned up plugin...
drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

OK, great.
Committed.
Thanks again to everyone!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

andrezstar’s picture

Still having the issue
Warning: uasort(): Array was modified by the user comparison function in Drupal\facets\Plugin\facets\facet_source\SearchApiDisplayDeriver->getDerivativeDefinitions() (line 61 of modules/contrib/facets/src/Plugin/facets/facet_source/SearchApiDisplayDeriver.php).

My stuff:
Drupal core 8.4.5
Bootstrap 8.x-3.10

Facets 8.x-1.0-beta2
Search API 8.x-1.7
Elasticsearch Connector 8.x-5.0-alpha2