You are here

meta_position.module in Meta position 8

File

meta_position.module
View source
<?php

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

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

    // Main module help for the meta_position module.
    case 'help.page.meta_position':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Provide settings to change the default position of the metadata panel on node edit form.') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function meta_position_form_node_form_alter(&$form, FormStateInterface &$form_state, $form_id) {
  $form['#process'][] = 'meta_position_form_node_form_process';
}

/**
 * Process function for altering node form.
 */
function meta_position_form_node_form_process(&$form, FormStateInterface &$form_state) {

  // Set advanced settings in node form as verticals tabs.
  $config = \Drupal::config('meta_position.settings');
  $enabled = $config
    ->get('enabled');
  $node_types = $config
    ->get('node_types');
  if ($enabled) {

    /** @var \Drupal\node\NodeInterface $node */
    $node = $form_state
      ->getFormObject()
      ->getEntity();
    $types_enabled = $node_types ?: [];
    if (in_array($node
      ->bundle(), $types_enabled) || empty($types_enabled)) {
      $form['advanced']['#type'] = 'vertical_tabs';
      $form['meta']['#type'] = 'details';
      $form['meta']['#title'] = t('Information');
      $form['#attached']['library'][] = 'meta_position/node_meta';
    }
  }
  return $form;
}

Functions

Namesort descending Description
meta_position_form_node_form_alter Implements hook_form_BASE_FORM_ID_alter().
meta_position_form_node_form_process Process function for altering node form.
meta_position_help Implements hook_help().