function block_class_form_block_form_alter in Block Class 8
Implements hook_form_FORM_ID_alter().
File
- ./
block_class.module, line 53 - Adding classes to blocks.
Code
function block_class_form_block_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (\Drupal::currentUser()
->hasPermission('administer block classes')) {
$form_object = $form_state
->getFormObject();
if ($form_object instanceof EntityFormInterface) {
/** @var \Drupal\block\BlockInterface $block */
$block = $form_object
->getEntity();
// This will automatically be saved in the third party settings.
$form['third_party_settings']['#tree'] = TRUE;
$form['third_party_settings']['block_class']['classes'] = [
'#type' => 'textfield',
'#title' => t('CSS class(es)'),
'#description' => t('Customize the styling of this block by adding CSS classes. Separate multiple classes by spaces.'),
'#default_value' => $block
->getThirdPartySetting('block_class', 'classes'),
'#maxlength' => 255,
];
}
}
}