You are here

function claro_extras_form_node_form_alter in Claro Extras 1.0.x

Implements hook_form_alter().

File

./claro_extras.module, line 30
Contains claro_extras.module.

Code

function claro_extras_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $config_factory = \Drupal::configFactory();
  $admin_theme = $config_factory
    ->getEditable('system.theme')
    ->get('admin');
  if ($admin_theme !== 'claro') {
    return;
  }
  $claro_extra_settings = $config_factory
    ->getEditable('claro_extras.settings');
  if ($form_state
    ->getBuildInfo()['base_form_id'] === 'node_form') {

    /** @var \Drupal\node\NodeInterface $node */
    $node = $form_state
      ->getFormObject()
      ->getEntity();
    $claro_extras_config = $claro_extra_settings
      ->get('node_form_meta_types');
    $types_enabled = $claro_extras_config ? array_filter($claro_extras_config) : [];
    if (in_array($node
      ->bundle(), $types_enabled)) {
      $form['advanced']['#type'] = 'vertical_tabs';
      $form['meta']['#type'] = 'details';
      $form['meta']['#title'] = t('Informations');
      $form['#attached']['library'][] = 'claro_extras/claro_extras';
    }
    if ((bool) $claro_extra_settings
      ->get('enhance_paragraph_titles') === TRUE) {
      $form['#attached']['library'][] = 'claro_extras/claro_extras-paragraph_titles';
    }
    if ((bool) $claro_extra_settings
      ->get('node_breadcrumbs') === TRUE) {
      $form['#attached']['library'][] = 'claro_extras/claro_extras-node_breadcrumbs';
    }
  }
}