BlockPluginTrait
trait BlockPluginTrait (View source)
| internal | This trait is used internally by the block system. Block plugins should extend \Drupal\Core\Block\BlockBase. |
Provides the base implementation of a block plugin.
Traits
Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.
Provides a trait for the messenger service.
Provides a trait with typical behavior for plugins which have forms.
Properties
| protected TranslationInterface | $stringTranslation | The string translation service. |
from StringTranslationTrait |
| protected MessengerInterface | $messenger | The messenger. |
from MessengerTrait |
| protected TransliterationInterface | $transliteration | The transliteration service. |
Methods
Translates a string to the current language or to a given language.
Formats a string containing a count of items.
Returns the number of plurals supported by a given language.
Gets the string translation service.
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
Returns generic default configuration for block plugins.
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
Wraps the transliteration service.
Details
protected TranslatableMarkup
t(string $string, array $args = [], array $options = [])
Translates a string to the current language or to a given language.
See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.
In order for strings to be localized, make them available in one of the ways supported by the
protected
formatPlural($count, $singular, $plural, array $args = [], array $options = [])
Formats a string containing a count of items.
protected
getNumberOfPlurals($langcode = NULL)
Returns the number of plurals supported by a given language.
protected TranslationInterface
getStringTranslation()
Gets the string translation service.
$this
setStringTranslation(TranslationInterface $translation)
Sets the string translation service to use.
setMessenger(MessengerInterface $messenger)
Sets the messenger.
MessengerInterface
messenger()
Gets the messenger.
getFormClass($operation)
{@inheritdoc}
hasFormClass($operation)
{@inheritdoc}
label()
{@inheritdoc}
__construct(array $configuration, $plugin_id, $plugin_definition)
{@inheritdoc}
getConfiguration()
{@inheritdoc}
setConfiguration(array $configuration)
{@inheritdoc}
protected array
baseConfigurationDefaults()
Returns generic default configuration for block plugins.
defaultConfiguration()
{@inheritdoc}
setConfigurationValue($key, $value)
{@inheritdoc}
calculateDependencies()
{@inheritdoc}
access(AccountInterface $account, $return_as_object = FALSE)
{@inheritdoc}
protected AccessResult
blockAccess(AccountInterface $account)
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.
buildConfigurationForm(array $form, FormStateInterface $form_state)
{@inheritdoc}
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.
blockForm($form, FormStateInterface $form_state)
{@inheritdoc}
validateConfigurationForm(array $form, FormStateInterface $form_state)
{@inheritdoc}
Most block plugins should not override this method. To add validation for a specific block type, override BlockBase::blockValidate().
blockValidate($form, FormStateInterface $form_state)
{@inheritdoc}
submitConfigurationForm(array $form, FormStateInterface $form_state)
{@inheritdoc}
Most block plugins should not override this method. To add submission handling for a specific block type, override BlockBase::blockSubmit().
blockSubmit($form, FormStateInterface $form_state)
{@inheritdoc}
getMachineNameSuggestion()
{@inheritdoc}
getPreviewFallbackString()
{@inheritdoc}
protected TransliterationInterface
transliteration()
Wraps the transliteration service.
setTransliteration(TransliterationInterface $transliteration)
Sets the transliteration service.