You are here

public static function FeedImport::getEntityInfo in Feed Import 8

Gets info about an entity. This info is cached.

Parameters

string $entity_name The entity name:

Return value

object An object that describes entity

6 calls to FeedImport::getEntityInfo()
FeedImport::deleteExpired in feed_import_base/src/FeedImport.php
Delete all expired items.
FeedImport::setProcessorSettings in feed_import_base/src/FeedImport.php
Sets processor settings.
feed_import_base_entity_delete in feed_import_base/feed_import_base.module
Implements hook_entity_delete().
FieldsForm::buildForm in src/Form/FieldsForm.php
Form constructor.
FieldsForm::submitForm in src/Form/FieldsForm.php
Form submission handler.

... See full list

File

feed_import_base/src/FeedImport.php, line 32

Class

FeedImport
This class provides helper functions for feed import.

Namespace

Drupal\feed_import_base

Code

public static function getEntityInfo($entity_name) {
  if (empty($entity_name)) {
    return FALSE;
  }
  elseif (isset(static::$entityInfo[$entity_name])) {
    return static::$entityInfo[$entity_name];
  }
  if (!($entity = \Drupal::entityTypeManager()
    ->getDefinition($entity_name))) {
    return FALSE;
  }

  // Set main entity info.
  $info = (object) array(
    'name' => $entity_name,
    'idKey' => $entity
      ->getKey('id') ? $entity
      ->getKey('id') : NULL,
    'langKey' => $entity
      ->getKey('langcode') ? $entity
      ->getKey('langcode') : 'langcode',
    'bundleKey' => $entity
      ->getKey('bundle') ? $entity
      ->getKey('bundle') : NULL,
    'controller' => \Drupal::entityTypeManager()
      ->getStorage($entity_name),
    'properties' => array(),
    'fields' => array(),
  );
  if ($info->controller) {
    $info->controller->canSave = method_exists($info->controller, 'save');
    $info->controller->canDelete = method_exists($info->controller, 'delete');

    // TODO: look into this.
    // $info->controller->canResetCache = method_exists($info->controller, 'resetCache');
  }
  else {
    $info->controller = (object) array(
      'canCreate' => FALSE,
      'canSave' => FALSE,
      'canDelete' => FALSE,
      'canResetCache' => FALSE,
    );
  }
  $bundles = \Drupal::service('entity_type.bundle.info')
    ->getBundleInfo($entity_name);

  // Get fields info.
  foreach (array_keys($bundles) as $bundle_name) {
    if ($fieldlist = \Drupal::service('entity_field.manager')
      ->getFieldDefinitions($entity_name, $bundle_name)) {
      foreach ($fieldlist as &$field) {
        $field_info = FieldStorageConfig::loadByName($entity_name, $field
          ->getName());
        if ($field_info && (method_exists($field, 'isDeleted') && !$field
          ->isDeleted()) && !isset($info->fields[$field
          ->getName()])) {
          $info->fields[$field
            ->getName()] = array(
            'name' => $field
              ->getName(),
            'column' => key($field_info
              ->getSchema()['columns']),
            'columns' => array_keys($field_info
              ->getSchema()['columns']),
            'cardinality' => $field_info
              ->getCardinality(),
            'type' => $field
              ->getType(),
            'module' => $field_info
              ->getTypeProvider(),
          );
        }
        else {
          if (!isset($info->properties[$field
            ->getName()])) {
            $info->properties[$field
              ->getName()] = $field
              ->getName();
          }
        }
      }
    }
  }
  return static::$entityInfo[$entity_name] = $info;
}