You are here

AbstractProvider.php in Synonyms 8

Same filename and directory in other branches
  1. 2.0.x src/Plugin/Synonyms/Provider/AbstractProvider.php

File

src/Plugin/Synonyms/Provider/AbstractProvider.php
View source
<?php

namespace Drupal\synonyms\Plugin\Synonyms\Provider;

use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\synonyms\SynonymsProviderInterface\SynonymsProviderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Good starting point for a synonyms provider plugin.
 */
abstract class AbstractProvider extends PluginBase implements SynonymsProviderInterface, ContainerFactoryPluginInterface {
  use StringTranslationTrait;

  /**
   * The container.
   *
   * @var \Symfony\Component\DependencyInjection\ContainerInterface
   */
  protected $container;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, ContainerInterface $container) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->container = $container;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container);
  }

  /**
   * {@inheritdoc}
   */
  public function getBehaviorService() {
    return $this
      ->getPluginDefinition()['synonyms_behavior_service'];
  }

  /**
   * {@inheritdoc}
   */
  public function getBehaviorServiceInstance() {
    return $this->container
      ->get($this
      ->getPluginDefinition()['synonyms_behavior_service']);
  }

}

Classes

Namesort descending Description
AbstractProvider Good starting point for a synonyms provider plugin.