EntityLegalPluginBase.php in Entity Legal 8.2
File
src/EntityLegalPluginBase.php
View source
<?php
namespace Drupal\entity_legal;
use Drupal\Component\Plugin\PluginBase;
abstract class EntityLegalPluginBase extends PluginBase implements EntityLegalPluginInterface {
protected $documents = [];
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->documents = $this
->getDocumentsForMethod();
}
public function getDocumentsForMethod() {
if (\Drupal::currentUser()
->hasPermission('administer entity legal')) {
return [];
}
if ($this->pluginDefinition['type'] == 'existing_users' && \Drupal::currentUser()
->isAnonymous()) {
return [];
}
$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);
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;
}
}