Namespace
Drupal\rules\Core
File
-
src/Core/RulesActionBase.php
View source
<?php
namespace Drupal\rules\Core;
use Drupal\Component\Plugin\Exception\ContextException;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Plugin\ContextAwarePluginTrait;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Session\AccountInterface;
use Drupal\rules\Context\ContextProviderTrait;
abstract class RulesActionBase extends PluginBase implements RulesActionInterface {
use ContextAwarePluginTrait {
getContextValue as protected traitGetContextValue;
}
use ContextProviderTrait;
use ExecutablePluginTrait;
use ConfigurationAccessControlTrait;
protected $configuration;
public function getContextValue($name) {
try {
return $this->traitGetContextValue($name);
} catch (ContextException $e) {
if (strpos($e->getMessage(), 'context is required') === FALSE) {
throw $e;
}
}
}
public function refineContextDefinitions(array $selected_data) {
}
public function assertMetadata(array $selected_data) {
return [];
}
public function getConfiguration() {
return [
'id' => $this->getPluginId(),
] + $this->configuration;
}
public function setConfiguration(array $configuration) {
$this->configuration = $configuration + $this->defaultConfiguration();
return $this;
}
public function defaultConfiguration() {
return [];
}
public function calculateDependencies() {
return [];
}
public function executeMultiple(array $objects) {
}
public function autoSaveContext() {
return [];
}
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
if ($return_as_object) {
return AccessResult::forbidden();
}
return FALSE;
}
public function execute() {
$args = [];
foreach ($this->getContextDefinitions() as $name => $definition) {
$value = $this->getContextValue($name);
$type = $definition->toArray()['type'];
if (substr($type, 0, 6) == 'entity') {
if (is_array($value) && is_string($value[0])) {
$value = array_map([
$this,
'upcastEntityId',
], $value, array_fill(0, count($value), $type));
}
elseif (is_string($value)) {
$value = $this->upcastEntityId($value, $type);
}
}
$args[$name] = $value;
}
call_user_func_array([
$this,
'doExecute',
], $args);
}
}
Classes