Make bug-fix code for #3167733 (PHP 7.4 notice in views node wizard if a taxonomy field widget is hidden) more efficient

Created on 10 December 2020, over 3 years ago
Updated 30 January 2023, over 1 year ago

(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.

Feature request
Status

Needs work

Version

10.1

Component
Node system 

Last updated less than a minute ago

No maintainer
Created by

🇳🇱Netherlands Spokje

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • The 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.

Production build 0.71.5 2024