0
  public function blockForm($form, FormStateInterface $form_state) {
    $form = parent::blockForm($form, $form_state);

    // Retrieve existing configuration for this block.
    $config = $this->getConfiguration();

    // Add a form field to the existing block configuration form.
    $form['Heading'] = array(
      '#type' => 'textfield',
      '#title' => t('Heading'),
      '#default_value' => isset($config['heading']) ? $config['heading'] : '',
    );

'#default_value' => isset($config['heading']) ? $config['heading'] : '',

can this thing be translated? And how? I use it to display a text to site users

0

The key was in creating mymodule.schema.yml in mymodule/config/schema/mymodule.schema.yml

with content of a kind

block.settings.myblock:
  type: block_settings
  mapping:
    Heading:
      type: text
      label: 'Heading'
      translatable: true

also

$config = $this->getConfiguration();

is not needed using

$this->configuration['heading']

insted

\core\modules\system\src\Plugin\Block\SystemBrandingBlock.php -- is a good example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.