In `field_token_info_alter` it's checked whether there is a token type specified. If this is the case the fields are loaded and looped through. The first check in the loop is to see if there is any info set for the token type. If this is not the case then the field is skipped and the loop continues to the next field. Between one field and the next there's no way for the condition's result to change. It makes more sense to check this before loading any fields at all and just skip the entire loop.

Members fund testing for the Drupal project. Drupal Association Learn more

Comments

Kingdutch created an issue. See original summary.

Kingdutch’s picture

Assigned: Kingdutch » Unassigned
Status: Active » Needs review
FileSize
776 bytes

Patch attached

Status: Needs review » Needs work
Kingdutch’s picture

I don't quite see how that test is related to the changes in the patch unless it relied on side effects of loading the fieldDefinitions.

Berdir’s picture

Status: Needs work » Needs review

Nope, it wasn't, fixed the test fails in #2891981: Update tests for Drupal 8.4.x.

Berdir’s picture

Status: Needs review » Needs work

Makes sense, directly about we have an empty($token_type) check, what about combining both cases into a single if (this || that)? We have tons of continues and conditions in those loops and this helps to simplify that a bit I think.

Kingdutch’s picture

Status: Needs work » Needs review
FileSize
926 bytes
590 bytes

Good observation!

Attached is the patch that includes this change. If you've already applied that patch you can use the interdiff.

Berdir’s picture

Status: Needs review » Fixed

Thanks, committed.

  • Berdir committed 24edd86 on 8.x-1.x authored by Kingdutch
    Issue #2886498 by Kingdutch: Don't load fields if token_type does not...

Status: Fixed » Closed (fixed)

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