I request somebody to please explain why I have to use ['#attributes']
when adding one or a combination of CSS class
-es to the Submit
button inside a search-block-form
but when changing just the Text, ['#attributes']
is not required?
To change default text of the button I am writing:
function ezone_form_search_block_form_alter($&form, &$form_state, $form_id){
$form['actions']['submit']['#value'] = t('Search now');
}
But when adding a CSS class to the same button I have to write this:
function ezone_form_search_block_form_alter(&$form, &$form_state, $form_id){
$form['actions']['submit']['#attributes']['class'][] = 'btn btn-primary';
}
Why although value
and class
both are attributes of a button element, I have to do them differently? If I take out the ['#attributes']
part ($form['actions']['submit']['#class'][] = 'btn btn-primary';
) button classes don't not render.
I Googled but could not find anything specific about it! It would be great if someone can put lights on this. I am a new comer at Drupal platform!