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
71
core/lib/Drupal/Core/Annotation/Action.php
Normal file
71
core/lib/Drupal/Core/Annotation/Action.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Annotation\Action.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
|
||||
/**
|
||||
* Defines an Action annotation object.
|
||||
*
|
||||
* Plugin Namespace: Plugin\Action
|
||||
*
|
||||
* For a working example, see \Drupal\node\Plugin\Action\UnpublishNode
|
||||
*
|
||||
* @see \Drupal\Core\Action\ActionInterface
|
||||
* @see \Drupal\Core\Action\ActionManager
|
||||
* @see \Drupal\Core\Action\ActionBase
|
||||
* @see plugin_api
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class Action extends Plugin {
|
||||
|
||||
/**
|
||||
* The plugin ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* The human-readable name of the action plugin.
|
||||
*
|
||||
* @ingroup plugin_translatable
|
||||
*
|
||||
* @var \Drupal\Core\Annotation\Translation
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* The route name for a confirmation form for this action.
|
||||
*
|
||||
* @todo Provide a more generic way to allow an action to be confirmed first.
|
||||
*
|
||||
* @var string (optional)
|
||||
*/
|
||||
public $confirm_form_route_name = '';
|
||||
|
||||
/**
|
||||
* The entity type the action can apply to.
|
||||
*
|
||||
* @todo Replace with \Drupal\Core\Plugin\Context\Context.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = '';
|
||||
|
||||
/**
|
||||
* The category under which the action should be listed in the UI.
|
||||
*
|
||||
* @var \Drupal\Core\Annotation\Translation
|
||||
*
|
||||
* @ingroup plugin_translatable
|
||||
*/
|
||||
public $category;
|
||||
|
||||
}
|
139
core/lib/Drupal/Core/Annotation/ContextDefinition.php
Normal file
139
core/lib/Drupal/Core/Annotation/ContextDefinition.php
Normal file
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Annotation\ContextDefinition.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
use Drupal\Core\StringTranslation\TranslationWrapper;
|
||||
|
||||
/**
|
||||
* @defgroup plugin_context Annotation for context definition
|
||||
* @{
|
||||
* Describes how to use ContextDefinition annotation.
|
||||
*
|
||||
* When providing plugin annotations, contexts can be defined to support UI
|
||||
* interactions through providing limits, and mapping contexts to appropriate
|
||||
* plugins. Context definitions can be provided as such:
|
||||
* @code
|
||||
* context = {
|
||||
* "node" = @ContextDefinition("entity:node")
|
||||
* }
|
||||
* @endcode
|
||||
* Remove spaces after @ in your actual plugin - these are put into this sample
|
||||
* code so that it is not recognized as an annotation.
|
||||
*
|
||||
* To add a label to a context definition use the "label" key:
|
||||
* @code
|
||||
* context = {
|
||||
* "node" = @ContextDefinition("entity:node", label = @Translation("Node"))
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* Contexts are required unless otherwise specified. To make an optional
|
||||
* context use the "required" key:
|
||||
* @code
|
||||
* context = {
|
||||
* "node" = @ContextDefinition("entity:node", required = FALSE, label = @Translation("Node"))
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* To define multiple contexts, simply provide different key names in the
|
||||
* context array:
|
||||
* @code
|
||||
* context = {
|
||||
* "artist" = @ContextDefinition("entity:node", label = @Translation("Artist")),
|
||||
* "album" = @ContextDefinition("entity:node", label = @Translation("Album"))
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* Specifying a default value for the context definition:
|
||||
* @code
|
||||
* context = {
|
||||
* "message" = @ContextDefinition("string",
|
||||
* label = @Translation("Message"),
|
||||
* default_value = @Translation("Checkout complete! Thank you for your purchase.")
|
||||
* )
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @see annotation
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines a context definition annotation object.
|
||||
*
|
||||
* Some plugins require various data contexts in order to function. This class
|
||||
* supports that need by allowing the contexts to be easily defined within an
|
||||
* annotation and return a ContextDefinitionInterface implementing class.
|
||||
*
|
||||
* @Annotation
|
||||
*
|
||||
* @ingroup plugin_context
|
||||
*/
|
||||
class ContextDefinition extends Plugin {
|
||||
|
||||
/**
|
||||
* The ContextDefinitionInterface object.
|
||||
*
|
||||
* @var \Drupal\Core\Plugin\Context\ContextDefinitionInterface
|
||||
*/
|
||||
protected $definition;
|
||||
|
||||
/**
|
||||
* Constructs a new context definition object.
|
||||
*
|
||||
* @param array $values
|
||||
* An associative array with the following keys:
|
||||
* - value: The required data type.
|
||||
* - label: (optional) The UI label of this context definition.
|
||||
* - required: (optional) Whether the context definition is required.
|
||||
* - multiple: (optional) Whether the context definition is multivalue.
|
||||
* - description: (optional) The UI description of this context definition.
|
||||
* - default_value: (optional) The default value in case the underlying
|
||||
* value is not set.
|
||||
* - class: (optional) A custom ContextDefinitionInterface class.
|
||||
*
|
||||
* @throws \Exception
|
||||
* Thrown when the class key is specified with a non
|
||||
* ContextDefinitionInterface implementing class.
|
||||
*/
|
||||
public function __construct(array $values) {
|
||||
$values += array(
|
||||
'required' => TRUE,
|
||||
'multiple' => FALSE,
|
||||
'default_value' => NULL,
|
||||
);
|
||||
// Annotation classes extract data from passed annotation classes directly
|
||||
// used in the classes they pass to.
|
||||
foreach (['label', 'description'] as $key) {
|
||||
// @todo Remove this workaround in https://www.drupal.org/node/2362727.
|
||||
if (isset($values[$key]) && $values[$key] instanceof TranslationWrapper) {
|
||||
$values[$key] = (string) $values[$key]->get();
|
||||
}
|
||||
else {
|
||||
$values[$key] = NULL;
|
||||
}
|
||||
}
|
||||
if (isset($values['class']) && !in_array('Drupal\Core\Plugin\Context\ContextDefinitionInterface', class_implements($values['class']))) {
|
||||
throw new \Exception('ContextDefinition class must implement \Drupal\Core\Plugin\Context\ContextDefinitionInterface.');
|
||||
}
|
||||
$class = isset($values['class']) ? $values['class'] : 'Drupal\Core\Plugin\Context\ContextDefinition';
|
||||
$this->definition = new $class($values['value'], $values['label'], $values['required'], $values['multiple'], $values['description'], $values['default_value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of an annotation.
|
||||
*
|
||||
* @return \Drupal\Core\Plugin\Context\ContextDefinitionInterface
|
||||
*/
|
||||
public function get() {
|
||||
return $this->definition;
|
||||
}
|
||||
|
||||
}
|
52
core/lib/Drupal/Core/Annotation/Mail.php
Normal file
52
core/lib/Drupal/Core/Annotation/Mail.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Annotation\Mail.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
|
||||
/**
|
||||
* Defines a Mail annotation object.
|
||||
*
|
||||
* Plugin Namespace: Plugin\Mail
|
||||
*
|
||||
* For a working example, see \Drupal\Core\Mail\Plugin\Mail\PhpMail
|
||||
*
|
||||
* @see \Drupal\Core\Mail\MailInterface
|
||||
* @see \Drupal\Core\Mail\MailManager
|
||||
* @see plugin_api
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class Mail extends Plugin {
|
||||
|
||||
/**
|
||||
* The plugin ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* The human-readable name of the mail plugin.
|
||||
*
|
||||
* @var \Drupal\Core\Annotation\Translation
|
||||
*
|
||||
* @ingroup plugin_translatable
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* A short description of the mail plugin.
|
||||
*
|
||||
* @var \Drupal\Core\Annotation\Translation
|
||||
*
|
||||
* @ingroup plugin_translatable
|
||||
*/
|
||||
public $description;
|
||||
|
||||
}
|
65
core/lib/Drupal/Core/Annotation/QueueWorker.php
Normal file
65
core/lib/Drupal/Core/Annotation/QueueWorker.php
Normal file
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Annotation\QueueWorker.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
|
||||
/**
|
||||
* Declare queue workers that need to be run periodically.
|
||||
*
|
||||
* While there can be only one hook_cron() process running at the same time,
|
||||
* there can be any number of processes defined here running. Because of
|
||||
* this, long running tasks are much better suited for this API. Items queued
|
||||
* in hook_cron() might be processed in the same cron run if there are not many
|
||||
* items in the queue, otherwise it might take several requests, which can be
|
||||
* run in parallel.
|
||||
*
|
||||
* You can create queues, add items to them, claim them, etc. without using a
|
||||
* QueueWorker plugin if you want, however, you need to take care of processing
|
||||
* the items in the queue in that case. See \Drupal\Core\Cron for an example.
|
||||
*
|
||||
* Plugin Namespace: Plugin\QueueWorker
|
||||
*
|
||||
* For a working example, see
|
||||
* \Drupal\aggregator\Plugin\QueueWorker\AggregatorRefresh.
|
||||
*
|
||||
* @see \Drupal\Core\Queue\QueueWorkerInterface
|
||||
* @see \Drupal\Core\Queue\QueueWorkerBase
|
||||
* @see \Drupal\Core\Queue\QueueWorkerManager
|
||||
* @see plugin_api
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class QueueWorker extends Plugin {
|
||||
|
||||
/**
|
||||
* The plugin ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* The human-readable title of the plugin.
|
||||
*
|
||||
* @ingroup plugin_translatable
|
||||
*
|
||||
* @var \Drupal\Core\Annotation\Translation
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* An associative array containing the optional key:
|
||||
* - time: (optional) How much time Drupal cron should spend on calling
|
||||
* this worker in seconds. Defaults to 15.
|
||||
*
|
||||
* @var array (optional)
|
||||
*/
|
||||
public $cron;
|
||||
|
||||
}
|
99
core/lib/Drupal/Core/Annotation/Translation.php
Normal file
99
core/lib/Drupal/Core/Annotation/Translation.php
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Annotation\Translation.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\AnnotationBase;
|
||||
use Drupal\Core\StringTranslation\TranslationWrapper;
|
||||
|
||||
/**
|
||||
* @defgroup plugin_translatable Annotation for translatable text
|
||||
* @{
|
||||
* Describes how to put translatable UI text into annotations.
|
||||
*
|
||||
* When providing plugin annotation, properties whose values are displayed in
|
||||
* the user interface should be made translatable. Much the same as how user
|
||||
* interface text elsewhere is wrapped in t() to make it translatable, in plugin
|
||||
* annotation, wrap translatable strings in the @ Translation() annotation.
|
||||
* For example:
|
||||
* @code
|
||||
* title = @ Translation("Title of the plugin"),
|
||||
* @endcode
|
||||
* Remove spaces after @ in your actual plugin - these are put into this sample
|
||||
* code so that it is not recognized as annotation.
|
||||
*
|
||||
* To provide replacement values for placeholders, use the "arguments" array:
|
||||
* @code
|
||||
* title = @ Translation("Bundle !title", arguments = {"!title" = "Foo"}),
|
||||
* @endcode
|
||||
*
|
||||
* It is also possible to provide a context with the text, similar to t():
|
||||
* @code
|
||||
* title = @ Translation("Bundle", context = "Validation"),
|
||||
* @endcode
|
||||
* Other t() arguments like language code are not valid to pass in. Only
|
||||
* context is supported.
|
||||
*
|
||||
* @see i18n
|
||||
* @see annotation
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines a translatable annotation object.
|
||||
*
|
||||
* Some metadata within an annotation needs to be translatable. This class
|
||||
* supports that need by allowing both the translatable string and, if
|
||||
* specified, a context for that string. The string (with optional context)
|
||||
* is passed into t().
|
||||
*
|
||||
* @ingroup plugin_translatable
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class Translation extends AnnotationBase {
|
||||
|
||||
/**
|
||||
* The string translation object.
|
||||
*
|
||||
* @var \Drupal\Core\StringTranslation\TranslationWrapper
|
||||
*/
|
||||
protected $translation;
|
||||
|
||||
/**
|
||||
* Constructs a new class instance.
|
||||
*
|
||||
* Parses values passed into this class through the t() function in Drupal and
|
||||
* handles an optional context for the string.
|
||||
*
|
||||
* @param array $values
|
||||
* Possible array keys:
|
||||
* - value (required): the string that is to be translated.
|
||||
* - arguments (optional): an array with placeholder replacements, keyed by
|
||||
* placeholder.
|
||||
* - context (optional): a string that describes the context of "value";
|
||||
*/
|
||||
public function __construct(array $values) {
|
||||
$string = $values['value'];
|
||||
$arguments = isset($values['arguments']) ? $values['arguments'] : array();
|
||||
$options = array();
|
||||
if (!empty($values['context'])) {
|
||||
$options = array(
|
||||
'context' => $values['context'],
|
||||
);
|
||||
}
|
||||
$this->translation = new TranslationWrapper($string, $arguments, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get() {
|
||||
return $this->translation;
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue