I extend the EntityForm
class and I try to override a submission button, to set its HTML ID attribute (try #1). Since it doesn't work, I tried to wrap the button in a wrapper <div>
. I tried to wrap with two different ways (try #2 and try #3), but they don't work.
The only way I can override the submision button is to set '#attributes'
to set the HTML attribute class
and to add my own CSS class, but my wish was to set a HTML id
attribute. And I wanted to do this overriding in actions() method (not form()).
use Drupal\Core\Entity\ContentEntityForm;
class MyForm extends ContentEntityForm {
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
$actions['submit'] = [
'#type' => 'submit',
'#id' => 'save-button', // <-- try #1
'#value' => t('Save'),
'#ajax' => [
'callback' => '::ajaxCallback',
'event' => 'mousedown',
'wrapper' => 'bar-wrapper-1', // <-- try #2
],
'#prefix' => '<div id="bar-wrapper-2">', // <-- try #3
'#suffix' => '</div>',
'#attributes' => [
'class' => ['foo'], // <-- try #4
],
];
$actions['submit_wrapper'] = [
'#type' => 'markup',
'#markup' => '<div id="bar-wrapper-1"></div>'
];
return $actions;
}
}
I suppose I can only override the HTML ID within form()
, but it looks a little inconsistent because I can override/add a CSS class.