You are here

public static function Pool::getSelectablePools in CMS Content Sync 8

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

Returns an list of pools that can be selected for an entity type.

@oaram string $entity_type The entity type the pools should be returned for.

Parameters

string $bundle: The bundle the pools should be returned for

\Drupal\Core\Entity\EntityInterface $parent_entity: The parent entity, if any. Only required if $field_name is given-.

string $field_name: The name of the parent entity field that references this entity. In this case if the field handler is set to "automatically push referenced entities", the user doesn't have to make a choice as it is set automatically anyway.

mixed $entity_type:

Return value

array $selectable_pools

3 calls to Pool::getSelectablePools()
cms_content_sync_form_alter in ./cms_content_sync.module
1) Make sure the user is informed that content will not only be deleted on this * instance but also on all connected instances if configured that way.
_cms_content_sync_paragraphs_push_settings_form in ./cms_content_sync.module
Add the Push settings for to the several Paragraph widget types.
_cms_content_sync_update_pool_selector in ./cms_content_sync.module
Ajax callback to render the pools after flow selection.

File

src/Entity/Pool.php, line 345

Class

Pool
Defines the "Content Sync - Pool" entity.

Namespace

Drupal\cms_content_sync\Entity

Code

public static function getSelectablePools($entity_type, $bundle, $parent_entity = null, $field_name = null) {

  // Get all available flows.
  $flows = Flow::getAll();
  $configs = [];
  $selectable_pools = [];
  $selectable_flows = [];

  // When editing the entity directly, the "push as reference" flows won't be available and vice versa.
  $root_entity = !$parent_entity && !$field_name;
  if ($root_entity) {
    $allowed_push_options = [
      PushIntent::PUSH_FORCED,
      PushIntent::PUSH_MANUALLY,
      PushIntent::PUSH_AUTOMATICALLY,
    ];
  }
  else {
    $allowed_push_options = [
      PushIntent::PUSH_FORCED,
      PushIntent::PUSH_AS_DEPENDENCY,
    ];
  }
  foreach ($flows as $flow_id => $flow) {
    $flow_entity_config = $flow
      ->getEntityTypeConfig($entity_type, $bundle);
    if (empty($flow_entity_config)) {
      continue;
    }
    if ('ignore' == $flow_entity_config['handler']) {
      continue;
    }
    if (!in_array($flow_entity_config['export'], $allowed_push_options)) {
      continue;
    }
    if ($parent_entity && $field_name) {
      $parent_flow_config = $flow->sync_entities[$parent_entity
        ->getEntityTypeId() . '-' . $parent_entity
        ->bundle() . '-' . $field_name];
      if (!empty($parent_flow_config['handler_settings']['export_referenced_entities'])) {
        continue;
      }
    }
    $selectable_flows[$flow_id] = $flow;
    $configs[$flow_id] = [
      'flow_label' => $flow
        ->label(),
      'flow' => $flow
        ->getEntityTypeConfig($entity_type, $bundle),
    ];
  }
  foreach ($configs as $config_id => $config) {
    if (in_array('allow', $config['flow']['export_pools'])) {
      $selectable_pools[$config_id]['flow_label'] = $config['flow_label'];
      $selectable_pools[$config_id]['widget_type'] = $config['flow']['pool_export_widget_type'];
      foreach ($config['flow']['export_pools'] as $pool_id => $push_to_pool) {

        // Filter out all pools with configuration "allow".
        if (self::POOL_USAGE_ALLOW == $push_to_pool) {
          $pool_entity = \Drupal::entityTypeManager()
            ->getStorage('cms_content_sync_pool')
            ->loadByProperties([
            'id' => $pool_id,
          ]);
          $pool_entity = reset($pool_entity);
          $selectable_pools[$config_id]['pools'][$pool_id] = $pool_entity
            ->label();
        }
      }
    }
  }
  return $selectable_pools;
}