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
58
core/lib/Drupal/Core/Display/Annotation/DisplayVariant.php
Normal file
58
core/lib/Drupal/Core/Display/Annotation/DisplayVariant.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Display\Annotation\DisplayVariant.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Display\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
|
||||
/**
|
||||
* Defines a display variant annotation object.
|
||||
*
|
||||
* Display variants are used to dictate the output of a given Display, which
|
||||
* can be used to control the output of many parts of Drupal.
|
||||
*
|
||||
* Variants are usually chosen by some selection criteria, and are instantiated
|
||||
* directly. Each variant must define its own approach to rendering, and can
|
||||
* either load its own data or be injected with data from another Display
|
||||
* object.
|
||||
*
|
||||
* @todo: Revise description when/if Displays are added to core:
|
||||
* https://www.drupal.org/node/2292733
|
||||
*
|
||||
* Plugin namespace: Plugin\DisplayVariant
|
||||
*
|
||||
* For working examples, see
|
||||
* - \Drupal\Core\Render\Plugin\DisplayVariant\SimplePageVariant
|
||||
* - \Drupal\block\Plugin\DisplayVariant\BlockPageVariant
|
||||
*
|
||||
* @see \Drupal\Core\Display\VariantInterface
|
||||
* @see \Drupal\Core\Display\VariantBase
|
||||
* @see \Drupal\Core\Display\VariantManager
|
||||
* @see \Drupal\Core\Display\PageVariantInterface
|
||||
* @see plugin_api
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class DisplayVariant extends Plugin {
|
||||
|
||||
/**
|
||||
* The plugin ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* The administrative label.
|
||||
*
|
||||
* @var \Drupal\Core\Annotation\Translation
|
||||
*
|
||||
* @ingroup plugin_translatable
|
||||
*/
|
||||
public $admin_label = '';
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Display\Annotation\PageDisplayVariant.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Display\Annotation;
|
||||
|
||||
/**
|
||||
* Defines a page display variant annotation object.
|
||||
*
|
||||
* Page display variants are a specific type of display variant, intended to
|
||||
* render entire pages. They must render the crucial parts of a page, which are:
|
||||
* - the title
|
||||
* - the main content
|
||||
* - any messages (#type => status_messages)
|
||||
*
|
||||
* @see \Drupal\Core\Display\VariantInterface
|
||||
* @see \Drupal\Core\Display\PageVariantInterface
|
||||
* @see \Drupal\Core\Display\VariantBase
|
||||
* @see \Drupal\Core\Display\VariantManager
|
||||
* @see plugin_api
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class PageDisplayVariant extends DisplayVariant {
|
||||
|
||||
}
|
39
core/lib/Drupal/Core/Display/PageVariantInterface.php
Normal file
39
core/lib/Drupal/Core/Display/PageVariantInterface.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Display\PageVariantInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Display;
|
||||
|
||||
/**
|
||||
* Provides an interface for PageDisplayVariant plugins.
|
||||
*
|
||||
* Page display variants are a specific type of DisplayVariant, intended for
|
||||
* "pages", which always have some main content to be rendered. Hence page
|
||||
* display variants may choose to render that main content in a certain way:
|
||||
* decorated in a certain way, laid out in a certain way, et cetera.
|
||||
*
|
||||
* For example, the \Drupal\block\Plugin\DisplayVariant\FullPageVariant page
|
||||
* display variant is used by the Block module to control regions and output
|
||||
* blocks placed in those regions.
|
||||
*
|
||||
* @see \Drupal\Core\Display\Annotation\DisplayVariant
|
||||
* @see \Drupal\Core\Display\VariantBase
|
||||
* @see \Drupal\Core\Display\VariantManager
|
||||
* @see plugin_api
|
||||
*/
|
||||
interface PageVariantInterface extends VariantInterface {
|
||||
|
||||
/**
|
||||
* Sets the main content for the page being rendered.
|
||||
*
|
||||
* @param array $main_content
|
||||
* The render array representing the main content.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMainContent(array $main_content);
|
||||
|
||||
}
|
140
core/lib/Drupal/Core/Display/VariantBase.php
Normal file
140
core/lib/Drupal/Core/Display/VariantBase.php
Normal file
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Display\VariantBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Display;
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\PluginBase;
|
||||
use Drupal\Core\Plugin\PluginDependencyTrait;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
||||
/**
|
||||
* Provides a base class for DisplayVariant plugins.
|
||||
*
|
||||
* @see \Drupal\Core\Display\Annotation\DisplayVariant
|
||||
* @see \Drupal\Core\Display\VariantInterface
|
||||
* @see \Drupal\Core\Display\VariantManager
|
||||
* @see plugin_api
|
||||
*/
|
||||
abstract class VariantBase extends PluginBase implements VariantInterface {
|
||||
|
||||
use PluginDependencyTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
|
||||
$this->setConfiguration($configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function label() {
|
||||
return $this->configuration['label'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function adminLabel() {
|
||||
return $this->pluginDefinition['admin_label'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function id() {
|
||||
return $this->configuration['uuid'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getWeight() {
|
||||
return (int) $this->configuration['weight'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setWeight($weight) {
|
||||
$this->configuration['weight'] = (int) $weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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(
|
||||
'label' => '',
|
||||
'uuid' => '',
|
||||
'weight' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function calculateDependencies() {
|
||||
return $this->dependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
$form['label'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Label'),
|
||||
'#description' => $this->t('The label for this display variant.'),
|
||||
'#default_value' => $this->label(),
|
||||
'#maxlength' => '255',
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->configuration['label'] = $form_state->getValue('label');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access(AccountInterface $account = NULL) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
87
core/lib/Drupal/Core/Display/VariantInterface.php
Normal file
87
core/lib/Drupal/Core/Display/VariantInterface.php
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Display\VariantInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Display;
|
||||
|
||||
use Drupal\Component\Plugin\ConfigurablePluginInterface;
|
||||
use Drupal\Component\Plugin\PluginInspectionInterface;
|
||||
use Drupal\Core\Plugin\PluginFormInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for DisplayVariant plugins.
|
||||
*
|
||||
* @see \Drupal\Core\Display\Annotation\DisplayVariant
|
||||
* @see \Drupal\Core\Display\VariantBase
|
||||
* @see \Drupal\Core\Display\VariantManager
|
||||
* @see plugin_api
|
||||
*/
|
||||
interface VariantInterface extends PluginInspectionInterface, ConfigurablePluginInterface, PluginFormInterface {
|
||||
|
||||
/**
|
||||
* Returns the user-facing display variant label.
|
||||
*
|
||||
* @return string
|
||||
* The display variant label.
|
||||
*/
|
||||
public function label();
|
||||
|
||||
/**
|
||||
* Returns the admin-facing display variant label.
|
||||
*
|
||||
* This is for the type of display variant, not the configured variant itself.
|
||||
*
|
||||
* @return string
|
||||
* The display variant administrative label.
|
||||
*/
|
||||
public function adminLabel();
|
||||
|
||||
/**
|
||||
* Returns the unique ID for the display variant.
|
||||
*
|
||||
* @return string
|
||||
* The display variant ID.
|
||||
*/
|
||||
public function id();
|
||||
|
||||
/**
|
||||
* Returns the weight of the display variant.
|
||||
*
|
||||
* @return int
|
||||
* The display variant weight.
|
||||
*/
|
||||
public function getWeight();
|
||||
|
||||
/**
|
||||
* Sets the weight of the display variant.
|
||||
*
|
||||
* @param int $weight
|
||||
* The weight to set.
|
||||
*/
|
||||
public function setWeight($weight);
|
||||
|
||||
/**
|
||||
* Determines if this display variant is accessible.
|
||||
*
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* (optional) The user for which to check access, or NULL to check access
|
||||
* for the current user. Defaults to NULL.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if this display variant is accessible, FALSE otherwise.
|
||||
*/
|
||||
public function access(AccountInterface $account = NULL);
|
||||
|
||||
/**
|
||||
* Builds and returns the renderable array for the display variant.
|
||||
*
|
||||
* @return array
|
||||
* A render array for the display variant.
|
||||
*/
|
||||
public function build();
|
||||
|
||||
}
|
42
core/lib/Drupal/Core/Display/VariantManager.php
Normal file
42
core/lib/Drupal/Core/Display/VariantManager.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Display\VariantManager.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Display;
|
||||
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Plugin\DefaultPluginManager;
|
||||
|
||||
/**
|
||||
* Manages discovery of display variant plugins.
|
||||
*
|
||||
* @see \Drupal\Core\Display\Annotation\DisplayVariant
|
||||
* @see \Drupal\Core\Display\VariantInterface
|
||||
* @see \Drupal\Core\Display\VariantBase
|
||||
* @see plugin_api
|
||||
*/
|
||||
class VariantManager extends DefaultPluginManager {
|
||||
|
||||
/**
|
||||
* Constructs a new VariantManager.
|
||||
*
|
||||
* @param \Traversable $namespaces
|
||||
* An object that implements \Traversable which contains the root paths
|
||||
* keyed by the corresponding namespace to look for plugin implementations.
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
|
||||
* Cache backend instance to use.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler to invoke the alter hook with.
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
|
||||
parent::__construct('Plugin/DisplayVariant', $namespaces, $module_handler, 'Drupal\Core\Display\VariantInterface', 'Drupal\Core\Display\Annotation\DisplayVariant');
|
||||
|
||||
$this->setCacheBackend($cache_backend, 'variant_plugins');
|
||||
$this->alterInfo('display_variant_plugin');
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue