Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
14
core/lib/Drupal/Core/Executable/ExecutableException.php
Normal file
14
core/lib/Drupal/Core/Executable/ExecutableException.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Executable\ExecutableException.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Executable;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\ExceptionInterface;
|
||||
|
||||
/**
|
||||
* Generic executable plugin exception class.
|
||||
*/
|
||||
class ExecutableException extends \Exception implements ExceptionInterface {}
|
22
core/lib/Drupal/Core/Executable/ExecutableInterface.php
Normal file
22
core/lib/Drupal/Core/Executable/ExecutableInterface.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Executable\ExecutableInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Executable;
|
||||
|
||||
/**
|
||||
* An interface for executable plugins.
|
||||
*
|
||||
* @ingroup plugin_api
|
||||
*/
|
||||
interface ExecutableInterface {
|
||||
|
||||
/**
|
||||
* Executes the plugin.
|
||||
*/
|
||||
public function execute();
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Executable\ExecutableManagerInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Executable;
|
||||
|
||||
use Drupal\Component\Plugin\PluginManagerInterface;
|
||||
|
||||
/**
|
||||
* An interface for managers of executable plugins.
|
||||
*/
|
||||
interface ExecutableManagerInterface extends PluginManagerInterface {
|
||||
|
||||
/**
|
||||
* Executes an executable plugin.
|
||||
*
|
||||
* @param \Drupal\Core\Executable\ExecutableInterface $plugin
|
||||
* An executable plugin instance managed by the implementing manager.
|
||||
*
|
||||
* @throws \Drupal\Core\Executable\ExecutableException
|
||||
* If the plugin could not be executed.
|
||||
*
|
||||
* @return mixed
|
||||
* The returned data varies by plugin implementation, e.g. conditions return
|
||||
* the boolean evaluation result.
|
||||
*/
|
||||
public function execute(ExecutableInterface $plugin);
|
||||
|
||||
}
|
93
core/lib/Drupal/Core/Executable/ExecutablePluginBase.php
Normal file
93
core/lib/Drupal/Core/Executable/ExecutablePluginBase.php
Normal file
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Executable\ExecutablePluginBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Executable;
|
||||
|
||||
use Drupal\Core\Plugin\ContextAwarePluginBase;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
use Drupal\Component\Plugin\Exception\PluginException;
|
||||
|
||||
/**
|
||||
* Provides the basic architecture for executable plugins.
|
||||
*/
|
||||
abstract class ExecutablePluginBase extends ContextAwarePluginBase implements ExecutableInterface {
|
||||
|
||||
/**
|
||||
* Gets an array of definitions of available configuration options.
|
||||
*
|
||||
* @todo: This needs to go into an interface.
|
||||
*
|
||||
* @return array
|
||||
* An array of typed data definitions describing available configuration
|
||||
* options, keyed by option name.
|
||||
*/
|
||||
public function getConfigDefinitions() {
|
||||
$definition = $this->getPluginDefinition();
|
||||
if (!empty($definition['configuration'])) {
|
||||
return $definition['configuration'];
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the definition of a configuration option.
|
||||
*
|
||||
* @todo: This needs to go into an interface.
|
||||
*
|
||||
* @return array
|
||||
* The typed data definition describing the configuration option, or FALSE
|
||||
* if the option does not exist.
|
||||
*/
|
||||
public function getConfigDefinition($key) {
|
||||
$definition = $this->getPluginDefinition();
|
||||
if (!empty($definition['configuration'][$key])) {
|
||||
return $definition['configuration'][$key];
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all configuration values.
|
||||
*
|
||||
* @todo: This needs to go into an interface.
|
||||
*
|
||||
* @return array
|
||||
* The array of all configuration values, keyed by configuration option
|
||||
* name.
|
||||
*/
|
||||
public function getConfig() {
|
||||
return $this->configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a particular configuration option.
|
||||
*
|
||||
* @param string $name
|
||||
* The name of the configuration option to set.
|
||||
* @param mixed $value
|
||||
* The value to set.
|
||||
*
|
||||
* @todo This doesn't belong here. Move this into a new base class in
|
||||
* https://www.drupal.org/node/1764380.
|
||||
* @todo This does not set a value in \Drupal::config(), so the name is confusing.
|
||||
*
|
||||
* @return \Drupal\Core\Executable\ExecutablePluginBase.
|
||||
* The executable object for chaining.
|
||||
*/
|
||||
public function setConfig($key, $value) {
|
||||
if ($definition = $this->getConfigDefinition($key)) {
|
||||
$typed_data = \Drupal::typedDataManager()->create($definition, $value);
|
||||
|
||||
if ($typed_data->validate()->count() > 0) {
|
||||
throw new PluginException("The provided configuration value does not pass validation.");
|
||||
}
|
||||
}
|
||||
$this->configuration[$key] = $value;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Reference in a new issue