You are here

function content_access_save_per_node_settings in Content Access 8

Same name and namespace in other branches
  1. 5 content_access.module \content_access_save_per_node_settings()
  2. 6 content_access.module \content_access_save_per_node_settings()
  3. 7 content_access.module \content_access_save_per_node_settings()

Saves custom per node settings in the own content_access table.

3 calls to content_access_save_per_node_settings()
ActionGrantNodePermissions::execute in src/Plugin/RulesAction/ActionGrantNodePermissions.php
Executes the plugin.
ActionRevokeNodePermissions::execute in src/Plugin/RulesAction/ActionRevokeNodePermissions.php
Executes the plugin.
ContentAccessPageForm::submitForm in src/Form/ContentAccessPageForm.php
Form submission handler.

File

./content_access.module, line 514
Content access module file.

Code

function content_access_save_per_node_settings(NodeInterface $node, $settings) {
  $database = \Drupal::database();
  $count = $database
    ->select('content_access')
    ->fields('c', [
    'settings',
  ])
    ->condition('nid', $node
    ->id())
    ->countQuery()
    ->execute()
    ->fetchField();
  if ($count > 0) {
    $database
      ->update('content_access')
      ->condition('nid', $node
      ->id())
      ->fields([
      'settings' => serialize($settings),
    ])
      ->execute();
  }
  else {
    $database
      ->insert('content_access')
      ->fields([
      'nid' => $node
        ->id(),
      'settings' => serialize($settings),
    ])
      ->execute();
  }

  // Make content_access_per_node_setting() use the new settings.
  content_access_per_node_setting(NULL, $node, $settings);
}