acquia_search-3.0.1/src/Event/AcquiaPossibleCoresEvent.php
src/Event/AcquiaPossibleCoresEvent.php
<?php
namespace Drupal\acquia_search\Event;
use Drupal\acquia_connector\Event\EventBase;
use Drupal\search_api\ServerInterface;
/**
* The event dispatched to populate possible cores outside the service.
*/
class AcquiaPossibleCoresEvent extends EventBase {
/**
* Readonly status of Acquia Search.
*
* @var bool
*/
protected $coreReadonly;
/**
* Raw subscription data to alter.
*
* @var array
*/
protected $possibleCores;
/**
* The Search API server ID.
*
* @var \Drupal\search_api\ServerInterface|string
*/
private $server;
/**
* Pass in connector config by default to all events.
*
* @param \Drupal\search_api\ServerInterface|string $server
* The Search API server ID.
* @param array $possible_cores
* The already considered possible cores.
*/
public function __construct($server, array $possible_cores) {
if (is_string($server)) {
@trigger_error('Calling ' . __METHOD__ . '() with $server as a string instead of \Drupal\search_api\Entity\ServerInterface is deprecated in acquia_search:3.2.0 and will be required in drupal:3.3.0. See https://www.drupal.org/project/acquia_search/issues/3432307', E_USER_DEPRECATED);
}
$this->server = $server;
$this->possibleCores = $possible_cores;
$this->coreReadonly = TRUE;
}
/**
* Get the Search API server ID.
*
* @return string
* The Search API server ID.
*
* @deprecated in acquia_search:3.2.0 and is removed from acquia_search:3.3.0
* Please use getServer()->id() instead.
* @see https://www.drupal.org/project/acquia_search/issues/3432307
*/
public function getServerId(): string {
// @todo remove string check in Search 3.3+
if (is_string($this->server)) {
return $this->server;
}
else {
return $this->server->id();
}
}
/**
* Get the Search API server object or server as string.
*
* @return \Drupal\search_api\ServerInterface|string
* The Search API server.
*/
public function getServer() {
return $this->server;
}
/**
* Gets possible cores from the event.
*
* @return array
* The Acquia Subscription data.
*/
public function getPossibleCores() {
return $this->possibleCores;
}
/**
* Add possible core.
*
* @param string $core_id
* Core to be added.
*/
public function addPossibleCore(string $core_id): void {
if (!array_search($core_id, $this->possibleCores)) {
$this->possibleCores[] = $core_id;
}
}
/**
* Get Readonly Status from Acquia Search.
*
* @return bool
* Readonly Status.
*/
public function isReadOnly() {
return $this->coreReadonly;
}
/**
* Set readonly status for Acquia Search.
*
* @param bool $coreReadonly
* Set Readonly Status.
*/
public function setReadOnly(bool $coreReadonly) {
$this->coreReadonly = $coreReadonly;
}
}
