You are here

class ClusterManager in Elasticsearch Connector 8.5

Same name and namespace in other branches
  1. 8.7 src/ClusterManager.php \Drupal\elasticsearch_connector\ClusterManager
  2. 8.6 src/ClusterManager.php \Drupal\elasticsearch_connector\ClusterManager

ClusterManager service.

Hierarchy

Expanded class hierarchy of ClusterManager

5 files declare their use of ClusterManager
ClusterDeleteForm.php in src/Form/ClusterDeleteForm.php
ClusterForm.php in src/Form/ClusterForm.php
ClusterManagerTest.php in tests/src/Unit/ClusterManagerTest.php
IndexForm.php in src/Form/IndexForm.php
SearchApiElasticsearchBackend.php in src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php
1 string reference to 'ClusterManager'
elasticsearch_connector.services.yml in ./elasticsearch_connector.services.yml
elasticsearch_connector.services.yml
1 service uses ClusterManager
elasticsearch_connector.cluster_manager in ./elasticsearch_connector.services.yml
Drupal\elasticsearch_connector\ClusterManager

File

src/ClusterManager.php, line 11

Namespace

Drupal\elasticsearch_connector
View source
class ClusterManager {

  /**
   * The state storage service.
   *
   * @var \Drupal\Node\NodeStorageInterface
   */
  protected $state;

  /**
   * The entity type manager service.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * ClusterManager constructor.
   *
   * @param \Drupal\Core\State\StateInterface $state
   *   The state storage service.
   */
  public function __construct(StateInterface $state, EntityTypeManagerInterface $entity_type_manager) {
    $this->state = $state;
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * Get the default (cluster) used by Elasticsearch.
   *
   * @return string
   *   The cluster identifier.
   */
  public function getDefaultCluster() {
    return $this->state
      ->get('elasticsearch_connector_get_default_connector', '');
  }

  /**
   * Set the default (cluster) used by Elasticsearch.
   *
   * @param string $cluster_id
   *   The new cluster identifier.
   */
  public function setDefaultCluster($cluster_id) {
    $this->state
      ->set('elasticsearch_connector_get_default_connector', $cluster_id);
  }

  /**
   * Load all clusters.
   *
   * @param bool $include_inactive
   *
   * @return \Drupal\elasticsearch_connector\Entity\Cluster[]
   */
  public function loadAllClusters($include_inactive = TRUE) {
    $clusters = $this->entityTypeManager
      ->getStorage('elasticsearch_cluster')
      ->loadMultiple();
    foreach ($clusters as $cluster) {
      if (!$include_inactive && !$cluster->status) {
        unset($clusters[$cluster->cluster_id]);
      }
    }
    return $clusters;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ClusterManager::$entityTypeManager protected property The entity type manager service.
ClusterManager::$state protected property The state storage service.
ClusterManager::getDefaultCluster public function Get the default (cluster) used by Elasticsearch.
ClusterManager::loadAllClusters public function Load all clusters.
ClusterManager::setDefaultCluster public function Set the default (cluster) used by Elasticsearch.
ClusterManager::__construct public function ClusterManager constructor.