You are here

public function DomainAccessAddEditor::execute in Domain Access 8

Executes the plugin.

Overrides ExecutableInterface::execute

File

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

Class

DomainAccessAddEditor
Assigns an editor to a domain.

Namespace

Drupal\domain_access\Plugin\Action

Code

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

  // Skip adding the role to the user if they already have it.
  if ($entity !== FALSE && !isset($user_domains[$id])) {
    $user_domains[$id] = $id;
    $entity
      ->set(DomainAccessManagerInterface::DOMAIN_ACCESS_FIELD, array_keys($user_domains));
    $entity
      ->save();
  }
}