(This is a follow-up on PHP 7.4 notice in views node wizard if a taxonomy field widget is hidden)
In the above issue a bug fix was made for hidden taxonomy field widgets in the views node wizard.
As point out by @alexpott here the code that fixes the bug can be made more efficient:
+++ b/core/modules/node/src/Plugin/views/wizard/Node.php @@ -279,7 +279,7 @@ protected function buildFilters(&$form, FormStateInterface $form_state) { $widget = $display->getComponent($field_name); // We define "tag-like" taxonomy fields as ones that use the // "Autocomplete (Tags style)" widget. - if ($widget['type'] == 'entity_reference_autocomplete_tags') { + if (!empty($widget) && $widget['type'] == 'entity_reference_autocomplete_tags') { $tag_fields[$field_name] = $field; }The logic above here is looping around this already... so we're doing more loops than is really necessary.
We can combine the two by doing...
$tag_fields += array_filter($this->entityFieldManager->getFieldDefinitions($this->entityTypeId, $bundle), function (FieldDefinitionInterface $field_definition) use ($display) { if ($field_definition->getType() == 'entity_reference' && $field_definition->getSetting('target_type') == 'taxonomy_term') { $widget = $display->getComponent($field_definition->getName()); return isset($widget['type']) && $widget['type'] == 'entity_reference_autocomplete_tags'; } return FALSE; });
Can you open a follow-up for this? Shouldn't be part of the change here.
This issue was created to "efficiencify" the code from #3167733 according to the proposed code above.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | 3187643-nr-bot.txt | 1.28 KB | needs-review-queue-bot |
Issue fork drupal-3187643
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3187643-make-bug-fix-code
changes, plain diff MR !479
Comments
Comment #2
spokjeAnd postponing until PHP 7.4 notice in views node wizard if a taxonomy field widget is hidden is committed.
Comment #3
spokjeComment #4
spokjeComment #5
spokjeUn-postponing, since PHP 7.4 notice in views node wizard if a taxonomy field widget is hidden is committed.
Comment #7
spokjeComment #9
spokjeRerolled against
9.3.xComment #13
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #16
acbramley commentedRebased onto 11.x and fixed the double (triple?) loop
Comment #17
quietone commentedCan the title be simplified? Referring to a previous issue in the commit message is uncommon. Maybe 'Make X more efficient' ?
Comment #18
acbramley commentedDone
Comment #19
smustgrave commentedSeems pretty straight forward.
Comment #21
catchThis is a lot more readable, changing to a task - no new feature is added.
Committed/pushed to 11.x, thanks!