You are here

public function FlowControllerBase::canPushEntityType in CMS Content Sync 2.1.x

@inheritDoc

1 call to FlowControllerBase::canPushEntityType()
FlowControllerBase::canPushEntity in src/Controller/FlowControllerBase.php
@inheritDoc

File

src/Controller/FlowControllerBase.php, line 46

Class

FlowControllerBase

Namespace

Drupal\cms_content_sync\Controller

Code

public function canPushEntityType($entity_type_name, $bundle_name, $reason, $action = SyncIntent::ACTION_CREATE, $pool = null) {
  $any_reason = [
    PushIntent::PUSH_AUTOMATICALLY,
    PushIntent::PUSH_MANUALLY,
    PushIntent::PUSH_AS_DEPENDENCY,
  ];
  if (is_string($reason)) {
    if (PushIntent::PUSH_ANY === $reason || PushIntent::PUSH_FORCED === $reason) {
      $reason = $any_reason;
    }
    else {
      $reason = [
        $reason,
      ];
    }
  }
  if (!$bundle_name) {
    foreach ($this
      ->getEntityTypeConfig($entity_type_name) as $bundles) {
      foreach ($bundles as $bundle_name => $config) {
        if ($this
          ->canPushEntityType($entity_type_name, $bundle_name, $reason, $action, $pool)) {
          return true;
        }
      }
    }
    return false;
  }
  $config = $this
    ->getEntityTypeConfig($entity_type_name, $bundle_name);
  if (empty($config) || Flow::HANDLER_IGNORE == $config['handler']) {
    return false;
  }
  if (PushIntent::PUSH_DISABLED == $config['export']) {
    return false;
  }
  if (SyncIntent::ACTION_DELETE == $action && !boolval($config['export_deletion_settings']['export_deletion'])) {
    return false;
  }
  if ($pool) {
    if (empty($config['export_pools'][$pool->id]) || Pool::POOL_USAGE_FORBID == $config['export_pools'][$pool->id]) {
      return false;
    }
  }
  return in_array($config['export'], $reason);
}