DomainAccessRemove.php 740 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace Drupal\domain_access\Plugin\Action;
  3. /**
  4. * Removes a node from a domain.
  5. *
  6. * @Action(
  7. * id = "domain_access_remove_action",
  8. * label = @Translation("Remove domain from content"),
  9. * type = "node"
  10. * )
  11. */
  12. class DomainAccessRemove extends DomainAccessActionBase {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public function execute($entity = NULL) {
  17. $id = $this->configuration['domain_id'];
  18. $node_domains = \Drupal::service('domain_access.manager')->getAccessValues($entity);
  19. // Remove domain assignment if present.
  20. if ($entity !== FALSE && isset($node_domains[$id])) {
  21. unset($node_domains[$id]);
  22. $entity->set(DOMAIN_ACCESS_FIELD, array_keys($node_domains));
  23. $entity->save();
  24. }
  25. }
  26. }