You are here

EncryptionMethodBase.php in Encrypt 8.3

File

src/Plugin/EncryptionMethod/EncryptionMethodBase.php
View source
<?php

namespace Drupal\encrypt\Plugin\EncryptionMethod;

use Drupal\Component\Plugin\ConfigurableInterface;
use Drupal\Component\Plugin\DependentPluginInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Plugin\PluginBase;
use Drupal\encrypt\EncryptionMethodInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Provides a base class for EncryptionMethod plugins.
 */
abstract class EncryptionMethodBase extends PluginBase implements EncryptionMethodInterface, ConfigurableInterface, DependentPluginInterface {

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

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

  /**
   * {@inheritdoc}
   */
  public function getLabel() {
    return $this->pluginDefinition['title'];
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getConfiguration() {
    return $this->configuration;
  }

  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) {
    $this->configuration = $configuration;
  }

  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function canDecrypt() {
    return $this->pluginDefinition['can_decrypt'];
  }

  /**
   * {@inheritdoc}
   */
  public function isDeprecated() {
    return $this->pluginDefinition['deprecated'];
  }

}

Classes

Namesort descending Description
EncryptionMethodBase Provides a base class for EncryptionMethod plugins.