Make difference between $entity and $content more clear

Created on 2 April 2025, 22 days ago

It feels to me that the words 'entity' and 'content' would benefit from a more clear definition in the code/the documentation.

To me, the 'entity' is the 'content' I am trying to export/import.

This makes the following code e.g. confusing:

  /**
   * Constructs a new ImportEvent object.
   *
   * @param \Drupal\Core\Entity\ContentEntityInterface $entity
   *   The entity being imported. Could be either a new or existing entity.
   * @param array $content
   *   The content to import.
   */
  public function __construct(ContentEntityInterface $entity, array $content) {
    $this->entity = $entity;
    $this->content = $content;
  }

If I would like to alter something, should I alter the $entity object, the $content array, or both?

Another example: on https://www.drupal.org/docs/extending-drupal/contributed-modules/contrib... it says:

 switch ($entity->bundle()) {
        case 'gpx':
          // Change bundle for original export.
          if (!$is_translation) {
            $output['bundle'] = 'file'; 
          }
          break;
      }

Why use $entity->bundle(), as $output['bundle'] also has the bundle?

📌 Task
Status

Active

Version

1.4

Component

Documentation

Created by

🇳🇱Netherlands koosvdkolk

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

Comments & Activities

Production build 0.71.5 2024