3 namespace Drupal\block_test\Plugin\Block;
5 use Drupal\Core\Block\BlockBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Provides a test settings validation block.
12 * id = "test_settings_validation",
13 * admin_label = @Translation("Test settings validation block"),
16 class TestSettingsValidationBlock extends BlockBase {
21 public function blockForm($form, FormStateInterface $form_state) {
22 return ['digits' => ['#type' => 'textfield']] + $form;
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'));
37 public function build() {
38 return ['#markup' => 'foo'];