You are here

function node_install in Drupal 8

Same name and namespace in other branches
  1. 7 modules/node/node.install \node_install()
  2. 9 core/modules/node/node.install \node_install()
  3. 10 core/modules/node/node.install \node_install()

Implements hook_install().

File

core/modules/node/node.install, line 124
Install, update and uninstall functions for the node module.

Code

function node_install() {

  // Enable default permissions for system roles.
  // IMPORTANT: Modules SHOULD NOT automatically grant any user role access
  // permissions in hook_install().
  // However, the 'access content' permission is a very special case, since
  // there is hardly a point in installing the Node module without granting
  // these permissions. Doing so also allows tests to continue to operate as
  // expected without first having to manually grant these default permissions.
  if (\Drupal::moduleHandler()
    ->moduleExists('user')) {
    user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
      'access content',
    ]);
    user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, [
      'access content',
    ]);
  }

  // Populate the node access table.
  Database::getConnection()
    ->insert('node_access')
    ->fields([
    'nid' => 0,
    'gid' => 0,
    'realm' => 'all',
    'grant_view' => 1,
    'grant_update' => 0,
    'grant_delete' => 0,
  ])
    ->execute();
}