i have created a custom block
<?php
namespace Drupal\amu_external_search_block\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a 'amu_external_search_form_block' block.
*
* @Block(
* id = "amu_external_search_form",
* admin_label = @Translation("recherche externe"),
* )
*/
class AmuSearchFormBlock extends BlockBase implements BlockPluginInterface {
/**
* {@inheritdoc}
*/
public function build() {
$form = \Drupal::formBuilder()
->getForm('Drupal\amu_external_search_block\Form\AmuSearchForm');
$content = $form;
$elements[] = [
'#theme' => 'amu_external_search_block',
'#content' => $content,
];
return $elements;
}
/**
* Ajoute à l'instanciation du block un form input pour configurer l'url du
* submit button.
*
* {@inheritdoc}
*/
public function blockForm($form, FormStateInterface $form_state) {
$form = parent::blockForm($form, $form_state);
$config = $this->getConfiguration();
$form['submit_action_amu_external_search_form_block_settings'] = [
'#type' => 'textfield',
'#title' => $this->t('URL de recherche externe'),
'#default_value' => isset($config['submit_action_amu_external_search_form_block_settings']) ? $config['submit_action_amu_external_search_form_block_settings'] : 'https://univ-amu.summon.serialssolutions.com/#!/search?ho=t&l=fr-FR&q=',
];
$form['amu_external_search_block_description'] = [
'#type' => 'textarea',
'#title' => $this->t('Complément d\'information'),
'#default_value' => isset($config['amu_external_search_block_description']) ? $config['amu_external_search_block_description'] : '',
'#description' => 'Ajout d\'informations ou d\'un lien (code html optionnel)'
];
$form['amu_external_search_block_placeholder'] = [
'#type' => 'checkbox',
'#title' => $this->t('Afficher le placeholder'),
'#default_value' => isset($config['amu_external_search_block_placeholder']) ? $config['amu_external_search_block_placeholder'] : false,
];
$form['amu_external_search_block_title'] = [
'#type' => 'checkbox',
'#title' => $this->t('Afficher l\'étiquette de la barre de recherche externe'),
'#default_value' => isset($config['amu_external_search_block_title']) ? $config['amu_external_search_block_title'] : true,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $form_state) {
$this->configuration['submit_action_amu_external_search_form_block_settings'] = $form_state->getValue('submit_action_amu_external_search_form_block_settings');
$this->configuration['amu_external_search_block_description'] = $form_state->getValue('amu_external_search_block_description');
$this->configuration['amu_external_search_block_placeholder'] = $form_state->getValue('amu_external_search_block_placeholder');
$this->configuration['amu_external_search_block_title'] = $form_state->getValue('amu_external_search_block_title');
}
}
How to make the textfield and textarea input translatable using the block translation from the back office ?