You are here

protected function ContentEntity::toArray in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php \Drupal\migrate_drupal\Plugin\migrate\source\ContentEntity::toArray()

Converts an entity to an array.

Makes all IDs into flat values. All other values are returned as per $entity->toArray(), which is a nested array.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to convert.

Return value

array The entity, represented as an array.

1 call to ContentEntity::toArray()
ContentEntity::yieldEntities in core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php
Loads and yields entities, one at a time.

File

core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php, line 204

Class

ContentEntity
Source plugin to get content entities from the current version of Drupal.

Namespace

Drupal\migrate_drupal\Plugin\migrate\source

Code

protected function toArray(ContentEntityInterface $entity) {
  $return = $entity
    ->toArray();

  // This is necessary because the IDs must be flat. They cannot be nested for
  // the ID map.
  foreach (array_keys($this
    ->getIds()) as $id) {

    /** @var \Drupal\Core\TypedData\Plugin\DataType\ItemList $value */
    $value = $entity
      ->get($id);

    // Force the IDs on top of the previous values.
    $return[$id] = $value
      ->first()
      ->getString();
  }
  return $return;
}