refactor entity_reference_purger_entity_delete() for readability

Created on 31 August 2022, about 2 years ago
Updated 21 June 2024, 5 months ago

Problem/Motivation

Just a suggestion, but entity_reference_purger_entity_delete() would be a lot easier to read if instead of:

  foreach ($field_map as $entity_type => $data) {
    foreach ($data as $field_name => $field_data) {
      foreach ($field_data['bundles'] as $bundle) {
        // multiple guard clauses
      
        // do work here

if was refactored into:

  $field_definitions_to_purge = [];
  foreach ($field_map as $entity_type => $data) {
    foreach ($data as $field_name => $field_data) {
      foreach ($field_data['bundles'] as $bundle) {
        // multiple guard clauses

        $field_definitions_to_purge[] = $field_definition;
      }
   }
}

foreach ($field_definitions_to_purge) {
  // do work here
}

So two loops instead of one, and with much less nesting of code.

The code that builds up the list of fields to work on could also be moved to a helper function.

📌 Task
Status

Needs review

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom joachim

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.

Production build 0.71.5 2024