BlockFieldTestContentBlock.php in Block field 8
File
tests/modules/block_field_test/src/Plugin/Block/BlockFieldTestContentBlock.php
View source
<?php
namespace Drupal\block_field_test\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
class BlockFieldTestContentBlock extends BlockBase {
public function defaultConfiguration() {
return [
'content' => $this
->t('A default value. This block was created at @time', [
'@time' => date('Y-m-d h:i:sa'),
]),
];
}
public function blockForm($form, FormStateInterface $form_state) {
$form['content'] = [
'#type' => 'textarea',
'#title' => $this
->t('Content'),
'#default_value' => $this->configuration['content'],
];
return $form;
}
public function blockSubmit($form, FormStateInterface $form_state) {
$this->configuration['content'] = $form_state
->getValue('content');
}
public function build() {
return [
'#type' => 'markup',
'#markup' => $this->configuration['content'],
'#attributes' => [
'class' => [
'block-field-test-content-block--custom-class',
],
'data-custom-attr' => 'block-field-test-content-block--custom-data-attribute',
],
];
}
}