You are here

lightning_layout.install in Lightning Layout 8

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

Contains installation and update routines for Lightning Layout.

File

lightning_layout.install
View source
<?php

/**
 * @file
 * Contains installation and update routines for Lightning Layout.
 */
use Drupal\lightning_core\ConfigHelper as Config;
use Drupal\node\Entity\NodeType;
use Drupal\user\Entity\Role;

/**
 * Implements hook_install().
 */
function lightning_layout_install() {

  // Set up layout_manager permissions.
  lightning_layout_update_8003();

  // Add layout permissions to Lightning Roles' content role configuration.
  if (\Drupal::moduleHandler()
    ->moduleExists('lightning_roles')) {
    lightning_layout_modules_installed([
      'lightning_roles',
    ]);
  }
}

/**
 * Installs Panelizer and default configuration for landing page content type.
 */
function lightning_layout_update_8001() {
  \Drupal::service('module_installer')
    ->install([
    'panelizer',
  ]);
  \Drupal::service('config.installer')
    ->installDefaultConfig('module', 'lightning_layout');
}

/**
 * Creates the layout_manager role.
 */
function lightning_layout_update_8002() {
  Config::forModule('lightning_layout')
    ->getEntity('user_role', 'layout_manager')
    ->save();
}

/**
 * Adds Panelizer permissions to layout_manager role.
 */
function lightning_layout_update_8003() {
  $node_types = NodeType::loadMultiple();
  array_walk($node_types, 'lightning_layout_node_type_insert');
}

/**
 * Removed in Lightning 8.x-2.05.
 *
 * Formerly installed Panelizer defaults for the landing_page content type.
 */
function lightning_layout_update_8004() {
}

/**
 * Removed in Lightning 8.x-2.06.
 *
 * Formerly added Panels and Panelizer permissions to content roles.
 */
function lightning_layout_update_8005() {
}

/**
 * Removes administrative privileges from layout_manager role.
 */
function lightning_layout_update_8006() {
  $role_storage = \Drupal::entityTypeManager()
    ->getStorage('user_role');

  /** @var \Drupal\user\RoleInterface[] $roles */
  $roles = $role_storage
    ->loadByProperties([
    'is_admin' => TRUE,
  ]);
  $keys = array_keys($roles);
  sort($keys);
  if ($keys == [
    'administrator',
    'layout_manager',
  ]) {
    $roles['layout_manager']
      ->setIsAdmin(FALSE)
      ->grantPermission('administer node display')
      ->grantPermission('administer panelizer')
      ->save();
    lightning_layout_update_8003();
  }
}

/**
 * Creates Lightning Layout settings config object and installs Entity Blocks.
 */
function lightning_layout_update_8007() {
  Config::forModule('lightning_layout')
    ->get('lightning_layout.settings')
    ->save();
  \Drupal::service('module_installer')
    ->install([
    'entity_block',
  ]);
}

/**
 * Installs the Panelizer Quick Edit module.
 */
function lightning_layout_update_8008() {
  \Drupal::service('module_installer')
    ->install([
    'panelizer_quickedit',
  ]);
}

/**
 * Removes the Lightning third_party_settings from Layout Manager role.
 */
function lightning_layout_update_8009() {
  $role = Role::load('layout_manager');
  if ($role) {
    $role
      ->unsetThirdPartySetting('lightning', 'bundled');
    $role
      ->save();
  }
}

Functions

Namesort descending Description
lightning_layout_install Implements hook_install().
lightning_layout_update_8001 Installs Panelizer and default configuration for landing page content type.
lightning_layout_update_8002 Creates the layout_manager role.
lightning_layout_update_8003 Adds Panelizer permissions to layout_manager role.
lightning_layout_update_8004 Removed in Lightning 8.x-2.05.
lightning_layout_update_8005 Removed in Lightning 8.x-2.06.
lightning_layout_update_8006 Removes administrative privileges from layout_manager role.
lightning_layout_update_8007 Creates Lightning Layout settings config object and installs Entity Blocks.
lightning_layout_update_8008 Installs the Panelizer Quick Edit module.
lightning_layout_update_8009 Removes the Lightning third_party_settings from Layout Manager role.