ConditionPluginBase.php 1.97 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php

/**
 * @file
 * Contains \Drupal\Core\Condition\ConditionPluginBase.
 */

namespace Drupal\Core\Condition;

use Drupal\Core\Executable\ExecutablePluginBase;

/**
 * Provides a basis for fulfilling contexts for condition plugins.
 */
abstract class ConditionPluginBase extends ExecutablePluginBase implements ConditionInterface {

  /**
18
   * {@inheritdoc}
19
   */
20
21
22
23
  public function __construct(array $configuration, $plugin_id, $plugin_definition) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);

    $this->setConfiguration($configuration);
24
25
26
  }

  /**
27
   * {@inheritdoc}
28
29
30
31
32
33
   */
  public function isNegated() {
    return !empty($this->configuration['negate']);
  }

  /**
34
   * {@inheritdoc}
35
   */
36
  public function buildConfigurationForm(array $form, array &$form_state) {
37
38
    $form['negate'] = array(
      '#type' => 'checkbox',
39
      '#title' => $this->t('Negate the condition.'),
40
41
42
43
44
45
      '#default_value' => isset($this->configuration['negate']) ? $this->configuration['negate'] : FALSE,
    );
    return $form;
  }

  /**
46
   * {@inheritdoc}
47
   */
48
49
  public function validateConfigurationForm(array &$form, array &$form_state) {
  }
50
51

  /**
52
   * {@inheritdoc}
53
   */
54
  public function submitConfigurationForm(array &$form, array &$form_state) {
55
56
57
58
    $this->configuration['negate'] = $form_state['values']['negate'];
  }

  /**
59
   * {@inheritdoc}
60
61
62
63
64
   */
  public function execute() {
    return $this->executableManager->execute($this);
  }

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  /**
   * {@inheritdoc}
   */
  public function getConfiguration() {
    return array(
      'id' => $this->getPluginId(),
    ) + $this->configuration;
  }

  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) {
    $this->configuration = $configuration + $this->defaultConfiguration();
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    return array();
  }

96
}