CustomSubmit.php in Extra Field 8.2
File
modules/extra_field_example/src/Plugin/ExtraField/Form/CustomSubmit.php
View source
<?php
namespace Drupal\extra_field_example\Plugin\ExtraField\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerTrait;
use Drupal\extra_field\Plugin\ExtraFieldFormBase;
class CustomSubmit extends ExtraFieldFormBase {
use MessengerTrait;
public function formElement(array &$form, FormStateInterface $form_state) {
$element = [
'#type' => 'submit',
'#value' => $this
->t('Custom submit'),
'#submit' => [
'::submitForm',
[
$this,
'addCustomMessage',
],
],
];
return $element;
}
public function addCustomMessage(array $form, FormStateInterface $form_state) {
$this
->messenger()
->addMessage(t('Custom submit was triggered.'));
}
}