function ContentEntity::fields

Same name in other branches
  1. 8.9.x core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php \Drupal\migrate_drupal\Plugin\migrate\source\ContentEntity::fields()
  2. 10 core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php \Drupal\migrate_drupal\Plugin\migrate\source\ContentEntity::fields()
  3. 11.x core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php \Drupal\migrate_drupal\Plugin\migrate\source\ContentEntity::fields()

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.