ConditionPluginBase.php in Zircon Profile 8.0
File
core/lib/Drupal/Core/Condition/ConditionPluginBase.php
View source
<?php
namespace Drupal\Core\Condition;
use Drupal\Core\Executable\ExecutableManagerInterface;
use Drupal\Core\Executable\ExecutablePluginBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait;
abstract class ConditionPluginBase extends ExecutablePluginBase implements ConditionInterface {
use ContextAwarePluginAssignmentTrait;
protected $executableManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this
->setConfiguration($configuration);
}
public function isNegated() {
return !empty($this->configuration['negate']);
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$contexts = $form_state
->getTemporaryValue('gathered_contexts') ?: [];
$form['context_mapping'] = $this
->addContextAssignmentElement($this, $contexts);
$form['negate'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Negate the condition'),
'#default_value' => $this->configuration['negate'],
);
return $form;
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['negate'] = $form_state
->getValue('negate');
}
public function execute() {
return $this->executableManager
->execute($this);
}
public function getConfiguration() {
return array(
'id' => $this
->getPluginId(),
) + $this->configuration;
}
public function setConfiguration(array $configuration) {
$this->configuration = $configuration + $this
->defaultConfiguration();
return $this;
}
public function defaultConfiguration() {
return array(
'negate' => FALSE,
);
}
public function calculateDependencies() {
return array();
}
public function setExecutableManager(ExecutableManagerInterface $executableManager) {
$this->executableManager = $executableManager;
return $this;
}
}