You are here

public function DomainAccessRemove::execute in Domain Access 8

Executes the plugin.

Overrides ExecutableInterface::execute

File

domain_access/src/Plugin/Action/DomainAccessRemove.php, line 21

Class

DomainAccessRemove
Removes a node from a domain.

Namespace

Drupal\domain_access\Plugin\Action

Code

public function execute($entity = NULL) {
  $id = $this->configuration['domain_id'];
  $node_domains = \Drupal::service('domain_access.manager')
    ->getAccessValues($entity);

  // Remove domain assignment if present.
  if ($entity !== FALSE && isset($node_domains[$id])) {
    unset($node_domains[$id]);
    $entity
      ->set(DomainAccessManagerInterface::DOMAIN_ACCESS_FIELD, array_keys($node_domains));
    $entity
      ->save();
  }
}