You are here

public function FormAlter::blockAddConfigureAlter in Inline Block Title Automatic 8

Invoked for implementations of hook form alter for layout builder.

File

src/FormAlter.php, line 48

Class

FormAlter
A bridge for the alter hooks.

Namespace

Drupal\inline_block_title_automatic

Code

public function blockAddConfigureAlter(&$form, FormStateInterface $form_state, $form_id) {

  // Only alter the block configuration forms for inline or reusable
  // block_content entity blocks, since they are primarily the ones afflicted
  // with the conflict described above.
  $is_reusable_block_content = $form['settings']['provider']['#value'] === 'block_content';
  $is_inline_block = isset($form['settings']['block_form']['#block']) && $form['settings']['block_form']['#block'] instanceof BlockContent;
  if (!$is_reusable_block_content && !$is_inline_block) {
    return;
  }

  // Hide the label of the block placement and provide a default value if it
  // is empty.
  $form['settings']['label']['#type'] = 'value';
  if (empty($form['settings']['label']['#default_value'])) {
    $form['settings']['label']['#default_value'] = 'Inline block';
  }

  // Default to hiding the label of the block.
  $form['settings']['label_display']['#default_value'] = FALSE;
  $form['settings']['label_display']['#type'] = 'value';
}