BlockWithAlteredSettings.php in Panopoly Magic 8.2
File
tests/modules/panopoly_magic_preview_test/src/Plugin/Block/BlockWithAlteredSettings.php
View source
<?php
namespace Drupal\panopoly_magic_preview_test\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
class BlockWithAlteredSettings extends BlockBase {
public function defaultConfiguration() {
return [
'message' => 'The default message',
];
}
public function blockForm($form, FormStateInterface $form_state) {
$config = $this
->getConfiguration();
$form['message'] = [
'#type' => 'textfield',
'#title' => $this
->t('Message'),
'#default_value' => $config['message'],
];
return $form;
}
public function blockSubmit($form, FormStateInterface $form_state) {
$config = $this
->getConfiguration();
$config['message'] = $form_state
->getValue('message');
$this
->setConfiguration($config);
}
public function build() {
$config = $this
->getConfiguration();
return [
'#markup' => 'BlockWithAlteredSettings: ' . $config['message'],
];
}
}