TestLayoutFormWithValidation.php in Layout Builder UX 8
File
tests/modules/lb_ux_test/src/Plugin/Layout/TestLayoutFormWithValidation.php
View source
<?php
namespace Drupal\lb_ux_test\Plugin\Layout;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Layout\LayoutDefault;
class TestLayoutFormWithValidation extends LayoutDefault {
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::validateConfigurationForm($form, $form_state);
if ($form_state
->getValue('label') !== 'Abracadabra') {
$form_state
->setErrorByName('label', "That's not the magic word!");
}
}
}