ValidationErrorBlock.php in Drupal 9
File
core/modules/settings_tray/tests/modules/settings_tray_test/src/Plugin/Block/ValidationErrorBlock.php
View source
<?php
namespace Drupal\settings_tray_test\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
class ValidationErrorBlock extends BlockBase {
public function build() {
return [
'#markup' => '<span>If I had more time this would be very witty :(.</span>',
];
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::validateConfigurationForm($form, $form_state);
$form_state
->setError($form['label'], 'Sorry system error. Please save again.');
}
}