You are here

public function DomainAccessRemoveEditor::execute in Domain Access 8

Executes the plugin.

Overrides ExecutableInterface::execute

File

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

Class

DomainAccessRemoveEditor
Removes an editor from 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])) {
    unset($user_domains[$id]);
    $entity
      ->set(DomainAccessManagerInterface::DOMAIN_ACCESS_FIELD, array_keys($user_domains));
    $entity
      ->save();
  }
}