function ContentEntity::fields

Returns available fields on the source.

Return value

array Available fields in the source, keys are the field machine names as used in field mappings, values are descriptions.

Overrides MigrateSourceInterface::fields

File

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

Class

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

Namespace

Drupal\migrate_drupal\Plugin\migrate\source

Code

public function fields() {
  // Retrieving fields from a non-fieldable content entity will throw a
  // LogicException. Return an empty list of fields instead.
  if (!$this->entityType
    ->entityClassImplements('Drupal\\Core\\Entity\\FieldableEntityInterface')) {
    return [];
  }
  $field_definitions = $this->entityFieldManager
    ->getBaseFieldDefinitions($this->entityType
    ->id());
  if (!empty($this->configuration['bundle'])) {
    $field_definitions += $this->entityFieldManager
      ->getFieldDefinitions($this->entityType
      ->id(), $this->configuration['bundle']);
  }
  $fields = array_map(function ($definition) {
    return (string) $definition->getLabel();
  }, $field_definitions);
  return $fields;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.