Commit d77275ff authored by webchick's avatar webchick

Issue #1391694 by tim.plunkett, aspilicious, fago, pounard, plach, Crell,...

Issue #1391694 by tim.plunkett, aspilicious, fago, pounard, plach, Crell, msonnabaum, tstoeckler: Use type-hinting for entity-parameters.
parent 3b5fd77f
<?php
/**
* @file
* Contains \Drupal\aggregator\Plugin\Core\Entity\FeedInterface.
*/
namespace Drupal\aggregator;
use Drupal\Core\Entity\ContentEntityInterface;
/**
* Provides an interface defining an aggregator feed entity.
*/
interface FeedInterface extends ContentEntityInterface {
}
<?php
/**
* @file
* Contains \Drupal\aggregator\Plugin\Core\Entity\ItemInterface.
*/
namespace Drupal\aggregator;
use Drupal\Core\Entity\ContentEntityInterface;
/**
* Provides an interface defining an aggregator item entity.
*/
interface ItemInterface extends ContentEntityInterface {
}
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
namespace Drupal\aggregator\Plugin\Core\Entity; namespace Drupal\aggregator\Plugin\Core\Entity;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityNG; use Drupal\Core\Entity\EntityNG;
use Drupal\Core\Entity\Annotation\EntityType; use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation; use Drupal\Core\Annotation\Translation;
use Drupal\aggregator\FeedInterface;
/** /**
* Defines the aggregator feed entity class. * Defines the aggregator feed entity class.
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
* } * }
* ) * )
*/ */
class Feed extends EntityNG implements ContentEntityInterface { class Feed extends EntityNG implements FeedInterface {
/** /**
* The feed ID. * The feed ID.
......
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
namespace Drupal\aggregator\Plugin\Core\Entity; namespace Drupal\aggregator\Plugin\Core\Entity;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityNG; use Drupal\Core\Entity\EntityNG;
use Drupal\Core\Entity\Annotation\EntityType; use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation; use Drupal\Core\Annotation\Translation;
use Drupal\aggregator\ItemInterface;
/** /**
* Defines the aggregator item entity class. * Defines the aggregator item entity class.
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
* } * }
* ) * )
*/ */
class Item extends EntityNG implements ContentEntityInterface { class Item extends EntityNG implements ItemInterface {
/** /**
* The feed item ID. * The feed item ID.
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* A renderable array of data, as returned from the build() implementation of * A renderable array of data, as returned from the build() implementation of
* the plugin that defined the block: * the plugin that defined the block:
* - #title: The default localized title of the block. * - #title: The default localized title of the block.
* @param \Drupal\block\BlockInterface $block * @param \Drupal\block\BlockPluginInterface $block
* The block instance. * The block instance.
* *
* @see hook_block_view_ID_alter() * @see hook_block_view_ID_alter()
...@@ -51,7 +51,7 @@ function hook_block_view_alter(array &$build, \Drupal\block\Plugin\Core\Entity\B ...@@ -51,7 +51,7 @@ function hook_block_view_alter(array &$build, \Drupal\block\Plugin\Core\Entity\B
* A renderable array of data, as returned from the build() implementation of * A renderable array of data, as returned from the build() implementation of
* the plugin that defined the block: * the plugin that defined the block:
* - #title: The default localized title of the block. * - #title: The default localized title of the block.
* @param \Drupal\block\BlockInterface $block * @param \Drupal\block\BlockPluginInterface $block
* The block instance. * The block instance.
* *
* @todo Add a more specific example of a block ID, and illustrate how this is * @todo Add a more specific example of a block ID, and illustrate how this is
...@@ -60,7 +60,7 @@ function hook_block_view_alter(array &$build, \Drupal\block\Plugin\Core\Entity\B ...@@ -60,7 +60,7 @@ function hook_block_view_alter(array &$build, \Drupal\block\Plugin\Core\Entity\B
* @see hook_block_view_alter() * @see hook_block_view_alter()
* @see hook_block_view_NAME_alter() * @see hook_block_view_NAME_alter()
*/ */
function hook_block_view_ID_alter(array &$build, \Drupal\block\BlockInterface $block) { function hook_block_view_ID_alter(array &$build, \Drupal\block\BlockPluginInterface $block) {
// This code will only run for a specific block. For example, if ID // This code will only run for a specific block. For example, if ID
// in the function definition above is set to "someid", the code // in the function definition above is set to "someid", the code
// will only run on the "someid" block. // will only run on the "someid" block.
...@@ -79,7 +79,7 @@ function hook_block_view_ID_alter(array &$build, \Drupal\block\BlockInterface $b ...@@ -79,7 +79,7 @@ function hook_block_view_ID_alter(array &$build, \Drupal\block\BlockInterface $b
* A renderable array of data, as returned from the build() implementation of * A renderable array of data, as returned from the build() implementation of
* the plugin that defined the block: * the plugin that defined the block:
* - #title: The default localized title of the block. * - #title: The default localized title of the block.
* @param \Drupal\block\BlockInterface $block * @param \Drupal\block\BlockPluginInterface $block
* The block instance. * The block instance.
* *
* @todo NAME is ambiguous, and so is the example here. Use a more specific * @todo NAME is ambiguous, and so is the example here. Use a more specific
...@@ -89,7 +89,7 @@ function hook_block_view_ID_alter(array &$build, \Drupal\block\BlockInterface $b ...@@ -89,7 +89,7 @@ function hook_block_view_ID_alter(array &$build, \Drupal\block\BlockInterface $b
* @see hook_block_view_alter() * @see hook_block_view_alter()
* @see hook_block_view_ID_alter() * @see hook_block_view_ID_alter()
*/ */
function hook_block_view_NAME_alter(array &$build, \Drupal\block\BlockInterface $block) { function hook_block_view_NAME_alter(array &$build, \Drupal\block\BlockPluginInterface $block) {
// This code will only run for a specific block instance. For example, if NAME // This code will only run for a specific block instance. For example, if NAME
// in the function definition above is set to "someid", the code will only run // in the function definition above is set to "someid", the code will only run
// on the "someid" block. // on the "someid" block.
......
<?php
/**
* @file
* Contains \Drupal\custom_block\Plugin\Core\Entity\CustomBlockInterface.
*/
namespace Drupal\custom_block;
use Drupal\Core\Entity\ContentEntityInterface;
/**
* Provides an interface defining a custom block entity.
*/
interface CustomBlockInterface extends ContentEntityInterface {
/**
* Sets the theme value.
*
* When creating a new custom block from the block library, the user is
* redirected to the configure form for that block in the given theme. The
* theme is stored against the block when the custom block add form is shown.
*
* @param string $theme
* The theme name.
*/
public function setTheme($theme);
/**
* Gets the theme value.
*
* When creating a new custom block from the block library, the user is
* redirected to the configure form for that block in the given theme. The
* theme is stored against the block when the custom block add form is shown.
*
* @return string
* The theme name.
*/
public function getTheme();
}
<?php
/**
* @file
* Contains \Drupal\custom_block\Plugin\Core\Entity\CustomBlockTypeInterface.
*/
namespace Drupal\custom_block;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Provides an interface defining a custom block type entity.
*/
interface CustomBlockTypeInterface extends ConfigEntityInterface {
}
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
namespace Drupal\custom_block\Plugin\Core\Entity; namespace Drupal\custom_block\Plugin\Core\Entity;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityNG; use Drupal\Core\Entity\EntityNG;
use Drupal\Core\Entity\Annotation\EntityType; use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation; use Drupal\Core\Annotation\Translation;
use Drupal\custom_block\CustomBlockInterface;
/** /**
* Defines the custom block entity class. * Defines the custom block entity class.
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
* } * }
* ) * )
*/ */
class CustomBlock extends EntityNG implements ContentEntityInterface { class CustomBlock extends EntityNG implements CustomBlockInterface {
/** /**
* The block ID. * The block ID.
...@@ -151,28 +151,14 @@ public function getRevisionId() { ...@@ -151,28 +151,14 @@ public function getRevisionId() {
} }
/** /**
* Sets the theme value. * {@inheritdoc}
*
* When creating a new custom block from the block library, the user is
* redirected to the configure form for that block in the given theme. The
* theme is stored against the block when the custom block add form is shown.
*
* @param string $theme
* The theme name.
*/ */
public function setTheme($theme) { public function setTheme($theme) {
$this->theme = $theme; $this->theme = $theme;
} }
/** /**
* Gets the theme value. * {@inheritdoc}
*
* When creating a new custom block from the block library, the user is
* redirected to the configure form for that block in the given theme. The
* theme is stored against the block when the custom block add form is shown.
*
* @return string
* The theme name.
*/ */
public function getTheme() { public function getTheme() {
return $this->theme; return $this->theme;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\Annotation\EntityType; use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation; use Drupal\Core\Annotation\Translation;
use Drupal\custom_block\CustomBlockTypeInterface;
/** /**
* Defines the custom block type entity. * Defines the custom block type entity.
...@@ -33,7 +34,7 @@ ...@@ -33,7 +34,7 @@
* } * }
* ) * )
*/ */
class CustomBlockType extends ConfigEntityBase { class CustomBlockType extends ConfigEntityBase implements CustomBlockTypeInterface {
/** /**
* The custom block type ID. * The custom block type ID.
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* block settings, and handling for general user-defined block visibility * block settings, and handling for general user-defined block visibility
* settings. * settings.
*/ */
abstract class BlockBase extends PluginBase implements BlockInterface { abstract class BlockBase extends PluginBase implements BlockPluginInterface {
/** /**
* The entity using this plugin. * The entity using this plugin.
...@@ -118,7 +118,7 @@ public function blockAccess() { ...@@ -118,7 +118,7 @@ public function blockAccess() {
} }
/** /**
* Implements \Drupal\block\BlockInterface::access(). * Implements \Drupal\block\BlockPluginInterface::access().
* *
* Adds the user-configured per-role, per-path, and per-language visibility * Adds the user-configured per-role, per-path, and per-language visibility
* settings to all blocks, and invokes hook_block_access(). * settings to all blocks, and invokes hook_block_access().
...@@ -212,7 +212,7 @@ public function access() { ...@@ -212,7 +212,7 @@ public function access() {
} }
/** /**
* Implements \Drupal\block\BlockInterface::form(). * Implements \Drupal\block\BlockPluginInterface::form().
* *
* Creates a generic configuration form for all block types. Individual * Creates a generic configuration form for all block types. Individual
* block plugins can add elements to this form by overriding * block plugins can add elements to this form by overriding
...@@ -419,7 +419,7 @@ public function blockForm($form, &$form_state) { ...@@ -419,7 +419,7 @@ public function blockForm($form, &$form_state) {
} }
/** /**
* Implements \Drupal\block\BlockInterface::validate(). * Implements \Drupal\block\BlockPluginInterface::validate().
* *
* Most block plugins should not override this method. To add validation * Most block plugins should not override this method. To add validation
* for a specific block type, override BlockBase::blockValdiate(). * for a specific block type, override BlockBase::blockValdiate().
...@@ -459,7 +459,7 @@ public function validate($form, &$form_state) { ...@@ -459,7 +459,7 @@ public function validate($form, &$form_state) {
public function blockValidate($form, &$form_state) {} public function blockValidate($form, &$form_state) {}
/** /**
* Implements \Drupal\block\BlockInterface::submit(). * Implements \Drupal\block\BlockPluginInterface::submit().
* *
* Most block plugins should not override this method. To add submission * Most block plugins should not override this method. To add submission
* handling for a specific block type, override BlockBase::blockSubmit(). * handling for a specific block type, override BlockBase::blockSubmit().
......
...@@ -2,104 +2,24 @@ ...@@ -2,104 +2,24 @@
/** /**
* @file * @file
* Contains \Drupal\block\BlockInterface. * Contains \Drupal\block\Plugin\Core\Entity\BlockInterface.
*/ */
namespace Drupal\block; namespace Drupal\block;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/** /**
* Defines the required interface for all block plugins. * Provides an interface defining a block entity.
*
* @todo Add detailed documentation here explaining the block system's
* architecture and the relationships between the various objects, including
* brif references to the important components that are not coupled to the
* interface.
*
* @see \Drupal\block\BlockBase
*/ */
interface BlockInterface { interface BlockInterface extends ConfigEntityInterface {
/**
* Returns the default settings for this block plugin.
*
* @return array
* An associative array of block settings for this block, keyed by the
* setting name.
*
* @todo Consider merging this with the general plugin configuration member
* variable and its getter/setter in http://drupal.org/node/1764380.
*/
public function settings();
/**
* Indicates whether the block should be shown.
*
* This method allows base implementations to add general access restrictions
* that should apply to all extending block plugins.
*
* @return bool
* TRUE if the block should be shown, or FALSE otherwise.
*
* @see \Drupal\block\BlockAccessController
*/
public function access();
/**
* Constructs the block configuration form.
*
* This method allows base implementations to add a generic configuration
* form for extending block plugins.
*
* @param array $form
* The form definition array for the block configuration form.
* @param array $form_state
* An array containing the current state of the configuration form.
*
* @return array $form
* The renderable form array representing the entire configuration form.
*
* @see \Drupal\block\BlockFormController::form()
* @see \Drupal\block\BlockInterace::validate()
* @see \Drupal\block\BlockInterace::submit()
*/
public function form($form, &$form_state);
/** /**
* Handles form validation for the block configuration form. * Returns the plugin instance.
*
* @param array $form
* The form definition array for the block configuration form.
* @param array $form_state
* An array containing the current state of the configuration form.
*
* @see \Drupal\block\BlockFormController::validate()
* @see \Drupal\block\BlockInterace::form()
* @see \Drupal\block\BlockInterace::submit()
*/
public function validate($form, &$form_state);
/**
* Handles form submissions for the block configuration form.
*
* @param array $form
* The form definition array for the block configuration form.
* @param array $form_state
* An array containing the current state of the configuration form.
*
* @see \Drupal\block\BlockFormController::submit()
* @see \Drupal\block\BlockInterace::form()
* @see \Drupal\block\BlockInterace::validate()
*/
public function submit($form, &$form_state);
/**
* Builds and returns the renderable array for this block plugin.
*
* @return array
* A renderable array representing the content of the block.
* *
* @see \Drupal\block\BlockRenderController * @return \Drupal\block\BlockPluginInterface
* The plugin instance for this block.
*/ */
public function build(); public function getPlugin();
} }
<?php
/**
* @file
* Contains \Drupal\block\BlockPluginInterface.
*/
namespace Drupal\block;
/**
* Defines the required interface for all block plugins.
*
* @todo Add detailed documentation here explaining the block system's
* architecture and the relationships between the various objects, including
* brif references to the important components that are not coupled to the
* interface.
*
* @see \Drupal\block\BlockBase
*/
interface BlockPluginInterface {
/**
* Returns the default settings for this block plugin.
*
* @return array
* An associative array of block settings for this block, keyed by the
* setting name.
*
* @todo Consider merging this with the general plugin configuration member
* variable and its getter/setter in http://drupal.org/node/1764380.
*/
public function settings();
/**
* Indicates whether the block should be shown.
*
* This method allows base implementations to add general access restrictions
* that should apply to all extending block plugins.
*
* @return bool
* TRUE if the block should be shown, or FALSE otherwise.
*
* @see \Drupal\block\BlockAccessController
*/
public function access();
/**
* Constructs the block configuration form.
*
* This method allows base implementations to add a generic configuration
* form for extending block plugins.
*
* @param array $form
* The form definition array for the block configuration form.
* @param array $form_state
* An array containing the current state of the configuration form.
*
* @return array $form
* The renderable form array representing the entire configuration form.
*
* @see \Drupal\block\BlockFormController::form()
* @see \Drupal\block\BlockInterace::validate()
* @see \Drupal\block\BlockInterace::submit()
*/
public function form($form, &$form_state);
/**
* Handles form validation for the block configuration form.
*
* @param array $form
* The form definition array for the block configuration form.
* @param array $form_state
* An array containing the current state of the configuration form.
*
* @see \Drupal\block\BlockFormController::validate()
* @see \Drupal\block\BlockInterace::form()
* @see \Drupal\block\BlockInterace::submit()
*/
public function validate($form, &$form_state);
/**
* Handles form submissions for the block configuration form.
*
* @param array $form
* The form definition array for the block configuration form.
* @param array $form_state
* An array containing the current state of the configuration form.
*
* @see \Drupal\block\BlockFormController::submit()
* @see \Drupal\block\BlockInterace::form()
* @see \Drupal\block\BlockInterace::validate()
*/