You are here

function _cms_content_sync_display_entity_type_differences_recursively in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x cms_content_sync.module \_cms_content_sync_display_entity_type_differences_recursively()
  2. 2.0.x cms_content_sync.module \_cms_content_sync_display_entity_type_differences_recursively()

Get HTML for a list of entity type differences and include all referenced entity types.

Parameters

array $result: A storage to save information per entity type + bundle in.

string $entity_type:

string $bundle:

Throws

Exception

2 calls to _cms_content_sync_display_entity_type_differences_recursively()
VersionMismatches::batch in modules/cms_content_sync_health/src/Controller/VersionMismatches.php
Batch push callback for the push-all operation.
_cms_content_sync_display_version_mismatches in ./cms_content_sync.module
Replace the "Show version mismatches" button with the actual information.

File

./cms_content_sync.module, line 165
Module file for cms_content_sync.

Code

function _cms_content_sync_display_entity_type_differences_recursively(&$result, $entity_type, $bundle) {
  if (isset($result[$entity_type][$bundle])) {
    return;
  }
  if (!EntityHandlerPluginManager::isEntityTypeFieldable($entity_type)) {
    return;
  }
  $self = _cms_content_sync_display_entity_type_differences($entity_type, $bundle);
  $result[$entity_type][$bundle] = empty($self) ? '' : $self;

  /**
   * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundleInfoService
   */
  $bundleInfoService = Drupal::service('entity_type.bundle.info');

  /**
   * @var \Drupal\Core\Entity\EntityFieldManager $entityFieldManager
   */
  $entityFieldManager = Drupal::service('entity_field.manager');

  /**
   * @var \Drupal\Core\Field\FieldDefinitionInterface[] $fields
   */
  $fields = $entityFieldManager
    ->getFieldDefinitions($entity_type, $bundle);
  foreach ($fields as $key => $field) {
    if (!in_array($field
      ->getType(), [
      "entity_reference",
      "entity_reference_revisions",
    ])) {
      continue;
    }
    $any_handler = FALSE;
    foreach (Flow::getAll() as $id => $flow) {
      $config = $flow
        ->getFieldHandlerConfig($entity_type, $bundle, $key);
      if (empty($config) || $config['handler'] == Flow::HANDLER_IGNORE) {
        continue;
      }
      $any_handler = TRUE;
      break;
    }
    if (!$any_handler) {
      continue;
    }
    $type = $field
      ->getSetting('target_type');
    $bundles = $field
      ->getSetting('target_bundles');
    if (empty($bundles)) {
      $bundles = array_keys($bundleInfoService
        ->getBundleInfo($type));
    }
    foreach ($bundles as $name) {
      $config = $flow
        ->getEntityTypeConfig($type, $name, TRUE);
      if (empty($config)) {
        continue;
      }
      _cms_content_sync_display_entity_type_differences_recursively($result, $type, $name);
    }
  }
}