You are here

form_mode_manager.install in Form mode manager 8

Same filename and directory in other branches
  1. 8.2 form_mode_manager.install

Install, update and uninstall functions for the Form Mode Manager module.

File

form_mode_manager.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the Form Mode Manager module.
 */

/**
 * Implements hook_install().
 */
function form_mode_manager_install() {
  _form_mode_manager_exclude_commerce_form_mode();
}

/**
 * Set the default Form Mode Manager general/links settings.
 */
function form_mode_manager_update_8001() {

  // Set the default Form Mode Manager general settings.
  \Drupal::configFactory()
    ->getEditable('form_mode_manager.settings')
    ->set("form_modes.user.to_exclude", [
    'register' => 'register',
  ])
    ->save(TRUE);

  // Set the default Form Mode Manager links settings.
  $config_links = \Drupal::configFactory()
    ->getEditable('form_mode_manager.links');
  $form_modes = array_keys(\Drupal::service('entity_display.repository')
    ->getAllFormModes());
  foreach ($form_modes as $entity_type_id) {
    $config_links
      ->set("local_tasks.{$entity_type_id}.position", 'secondary');
  }
  $config_links
    ->save(TRUE);
}

/**
 * Set "add_to_cart" Form Mode excluded from Form mode manager settings.
 */
function form_mode_manager_update_8002() {
  _form_mode_manager_exclude_commerce_form_mode();
}

/**
 * Exclude from form mode manager configuration the incompatible form modes.
 *
 * Add_to_cart are provided by commerce 'order',
 * and aren't compatible with form mode manager.
 */
function _form_mode_manager_exclude_commerce_form_mode() {
  if (\Drupal::moduleHandler()
    ->moduleExists('order')) {
    \Drupal::configFactory()
      ->getEditable('form_mode_manager.settings')
      ->set("form_modes.commerce_order_item.to_exclude", [
      'add_to_cart' => 'add_to_cart',
    ])
      ->save(TRUE);
    \Drupal::entityTypeManager()
      ->clearCachedDefinitions();
  }
}

Functions

Namesort descending Description
form_mode_manager_install Implements hook_install().
form_mode_manager_update_8001 Set the default Form Mode Manager general/links settings.
form_mode_manager_update_8002 Set "add_to_cart" Form Mode excluded from Form mode manager settings.
_form_mode_manager_exclude_commerce_form_mode Exclude from form mode manager configuration the incompatible form modes.