You are here

public function DomainAccessAdd::execute in Domain Access 8

Executes the plugin.

Overrides ExecutableInterface::execute

File

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

Class

DomainAccessAdd
Assigns a node to 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);

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