Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 299252

Make Node views wizard buildFilters more efficient

$
0
0

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


Viewing all articles
Browse latest Browse all 299252

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>