You are here

public function ActionGrantNodePermissions::execute in Content Access 8

Executes the plugin.

Overrides RulesActionBase::execute

File

src/Plugin/RulesAction/ActionGrantNodePermissions.php, line 64

Class

ActionGrantNodePermissions
Provides a 'Grant access by role' action.

Namespace

Drupal\content_access\Plugin\RulesAction

Code

public function execute() {
  $node = $this
    ->getContextValue('node');
  $permissions = $this
    ->getContextValue('permissions');
  if (!empty($node
    ->id()) && $this
    ->checkSetting($node)) {

    // Transform the value to the content-access format.
    $settings = $this
      ->transformRulesValue($permissions);
    $ca_settings = [];
    foreach (_content_access_get_operations() as $op => $label) {

      // Merge in the array of role-ids for each operation.
      $settings += [
        $op => [],
      ];
      $ca_settings[$op] = array_keys(array_flip(content_access_per_node_setting($op, $node)) + array_flip($settings[$op]));
    }
    content_access_save_per_node_settings($node, $ca_settings);
    $this
      ->aquireGrants($node);
  }
}