I extend a EntityForm
where I try to override a submit button, especially to set HTML id
attribute of the submit button (try #1). Because it doesn’t work, I try to wrap the button in a wrapper . I tried to wrap with two different ways (try #2 and try #3), but it doesn’t work.
The only way I can override the submit button is to set '#attributes'
to add an own HTML class
attribute.
But my wish was to set HTML id
attribute.
use DrupalCoreEntityContentEntityForm;
class MyForm extends ContentEntityForm {
...
...
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
// submit button (<button type="button"> in tagging form)
$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
attribute within the form() method, but it looks a little inconsistent because I can override/add class
attribute, but why not the id
attribute?