book-2.0.x-dev/book.install

book.install
<?php

/**
 * @file
 * Install, update and uninstall functions for the book module.
 */

/**
 * Implements hook_uninstall().
 */
function book_uninstall(): void {
  // Clear book data out of the cache.
  \Drupal::cache('data')->deleteAll();
}

/**
 * Implements hook_schema().
 */
function book_schema(): array {
  $schema['book'] = [
    'description' => 'Stores book outline information. Uniquely defines the location of each node in the book outline',
    'fields' => [
      'nid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => "The book page's {node}.nid.",
      ],
      'bid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => "The book ID is the {book}.nid of the top-level page.",
      ],
      'pid' => [
        'description' => 'The parent ID (pid) is the id of the node above in the hierarchy, or zero if the node is at the top level in its outline.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'has_children' => [
        'description' => 'Flag indicating whether any nodes have this node as a parent (1 = children exist, 0 = no children).',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'small',
      ],
      'weight' => [
        'description' => 'Weight among book entries in the same book at the same depth.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'depth' => [
        'description' => 'The depth relative to the top level. A link with pid == 0 will have depth == 1.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'small',
      ],
      'p1' => [
        'description' => 'The first nid in the materialized path. If N = depth, then pN must equal the nid. If depth > 1 then p(N-1) must equal the pid. All pX where X > depth must equal zero. The columns p1 .. p9 are also called the parents.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'p2' => [
        'description' => 'The second nid in the materialized path. See p1.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'p3' => [
        'description' => 'The third nid in the materialized path. See p1.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'p4' => [
        'description' => 'The fourth nid in the materialized path. See p1.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'p5' => [
        'description' => 'The fifth nid in the materialized path. See p1.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'p6' => [
        'description' => 'The sixth nid in the materialized path. See p1.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'p7' => [
        'description' => 'The seventh nid in the materialized path. See p1.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'p8' => [
        'description' => 'The eighth nid in the materialized path. See p1.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'p9' => [
        'description' => 'The ninth nid in the materialized path. See p1.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => ['nid'],
    'indexes' => [
      'book_parents' => ['bid', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9'],
    ],
  ];

  return $schema;
}

/**
 * Update Book permissions.
 *
 * Grant 'add any content to books' permission to all roles with 'administer
 * book outlines' permission for backward compatibility.
 *
 * @throws \Drupal\Core\Entity\EntityStorageException
 * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
 * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
 */
function book_update_103001(): void {
  $roles = \Drupal::entityTypeManager()
    ->getStorage('user_role')
    ->loadMultiple();
  foreach ($roles as $role) {
    if ($role->hasPermission('administer book outlines')) {
      $role->grantPermission('add any content to books');
      $role->save();
    }
  }
}

/**
 * Add book_sort key to book configuration.
 */
function book_update_103002(): void {
  $config_factory = \Drupal::configFactory();
  $config_factory->getEditable('book.settings')
    ->set('book_sort', 'weight')
    ->save(TRUE);
}

/**
 * Add reorder book pages permission to those who can edit outline.
 */
function book_update_103003(): void {
  $roles = \Drupal::entityTypeManager()
    ->getStorage('user_role')
    ->loadMultiple();
  foreach ($roles as $role) {
    if ($role->hasPermission('administer book outlines')) {
      $role->grantPermission('reorder book pages');
      $role->save();
    }
  }
}

/**
 * Remove book.navigation.mode from book settings config.
 */
function book_update_103004(): void {
  $config_factory = \Drupal::configFactory();
  $config_factory->getEditable('book.settings')->clear('block')->save();
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc