Security update to Drupal 8.4.6
[yaffs-website] / web / core / modules / block / tests / modules / block_test / src / Plugin / Block / TestSettingsValidationBlock.php
1 <?php
2
3 namespace Drupal\block_test\Plugin\Block;
4
5 use Drupal\Core\Block\BlockBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Provides a test settings validation block.
10  *
11  * @Block(
12  *  id = "test_settings_validation",
13  *  admin_label = @Translation("Test settings validation block"),
14  * )
15  */
16 class TestSettingsValidationBlock extends BlockBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function blockForm($form, FormStateInterface $form_state) {
22     return ['digits' => ['#type' => 'textfield']] + $form;
23   }
24
25   /**
26    * {@inheritdoc}
27    */
28   public function blockValidate($form, FormStateInterface $form_state) {
29     if (!ctype_digit($form_state->getValue('digits'))) {
30       $form_state->setErrorByName('digits', $this->t('Only digits are allowed'));
31     }
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public function build() {
38     return ['#markup' => 'foo'];
39   }
40
41 }