Advertisement
Guest User

Untitled

a guest
Apr 21st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Drupal\example_block\Plugin\Block;
  4.  
  5.  
  6. use Drupal\Core\Block\BlockBase;
  7. use Drupal\Core\Block\BlockPluginInterface;
  8. use Drupal\Core\Form\FormStateInterface;
  9.  
  10.  
  11. /**
  12. * Provides a Eventbrite attendees list Block.
  13. *
  14. * @Block(
  15. * id = "example_block_id",
  16. * admin_label = @Translation("My example block")
  17. * )
  18. */
  19. class ExampleBlock extends BlockBase implements BlockPluginInterface
  20. {
  21. /**
  22. * Return the block contents
  23. *
  24. * {@inheritdoc}
  25. */
  26. public function build()
  27. {
  28. $config = $this->getConfiguration();
  29.  
  30. return "Hello {$config['some_text']}";
  31. }
  32.  
  33. /**
  34. * Return a Form API array
  35. *
  36. * {@inheritdoc}
  37. */
  38. public function blockForm($form, FormStateInterface $form_state)
  39. {
  40. $form = parent::blockForm($form, $form_state);
  41.  
  42. $config = $this->getConfiguration();
  43.  
  44. $form['some_text'] = [
  45. '#type' => 'textfield',
  46. '#title' => $this->t('Some Text'),
  47. '#default_value' => isset($config['some_text']) ? $config['some_text'] : 'Jonathan',
  48. ];
  49.  
  50. return $form;
  51. }
  52.  
  53. /**
  54. * Update the configuration values from the form state
  55. *
  56. * {@inheritdoc}
  57. */
  58. public function blockSubmit($form, FormStateInterface $form_state)
  59. {
  60. $this->configuration['some_text'] = $form_state->getValue('some_text');
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement