node.install
Same filename and directory in other branches
Install, update and uninstall functions for the node module.
File
-
core/
modules/ node/ node.install
View source
<?php
/**
* @file
* Install, update and uninstall functions for the node module.
*/
use Drupal\Core\Database\Database;
use Drupal\Core\Database\SchemaDefinition\Column;
use Drupal\Core\Database\SchemaDefinition\ColumnSize;
use Drupal\Core\Database\SchemaDefinition\ForeignKey;
use Drupal\Core\Database\SchemaDefinition\IntValue;
use Drupal\Core\Database\SchemaDefinition\PrimaryKey;
use Drupal\Core\Database\SchemaDefinition\Schema;
use Drupal\Core\Database\SchemaDefinition\SchemaDefinitionType;
use Drupal\Core\Database\SchemaDefinition\StringValue;
use Drupal\Core\Database\SchemaDefinition\Table;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
/**
* Implements hook_schema().
*/
function node_schema() : Schema {
$tables[] = new Table(name: 'node_access', description: 'Identifies which realm/grant pairs a user must possess in order to view, update, or delete specific nodes.', columns: [
Column::int(name: 'nid', description: 'The {node}.nid this record affects.', unsigned: TRUE, notNull: TRUE, default: new IntValue(0)),
Column::varcharAscii(name: 'langcode', description: 'The {language}.langcode of this node.', length: 12, notNull: TRUE, default: new StringValue('')),
Column::int(name: 'fallback', description: 'Boolean indicating whether this record should be used as a fallback if a language condition is not provided.', size: ColumnSize::Tiny, unsigned: TRUE, notNull: TRUE, default: new IntValue(1)),
Column::int(name: 'gid', description: "The grant ID a user must possess in the specified realm to gain this row's privileges on the node.", unsigned: TRUE, notNull: TRUE, default: new IntValue(0)),
Column::varcharAscii(name: 'realm', description: 'The realm in which the user must possess the grant ID. Modules can define one or more realms by implementing hook_node_grants().', length: 255, notNull: TRUE, default: new StringValue('')),
Column::int(name: 'grant_view', description: 'Boolean indicating whether a user with the realm/grant pair can view this node.', size: ColumnSize::Tiny, unsigned: TRUE, notNull: TRUE, default: new IntValue(0)),
Column::int(name: 'grant_update', description: 'Boolean indicating whether a user with the realm/grant pair can edit this node.', size: ColumnSize::Tiny, unsigned: TRUE, notNull: TRUE, default: new IntValue(0)),
Column::int(name: 'grant_delete', description: 'Boolean indicating whether a user with the realm/grant pair can delete this node.', size: ColumnSize::Tiny, unsigned: TRUE, notNull: TRUE, default: new IntValue(0)),
], primaryKey: new PrimaryKey([
'nid',
'gid',
'realm',
'langcode',
]), foreignKeys: [
new ForeignKey(name: 'affected_node', foreignTable: 'node', columns: [
'nid',
], foreignColumns: [
'nid',
]),
]);
return new Schema(type: SchemaDefinitionType::Module, name: 'node', tables: $tables);
}
/**
* Implements hook_install().
*/
function node_install() : void {
// 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')) {
Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)?->grantPermissions([
'access content',
])?->save();
Role::loadOverrideFree(RoleInterface::AUTHENTICATED_ID)?->grantPermissions([
'access content',
])?->save();
}
// 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();
}
/**
* Implements hook_uninstall().
*/
function node_uninstall() : void {
// Delete remaining general module variables.
\Drupal::state()->delete('node.node_access_needs_rebuild');
}
/**
* Implements hook_update_last_removed().
*/
function node_update_last_removed() : int {
return 8700;
}
Functions
| Title | Deprecated | Summary |
|---|---|---|
| node_install | Implements hook_install(). | |
| node_schema | Implements hook_schema(). | |
| node_uninstall | Implements hook_uninstall(). | |
| node_update_last_removed | Implements hook_update_last_removed(). |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.