form_mode_manager-8.x-1.x-dev/form_mode_manager.install
form_mode_manager.install
<?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 module weight to higher than "content_translation" to be
// able to alter its routes.
module_set_weight('form_mode_manager', 11);
}
/**
* Implements hook_module_preinstall().
*/
function form_mode_manager_module_preinstall($module) {
\Drupal::configFactory()->getEditable('form_mode_manager.settings')
->set("form_modes.user.to_exclude", ['register' => 'register'])
->save(TRUE);
}
/**
* 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();
}
}
/**
* Set weight higher than "content_translation" to alter its routes.
*/
function form_mode_manager_update_8003() {
module_set_weight('form_mode_manager', 11);
}
