UserProtectionBase.php in User protect 8
File
src/Plugin/UserProtection/UserProtectionBase.php
View source
<?php
namespace Drupal\userprotect\Plugin\UserProtection;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\UserInterface;
abstract class UserProtectionBase extends PluginBase implements UserProtectionInterface {
public $provider;
public $status = FALSE;
public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this
->setConfiguration($configuration);
}
public function label() {
return $this->pluginDefinition['label'];
}
public function description() {
return $this->pluginDefinition['description'];
}
public function getWeight() {
return $this->pluginDefinition['weight'];
}
public function getConfiguration() {
return [
'id' => $this
->getPluginId(),
'provider' => $this->pluginDefinition['provider'],
'status' => $this->status,
];
}
public function setConfiguration(array $configuration) {
if (isset($configuration['status'])) {
$this->status = (bool) $configuration['status'];
}
return $this;
}
public function defaultConfiguration() {
return [];
}
public function calculateDependencies() {
return [];
}
public function isEnabled() {
return (bool) $this->status;
}
public function isProtected(UserInterface $user, $op, AccountInterface $account) {
if ($op == $this
->getPluginId()) {
return TRUE;
}
}
public function applyAccountFormProtection(array &$form, FormStateInterface $form_state) {
return FALSE;
}
}