You are here

public function EntityLegalPluginBase::getDocumentsForMethod in Entity Legal 8.2

Same name and namespace in other branches
  1. 4.0.x src/EntityLegalPluginBase.php \Drupal\entity_legal\EntityLegalPluginBase::getDocumentsForMethod()
  2. 3.0.x src/EntityLegalPluginBase.php \Drupal\entity_legal\EntityLegalPluginBase::getDocumentsForMethod()

Get all Entity Legal Documents for this plugin.

Return value

array All published entity legal documents required.

1 call to EntityLegalPluginBase::getDocumentsForMethod()
EntityLegalPluginBase::__construct in src/EntityLegalPluginBase.php
Constructs a \Drupal\Component\Plugin\PluginBase object.

File

src/EntityLegalPluginBase.php, line 36

Class

EntityLegalPluginBase
Class ResponsiveMenusPluginBase.

Namespace

Drupal\entity_legal

Code

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;
}