Drupal 8  8.0.2
BlockPluginInterface Interface Reference
Inheritance diagram for BlockPluginInterface:

Public Member Functions

 label ()
 
 access (AccountInterface $account, $return_as_object=FALSE)
 
 build ()
 
 setConfigurationValue ($key, $value)
 
 blockForm ($form, FormStateInterface $form_state)
 
 blockValidate ($form, FormStateInterface $form_state)
 
 blockSubmit ($form, FormStateInterface $form_state)
 
 getMachineNameSuggestion ()
 
- Public Member Functions inherited from ConfigurablePluginInterface
 getConfiguration ()
 
 setConfiguration (array $configuration)
 
 defaultConfiguration ()
 
- Public Member Functions inherited from DependentPluginInterface
 calculateDependencies ()
 
- Public Member Functions inherited from PluginFormInterface
 buildConfigurationForm (array $form, FormStateInterface $form_state)
 
 validateConfigurationForm (array &$form, FormStateInterface $form_state)
 
 submitConfigurationForm (array &$form, FormStateInterface $form_state)
 
- Public Member Functions inherited from PluginInspectionInterface
 getPluginId ()
 
 getPluginDefinition ()
 
- Public Member Functions inherited from CacheableDependencyInterface
 getCacheContexts ()
 
 getCacheTags ()
 
 getCacheMaxAge ()
 
- Public Member Functions inherited from DerivativeInspectionInterface
 getBaseId ()
 
 getDerivativeId ()
 

Detailed Description

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 brief references to the important components that are not coupled to the interface.

Member Function Documentation

access ( AccountInterface  $account,
  $return_as_object = FALSE 
)

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.

Parameters
\Drupal\Core\Session\AccountInterface$accountThe user session for which to check access.
bool$return_as_object(optional) Defaults to FALSE.
Returns
bool| The access result. Returns a boolean if $return_as_object is FALSE (this is the default) and otherwise an AccessResultInterface object. When a boolean is returned, the result of AccessInterface::isAllowed() is returned, i.e. TRUE means access is explicitly allowed, FALSE means access is either explicitly forbidden or "no opinion".
See Also

Implemented in BlockBase.

blockForm (   $form,
FormStateInterface  $form_state 
)

Returns the configuration form elements specific to this block plugin.

Blocks that need to add form elements to the normal block configuration form should implement this method.

Parameters
array$formThe form definition array for the block configuration form.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
Returns
array $form The renderable form array representing the entire configuration form.

Implemented in BlockBase, LocalTasksBlock, BlockContentBlock, BookNavigationBlock, ViewsBlock, ForumBlockBase, TestBlockInstantiation, and Broken.

blockSubmit (   $form,
FormStateInterface  $form_state 
)

Adds block type-specific submission handling for the block form.

Note that this method takes the form structure and form state for the full block configuration form as arguments, not just the elements defined in BlockPluginInterface::blockForm().

Parameters
array$formThe form definition array for the full block configuration form.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
See Also
::blockForm()
::blockValidate()

Implemented in BlockBase, ViewsBlockBase, LocalTasksBlock, BlockContentBlock, BookNavigationBlock, ViewsBlock, ForumBlockBase, and TestBlockInstantiation.

blockValidate (   $form,
FormStateInterface  $form_state 
)

Adds block type-specific validation for the block form.

Note that this method takes the form structure and form state for the full block configuration form as arguments, not just the elements defined in BlockPluginInterface::blockForm().

Parameters
array$formThe form definition array for the full block configuration form.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
See Also
::blockForm()
::blockSubmit()

Implemented in BlockBase, and ViewsBlock.

build ( )

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with cache set (with cacheability metadata indicating the circumstances for it being empty).

Returns
array A renderable array representing the content of the block.
See Also

Implemented in BlockContentBlock, SystemBrandingBlock, AggregatorFeedBlock, SystemMenuBlock, BookNavigationBlock, HelpBlock, LanguageBlock, LocalTasksBlock, UserLoginBlock, StatisticsPopularBlock, LocalActionsBlock, SystemBreadcrumbBlock, TestAccessBlock, RedirectFormBlock, AjaxFormBlock, TestBlockInstantiation, PageTitleBlock, SyndicateBlock, SystemMainBlock, SystemMessagesBlock, SearchBlock, ViewsExposedFilterBlock, AttachedRenderingBlock, TestContextAwareUnsatisfiedBlock, ShortcutsBlock, ViewsBlock, Broken, TestCacheBlock, TestFormBlock, TestHtmlBlock, ForumBlockBase, and SystemPoweredByBlock.

getMachineNameSuggestion ( )

Suggests a machine name to identify an instance of this block.

The block plugin need not verify that the machine name is at all unique. It is only responsible for providing a baseline suggestion; calling code is responsible for ensuring whatever uniqueness is required for the use case.

Returns
string The suggested machine name.

Implemented in BlockBase, and ViewsBlock.

label ( )

Returns the user-facing block label.

Todo:
Provide other specific label-related methods in https://www.drupal.org/node/2025649.
Returns
string The block label.

Implemented in BlockBase.

setConfigurationValue (   $key,
  $value 
)

Sets a particular value in the block settings.

Parameters
string$keyThe key of PluginBase::$configuration to set.
mixed$valueThe value to set for the provided key.
Todo:

This doesn't belong here. Move this into a new base class in https://www.drupal.org/node/1764380.

This does not set a value in ::config(), so the name is confusing.

See Also
::$configuration

Implemented in BlockBase.


The documentation for this interface was generated from the following file: