TestRichTextBlock.php in Lingotek Translation 3.8.x
File
tests/modules/lingotek_test/src/Plugin/Block/TestRichTextBlock.php
View source
<?php
namespace Drupal\lingotek_test\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Form\FormStateInterface;
class TestRichTextBlock extends BlockBase implements BlockPluginInterface {
public function blockForm($form, FormStateInterface $form_state) {
$form = parent::blockForm($form, $form_state);
$form['rich_text'] = [
'#type' => 'text_format',
'#title' => $this
->t('Rich text'),
'#format' => isset($this->configuration['rich_text']['format']) ? $this->configuration['rich_text']['format'] : NULL,
'#default_value' => isset($this->configuration['rich_text']['value']) ? $this->configuration['rich_text']['value'] : '',
];
return $form;
}
public function blockSubmit($form, FormStateInterface $form_state) {
parent::blockSubmit($form, $form_state);
$this->configuration['rich_text'] = $form_state
->getValue('rich_text');
}
public function build() {
$value = isset($this->configuration['rich_text']) && isset($this->configuration['rich_text']['value']) ? $this->configuration['rich_text']['value'] : '';
$format = isset($this->configuration['rich_text']) && isset($this->configuration['rich_text']['format']) ? $this->configuration['rich_text']['format'] : 'plain_text';
return [
'#type' => 'processed_text',
'#text' => $value,
'#format' => $format,
];
}
}