Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Drupal\example_block\Plugin\Block;
- use Drupal\Core\Block\BlockBase;
- use Drupal\Core\Block\BlockPluginInterface;
- use Drupal\Core\Form\FormStateInterface;
- /**
- * Provides a Eventbrite attendees list Block.
- *
- * @Block(
- * id = "example_block_id",
- * admin_label = @Translation("My example block")
- * )
- */
- class ExampleBlock extends BlockBase implements BlockPluginInterface
- {
- /**
- * Return the block contents
- *
- * {@inheritdoc}
- */
- public function build()
- {
- $config = $this->getConfiguration();
- return "Hello {$config['some_text']}";
- }
- /**
- * Return a Form API array
- *
- * {@inheritdoc}
- */
- public function blockForm($form, FormStateInterface $form_state)
- {
- $form = parent::blockForm($form, $form_state);
- $config = $this->getConfiguration();
- $form['some_text'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Some Text'),
- '#default_value' => isset($config['some_text']) ? $config['some_text'] : 'Jonathan',
- ];
- return $form;
- }
- /**
- * Update the configuration values from the form state
- *
- * {@inheritdoc}
- */
- public function blockSubmit($form, FormStateInterface $form_state)
- {
- $this->configuration['some_text'] = $form_state->getValue('some_text');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement