how can I get access to fields data (Variables) of custom plugin block in twig template?
this block has been created by a module (Not a custom block type) and has its own twig template.
in below is shown structure of my module directory:
my_module
├ src
| └ Plugin
| └ Block
| └ MyBlock.php
├ templates
| └ block--my-module.html.twig
├ my_module.info.yml
└ my_module.module
MyBlock.php:
<?php
namespace Drupal\my_modules\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* @Block(
* id = "my_block",
* admin_label = @Translation("My Block"),
* category = @Translation("My Block")
* )
*/
class MyBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function blockForm($form, FormStateInterface $form_state) {
// Add a form field to the existing block configuration form.
$form['block_LinkA_url'] = array(
'#type' => 'url',
'#title' => t('Link A:'),
'#size' => 60,
);
$form['block_LinkB_url'] = array(
'#type' => 'url',
'#title' => t('Link B:'),
'#size' => 60,
);
return $form;
}
/**
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $form_state) {
// Save our custom settings when the form is submitted.
$this->configuration['LinkA_url'] = $form_state->getValue('block_LinkA_url');
$this->configuration['LinkB_url'] = $form_state->getValue('block_LinkB_url');
}
}
I'm trying to get access to for eg LinkA_url
Variable in block--my-module.html.twig
with something like below code:
<div>
{% block content %}
{{ content.LinkA_url.value }}
{% endblock %}
</div>
But whatsoever I try nothing could not be displayed , I would be happy to hear what the problem is.
Thanks for any help.