ConditionBase.php in Commerce Core 8.2
File
src/Plugin/Commerce/Condition/ConditionBase.php
View source
<?php
namespace Drupal\commerce\Plugin\Commerce\Condition;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Form\FormStateInterface;
abstract class ConditionBase extends PluginBase implements ConditionInterface {
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this
->setConfiguration($configuration);
}
public function calculateDependencies() {
return [];
}
public function defaultConfiguration() {
return [];
}
public function getConfiguration() {
return $this->configuration;
}
public function setConfiguration(array $configuration) {
$this->configuration = NestedArray::mergeDeep($this
->defaultConfiguration(), $configuration);
return $this;
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form;
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration = [];
}
public function getLabel() {
return $this->pluginDefinition['label'];
}
public function getDisplayLabel() {
return $this->pluginDefinition['display_label'];
}
public function getEntityTypeId() {
return $this->pluginDefinition['entity_type'];
}
protected function assertEntity(EntityInterface $entity) {
$entity_type_id = $entity
->getEntityTypeId();
$condition_entity_type_id = $this
->getEntityTypeId();
if ($entity_type_id != $condition_entity_type_id) {
throw new \InvalidArgumentException(sprintf('The condition requires a "%s" entity, but a "%s" entity was given.', $condition_entity_type_id, $entity_type_id));
}
}
protected function getComparisonOperators() {
return [
'>' => $this
->t('Greater than'),
'>=' => $this
->t('Greater than or equal to'),
'<=' => $this
->t('Less than or equal to'),
'<' => $this
->t('Less than'),
'==' => $this
->t('Equals'),
];
}
}