You are here

content_access.install in Content Access 8

Content access install file.

File

content_access.install
View source
<?php

/**
 * @file
 * Content access install file.
 */
use Drupal\user\Entity\Role;

/**
 * Implements hook_install().
 */
function content_access_install() {
  $config = \Drupal::configFactory()
    ->getEditable('content_access.settings');
  $roles_gids = [];
  $roles = Role::loadMultiple();
  $i = 1;
  foreach ($roles as $role) {
    $roles_gids[$i] = $role
      ->id();
    $i++;
  }
  $config
    ->set('content_access_roles_gids', array_flip($roles_gids))
    ->save();
}

/**
 * Implements hook_uninstall().
 */
function content_access_uninstall() {
  content_access_disabling(TRUE);
}

/**
 * Implements hook_schema().
 */
function content_access_schema() {
  $schema['content_access'] = [
    'fields' => [
      'nid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'settings' => [
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'medium',
      ],
    ],
    'primary key' => [
      'nid',
    ],
  ];
  return $schema;
}

Functions