You are here

public static function EntityStatus::getInfosForEntity in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x src/Entity/EntityStatus.php \Drupal\cms_content_sync\Entity\EntityStatus::getInfosForEntity()
  2. 2.0.x src/Entity/EntityStatus.php \Drupal\cms_content_sync\Entity\EntityStatus::getInfosForEntity()

Get a list of all entity status entities for the given entity.

Parameters

string $entity_type: The entity type ID

string $entity_uuid: The entity UUID

array $filter: Additional filters. Usually "flow"=>... or "pool"=>...

Return value

EntityStatus[]

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

28 calls to EntityStatus::getInfosForEntity()
CliService::push in src/Cli/CliService.php
Push all entities for a specific flow.
cms_content_sync_entity_delete in ./cms_content_sync.module
Push the entity deletion automatically if configured to do so.
cms_content_sync_show_usage_operation in ./cms_content_sync.module
DebugForm::debugEntity in src/Form/DebugForm.php
EntityHandlerBase::ignorePush in src/Plugin/EntityHandlerBase.php
Check if the entity should not be ignored from the push.

... See full list

File

src/Entity/EntityStatus.php, line 136

Class

EntityStatus
Defines the "Content Sync - Entity Status" entity type.

Namespace

Drupal\cms_content_sync\Entity

Code

public static function getInfosForEntity($entity_type, $entity_uuid, $filter = null) {
  if (!$entity_type) {
    throw new \Exception('$entity_type is required.');
  }
  if (!$entity_uuid) {
    throw new \Exception('$entity_uuid is required.');
  }
  $base_filter = [
    'entity_type' => $entity_type,
    'entity_uuid' => $entity_uuid,
  ];
  $filters_combined = $base_filter;
  $filter_without_flow = isset($filter['flow']) && (empty($filter['flow']) || self::FLOW_NO_FLOW == $filter['flow']);
  if ($filter_without_flow) {
    $filters_combined = array_merge($filters_combined, [
      'flow' => self::FLOW_NO_FLOW,
    ]);
  }
  elseif ($filter) {
    $filters_combined = array_merge($filters_combined, $filter);
  }

  /**
   * @var EntityStatus[] $entities
   */
  $entities = \Drupal::entityTypeManager()
    ->getStorage('cms_content_sync_entity_status')
    ->loadByProperties($filters_combined);
  $result = [];

  // If a pull fails, we may create a status entity without a flow assigned.
  // We ignore them for normal functionality, so they're filtered out.
  if ($filter_without_flow) {
    foreach ($entities as $i => $entity) {
      if (!$entity
        ->getFlow()) {
        $result[] = $entity;
      }
    }
  }
  else {
    foreach ($entities as $i => $entity) {
      if ($entity
        ->getFlow()) {
        $result[] = $entity;
      }
    }
  }
  return $result;
}