You are here

abstract class EntityLegalPluginBase in Entity Legal 3.0.x

Same name and namespace in other branches
  1. 8.2 src/EntityLegalPluginBase.php \Drupal\entity_legal\EntityLegalPluginBase
  2. 4.0.x src/EntityLegalPluginBase.php \Drupal\entity_legal\EntityLegalPluginBase

Class ResponsiveMenusPluginBase.

@package Drupal\responsive_menus

Hierarchy

Expanded class hierarchy of EntityLegalPluginBase

4 files declare their use of EntityLegalPluginBase
Message.php in src/Plugin/EntityLegal/Message.php
Popup.php in src/Plugin/EntityLegal/Popup.php
ProfileForm.php in src/Plugin/EntityLegal/ProfileForm.php
Redirect.php in src/Plugin/EntityLegal/Redirect.php

File

src/EntityLegalPluginBase.php, line 12

Namespace

Drupal\entity_legal
View source
abstract class EntityLegalPluginBase extends PluginBase implements EntityLegalPluginInterface {

  /**
   * The legal documents that implement this plugin.
   *
   * @var array
   */
  protected $documents = [];

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

  /**
   * Get all Entity Legal Documents for this plugin.
   *
   * @return array
   *   All published entity legal documents required.
   */
  public function getDocumentsForMethod() {

    // Entity Legal administrators should never be forced to accept documents.
    if (\Drupal::currentUser()
      ->hasPermission('administer entity legal')) {
      return [];
    }

    // Ensure the correct user context for this plugin.
    if ($this->pluginDefinition['type'] == 'existing_users' && \Drupal::currentUser()
      ->isAnonymous()) {
      return [];
    }

    // Get all active documents that must be agreed to.
    $properties = [
      'require_existing' => 1,
    ];
    if ($this->pluginDefinition['type'] == 'new_users') {
      $properties = [
        'require_signup' => 1,
      ];
    }
    $documents = \Drupal::entityTypeManager()
      ->getStorage(ENTITY_LEGAL_DOCUMENT_ENTITY_NAME)
      ->loadByProperties($properties);

    // Remove any documents from the array set that don't use the given
    // acceptance method.

    /** @var \Drupal\entity_legal\EntityLegalDocumentInterface $document */
    foreach ($documents as $name => $document) {
      $agreed = !$document
        ->userMustAgree($this->pluginDefinition['type'] == 'new_users') || $document
        ->userHasAgreed();
      $is_method = $document
        ->getAcceptanceDeliveryMethod($this->pluginDefinition['type'] == 'new_users') == $this->pluginId;
      if ($agreed || !$is_method) {
        unset($documents[$name]);
      }
    }
    return $documents;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityLegalPluginBase::$documents protected property The legal documents that implement this plugin.
EntityLegalPluginBase::getDocumentsForMethod public function Get all Entity Legal Documents for this plugin.
EntityLegalPluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct 1
EntityLegalPluginInterface::execute public function Execute callback for Entity Legal method plugin. 4
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.