Drupal 8  8.0.2
BlockBase Class Reference
Inheritance diagram for BlockBase:

Public Member Functions

 label ()
 
 __construct (array $configuration, $plugin_id, $plugin_definition)
 
 getConfiguration ()
 
 setConfiguration (array $configuration)
 
 defaultConfiguration ()
 
 setConfigurationValue ($key, $value)
 
 calculateDependencies ()
 
 access (AccountInterface $account, $return_as_object=FALSE)
 
 buildConfigurationForm (array $form, FormStateInterface $form_state)
 
 blockForm ($form, FormStateInterface $form_state)
 
 validateConfigurationForm (array &$form, FormStateInterface $form_state)
 
 blockValidate ($form, FormStateInterface $form_state)
 
 submitConfigurationForm (array &$form, FormStateInterface $form_state)
 
 blockSubmit ($form, FormStateInterface $form_state)
 
 getMachineNameSuggestion ()
 
 setTransliteration (TransliterationInterface $transliteration)
 
- Public Member Functions inherited from ContextAwarePluginBase
 getContext ($name)
 
 setContext ($name, ComponentContextInterface $context)
 
 setContextValue ($name, $value)
 
 getContextMapping ()
 
 setContextMapping (array $context_mapping)
 
 getContextDefinitions ()
 
 getContextDefinition ($name)
 
- Public Member Functions inherited from ContextAwarePluginBase
 __construct (array $configuration, $plugin_id, $plugin_definition)
 
 getContextDefinitions ()
 
 getContextDefinition ($name)
 
 getContexts ()
 
 getContext ($name)
 
 setContext ($name, ContextInterface $context)
 
 getContextValues ()
 
 getContextValue ($name)
 
 setContextValue ($name, $value)
 
 validateContexts ()
 
- Public Member Functions inherited from PluginBase
 __construct (array $configuration, $plugin_id, $plugin_definition)
 
 getPluginId ()
 
 getBaseId ()
 
 getDerivativeId ()
 
 getPluginDefinition ()
 
- Public Member Functions inherited from BlockPluginInterface
 build ()
 
- Public Member Functions inherited from CacheableDependencyInterface
 getCacheContexts ()
 
 getCacheTags ()
 
 getCacheMaxAge ()
 

Protected Member Functions

 baseConfigurationDefaults ()
 
 blockAccess (AccountInterface $account)
 
 transliteration ()
 
- Protected Member Functions inherited from ContextAwarePluginBase
 createContextFromConfiguration (array $context_configuration)
 
 contextHandler ()
 
- Protected Member Functions inherited from ContextAwarePluginBase
 createContextFromConfiguration (array $context_configuration)
 

Protected Attributes

 $transliteration
 
- Protected Attributes inherited from ContextAwarePluginBase
 $context = []
 
- Protected Attributes inherited from PluginBase
 $pluginId
 
 $pluginDefinition
 
 $configuration
 

Additional Inherited Members

- Data Fields inherited from PluginBase
const DERIVATIVE_SEPARATOR = ':'
 

Detailed Description

Defines a base block implementation that most blocks plugins will extend.

This abstract class provides the generic block configuration form, default block settings, and handling for general user-defined block visibility settings.

Constructor & Destructor Documentation

__construct ( array  $configuration,
  $plugin_id,
  $plugin_definition 
)

{}

References BlockBase\setConfiguration().

Here is the call graph for this function:

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
}

Implements BlockPluginInterface.

References BlockBase\blockAccess().

Here is the call graph for this function:

baseConfigurationDefaults ( )
protected

Returns generic default configuration for block plugins.

Returns
array An associative array with the default configuration.

References BlockInterface\BLOCK_LABEL_VISIBLE, and PluginInspectionInterface\getPluginId().

Referenced by BlockBase\setConfiguration().

Here is the call graph for this function:

Here is the caller graph for this function:

blockAccess ( AccountInterface  $account)
protected

Indicates whether the block should be shown.

Blocks with specific access checking should override this method rather than access(), in order to avoid repeating the handling of the $return_as_object argument.

Parameters
\Drupal\Core\Session\AccountInterface$accountThe user session for which to check access.
Returns
The access result.
See Also
self::access()

References AccessResult\allowed().

Referenced by BlockBase\access().

Here is the call graph for this function:

Here is the caller graph for this function:

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.
}

Implements BlockPluginInterface.

Referenced by BlockBase\buildConfigurationForm().

Here is the caller graph for this function:

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()
}

Implements BlockPluginInterface.

Referenced by BlockBase\submitConfigurationForm().

Here is the caller graph for this function:

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()
}

Implements BlockPluginInterface.

Referenced by BlockBase\validateConfigurationForm().

Here is the caller graph for this function:

buildConfigurationForm ( array  $form,
FormStateInterface  $form_state 
)

{Form constructor.Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see .

Parameters
array$formAn associative array containing the initial structure of the plugin form.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the complete form.
Returns
array The form structure.
}

Creates a generic configuration form for all block types. Individual block plugins can add elements to this form by overriding BlockBase::blockForm(). Most block plugins should not override this method unless they need to alter the generic form elements.

See Also
::blockForm()

Implements PluginFormInterface.

References BlockInterface\BLOCK_LABEL_VISIBLE, BlockBase\blockForm(), PluginInspectionInterface\getPluginDefinition(), FormStateInterface\getTemporaryValue(), BlockBase\label(), and t().

Here is the call graph for this function:

calculateDependencies ( )

{Calculates dependencies for the configured plugin.Dependencies are saved in the plugin's configuration entity and are used to determine configuration synchronization order. For example, if the plugin integrates with specific user roles, this method should return an array of dependencies listing the specified roles.

Returns
array An array of dependencies grouped by type (config, content, module, theme). For example:
array(
'config' => array('user.role.anonymous', 'user.role.authenticated'),
'content' => array('node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'),
'module' => array('node', 'user'),
'theme' => array('seven'),
);
See Also
::getConfigDependencyName()
}

Implements DependentPluginInterface.

defaultConfiguration ( )

{Gets default configuration for this plugin.

Returns
array An associative array with the default configuration.
}

Implements ConfigurablePluginInterface.

Referenced by BlockBase\setConfiguration().

Here is the caller graph for this function:

getConfiguration ( )

{Gets this plugin's configuration.

Returns
array An array of this plugin's configuration.
}

Implements ConfigurablePluginInterface.

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.
}

Implements BlockPluginInterface.

References PluginInspectionInterface\getPluginDefinition(), LanguageInterface\LANGCODE_DEFAULT, Unicode\strtolower(), and BlockBase\transliteration().

Here is the call graph for this function:

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.
}

Implements BlockPluginInterface.

References PluginInspectionInterface\getPluginDefinition().

Referenced by BlockBase\buildConfigurationForm().

Here is the call graph for this function:

Here is the caller graph for this function:

setConfiguration ( array  $configuration)

{Sets the configuration for this plugin instance.

Parameters
array$configurationAn associative array containing the plugin's configuration.
}

Implements ConfigurablePluginInterface.

References BlockBase\baseConfigurationDefaults(), BlockBase\defaultConfiguration(), and NestedArray\mergeDeep().

Referenced by BlockBase\__construct().

Here is the call graph for this function:

Here is the caller graph for this function:

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
}

Implements BlockPluginInterface.

Referenced by Block\blockSubmit().

Here is the caller graph for this function:

setTransliteration ( TransliterationInterface  $transliteration)

Sets the transliteration service.

Parameters
\Drupal\Component\Transliteration\TransliterationInterface$transliterationThe transliteration service.

References BlockBase\transliteration().

Here is the call graph for this function:

submitConfigurationForm ( array &  $form,
FormStateInterface  $form_state 
)

{Form submission handler.

Parameters
array$formAn associative array containing the structure of the plugin form as built by static::buildConfigurationForm().
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the complete form.
}

Most block plugins should not override this method. To add submission handling for a specific block type, override BlockBase::blockSubmit().

See Also
::blockSubmit()

Implements PluginFormInterface.

References BlockBase\blockSubmit(), FormStateInterface\getErrors(), and FormStateInterface\getValue().

Here is the call graph for this function:

transliteration ( )
protected

Wraps the transliteration service.

Returns

References Drupal\transliteration().

Referenced by BlockBase\getMachineNameSuggestion(), and BlockBase\setTransliteration().

Here is the call graph for this function:

Here is the caller graph for this function:

validateConfigurationForm ( array &  $form,
FormStateInterface  $form_state 
)

{Form validation handler.

Parameters
array$formAn associative array containing the structure of the plugin form as built by static::buildConfigurationForm().
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the complete form.
}

Most block plugins should not override this method. To add validation for a specific block type, override BlockBase::blockValidate().

See Also
::blockValidate()

Implements PluginFormInterface.

References BlockBase\blockValidate(), and FormStateInterface\unsetValue().

Here is the call graph for this function:


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