You are here

class BehaviorService in Synonyms 2.0.x

Same name and namespace in other branches
  1. 8 src/SynonymsService/BehaviorService.php \Drupal\synonyms\SynonymsService\BehaviorService

Collect all known synonyms behavior services.

Collect all known synonyms behavior services during dependency injection container compilation.

Hierarchy

Expanded class hierarchy of BehaviorService

4 files declare their use of BehaviorService
BehaviorForm.php in src/Form/BehaviorForm.php
SettingsForm.php in src/Form/SettingsForm.php
SynonymConfigController.php in src/Controller/SynonymConfigController.php
SynonymsEntity.php in modules/synonyms_views_filter/src/Plugin/views/filter/SynonymsEntity.php
1 string reference to 'BehaviorService'
synonyms.services.yml in ./synonyms.services.yml
synonyms.services.yml
1 service uses BehaviorService
synonyms.behavior_service in ./synonyms.services.yml
Drupal\synonyms\SynonymsService\BehaviorService

File

src/SynonymsService/BehaviorService.php, line 16

Namespace

Drupal\synonyms\SynonymsService
View source
class BehaviorService implements ContainerInjectionInterface {

  /**
   * Collected behavior services.
   *
   * @var array
   */
  protected $behaviorServices;

  /**
   * Collected widget services.
   *
   * @var array
   */
  protected $widgetServices;

  /**
   * BehaviorService constructor.
   */
  public function __construct() {
    $this->behaviorServices = [];
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static();
  }

  /**
   * Add a new discovered behavior service.
   *
   * @param \Drupal\synonyms\BehaviorInterface\BehaviorInterface $behavior_service
   *   Behavior service object that was discovered and should be added into the
   *   list of known ones.
   * @param string $id
   *   Service ID that corresponds to this behavior service.
   */
  public function addBehaviorService(BehaviorInterface $behavior_service, $id) {

    // It is more convenient to use machine readable IDs as array keys here.
    $machine_id = $behavior_service
      ->getId();

    // Behavior services collector.
    if (!isset($this->behaviorServices[$machine_id])) {
      $this->behaviorServices[$machine_id] = $behavior_service;
    }

    // Widget services collector.
    if ($behavior_service instanceof WidgetInterface && !isset($this->widgetServices[$machine_id])) {
      $this->widgetServices[$machine_id] = $behavior_service;
    }
  }

  /**
   * Array of known behavior services.
   *
   * @return array
   *   The return value
   */
  public function getBehaviorServices() {
    return $this->behaviorServices;
  }

  /**
   * Array of known widget services.
   *
   * @return array
   *   The return value
   */
  public function getWidgetServices() {
    return $this->widgetServices;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BehaviorService::$behaviorServices protected property Collected behavior services.
BehaviorService::$widgetServices protected property Collected widget services.
BehaviorService::addBehaviorService public function Add a new discovered behavior service.
BehaviorService::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
BehaviorService::getBehaviorServices public function Array of known behavior services.
BehaviorService::getWidgetServices public function Array of known widget services.
BehaviorService::__construct public function BehaviorService constructor.