You are here

public static function EntityHandlerPluginManager::getEntityTypeInfo in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x src/Plugin/Type/EntityHandlerPluginManager.php \Drupal\cms_content_sync\Plugin\Type\EntityHandlerPluginManager::getEntityTypeInfo()
  2. 2.0.x src/Plugin/Type/EntityHandlerPluginManager.php \Drupal\cms_content_sync\Plugin\Type\EntityHandlerPluginManager::getEntityTypeInfo()

Parameters

mixed $type_key:

mixed $entity_bundle_name:

2 calls to EntityHandlerPluginManager::getEntityTypeInfo()
EntityHandlerPluginManager::getEntityTypes in src/Plugin/Type/EntityHandlerPluginManager.php
Return a list of all entity types and which are supported.
FlowForm::renderEntityType in src/Form/FlowForm.php
Render all bundles for the given entity type. Displayed in vertical tabs from the parent form.

File

src/Plugin/Type/EntityHandlerPluginManager.php, line 83

Class

EntityHandlerPluginManager
Manages discovery and instantiation of entity handler plugins.

Namespace

Drupal\cms_content_sync\Plugin\Type

Code

public static function getEntityTypeInfo($type_key, $entity_bundle_name) {
  static $cache = [];
  if (!empty($cache[$type_key][$entity_bundle_name])) {
    return $cache[$type_key][$entity_bundle_name];
  }
  $info = [
    'entity_type' => $type_key,
    'bundle' => $entity_bundle_name,
    'required_field_not_supported' => false,
    'optional_field_not_supported' => false,
  ];

  /**
   * @var \Drupal\Core\Entity\EntityTypeManager $entityTypeManager
   */
  $entityTypeManager = \Drupal::service('entity_type.manager');
  $type = $entityTypeManager
    ->getDefinition($type_key);

  /**
   * @var EntityHandlerPluginManager $entityPluginManager
   */
  $entityPluginManager = \Drupal::service('plugin.manager.cms_content_sync_entity_handler');
  $entity_handlers = $entityPluginManager
    ->getHandlerOptions($type_key, $entity_bundle_name, true);
  if (empty($entity_handlers)) {
    $info['no_entity_type_handler'] = true;
    if ('user' == $type_key) {
      $info['security_concerns'] = true;
    }
    elseif ($type instanceof ConfigEntityType) {
      $info['is_config_entity'] = true;
    }
  }
  else {
    $info['no_entity_type_handler'] = false;
    if ('block_content' == $type_key) {
      $info['hint'] = 'except for config like block placement';
    }
    elseif ('paragraph' == $type_key) {
      $info['hint'] = 'Paragraphs version >= 8.x-1.3';
    }
    elseif ('field_collection_item' == $type_key) {
      $info['hint'] = 'Paragraphs version 8.x-1.0-alpha1';
    }
    $entity_handlers = array_keys($entity_handlers);
    $handler = $entityPluginManager
      ->createInstance(reset($entity_handlers), [
      'entity_type_name' => $type_key,
      'bundle_name' => $entity_bundle_name,
      'settings' => [],
      'sync' => null,
    ]);
    $reserved = [];
    $pools = Pool::getAll();
    if (count($pools)) {
      $reserved = reset($pools)
        ->getClient()
        ->getReservedPropertyNames();
    }
    $forbidden_fields = array_merge($handler
      ->getForbiddenFields(), $reserved);
    $info['unsupported_required_fields'] = [];
    $info['unsupported_optional_fields'] = [];

    /**
     * @var FieldHandlerPluginManager $fieldPluginManager
     */
    $fieldPluginManager = \Drupal::service('plugin.manager.cms_content_sync_field_handler');

    /**
     * @var \Drupal\Core\Entity\EntityFieldManager $entityFieldManager
     */
    $entityFieldManager = \Drupal::service('entity_field.manager');
    if (!self::isEntityTypeFieldable($type)) {
      $info['fieldable'] = false;
    }
    else {
      $info['fieldable'] = true;

      /**
       * @var \Drupal\Core\Field\FieldDefinitionInterface[] $fields
       */
      $fields = $entityFieldManager
        ->getFieldDefinitions($type_key, $entity_bundle_name);
      foreach ($fields as $key => $field) {
        if (in_array($key, $forbidden_fields)) {
          continue;
        }
        $field_handlers = $fieldPluginManager
          ->getHandlerOptions($type_key, $entity_bundle_name, $key, $field, true);
        if (!empty($field_handlers)) {
          continue;
        }
        $name = $key . ' (' . $field
          ->getType() . ')';
        if ($field
          ->isRequired()) {
          $info['unsupported_required_fields'][] = $name;
        }
        else {
          $info['unsupported_optional_fields'][] = $name;
        }
      }
      $info['required_field_not_supported'] = count($info['unsupported_required_fields']) > 0;
      $info['optional_field_not_supported'] = count($info['unsupported_optional_fields']) > 0;
    }
  }
  $info['is_supported'] = !$info['no_entity_type_handler'] && !$info['required_field_not_supported'];
  return $cache[$type_key][$entity_bundle_name] = $info;
}