You are here

claro_extras.module in Claro Extras 1.0.x

File

claro_extras.module
View source
<?php

/**
 * @file
 * Contains claro_extras.module.
 */
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function claro_extras_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the claro_extras module.
    case 'help.page.claro_extras':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Provides extra administrative functionality with claro theme.') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_form_alter().
 */
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';
    }
  }
}

Functions