DomainAccessCommands.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Drupal\domain_access\Commands;
  3. use Consolidation\AnnotatedCommand\AnnotationData;
  4. use Consolidation\AnnotatedCommand\CommandData;
  5. use Drupal\domain\Commands\DomainCommands;
  6. use Symfony\Component\Console\Command\Command;
  7. use Symfony\Component\Console\Input\InputInterface;
  8. use Symfony\Component\Console\Input\InputOption;
  9. /**
  10. * Drush commands for the domain access module.
  11. *
  12. * These commands mainly extend base Domain commands. See the documentation at
  13. * https://github.com/consolidation/annotated-command for details.
  14. */
  15. class DomainAccessCommands extends DomainCommands {
  16. /**
  17. * Registers additional information to domain:info.
  18. *
  19. * @hook init domain:info
  20. */
  21. public function initDomainInfo(InputInterface $input, AnnotationData $annotationData) {
  22. // To add a field label, append to the 'field-labels' item.
  23. // @TODO: watch https://github.com/consolidation/annotated-command/pull/174
  24. $annotationData['field-labels'] .= "\n" . 'domain_access_entities: Domain access entities';
  25. }
  26. /**
  27. * Provides additional information to domain:info.
  28. *
  29. * @hook alter domain:info
  30. */
  31. public function alterDomainInfo($result, CommandData $commandData) {
  32. // Display which entities are enabled for domain by checking for the fields.
  33. $result['domain_access_entities'] = $this->getFieldEntities(DOMAIN_ACCESS_FIELD);
  34. return $result;
  35. }
  36. /**
  37. * @hook option domain:delete
  38. */
  39. public function deleteOptions(Command $command, AnnotationData $annotationData) {
  40. $command->addOption(
  41. 'content-assign',
  42. '',
  43. InputOption::VALUE_OPTIONAL,
  44. 'Reassign content for Domain Access',
  45. null
  46. );
  47. }
  48. /**
  49. * @hook on-event domain-delete
  50. */
  51. public function domainAccessDomainDelete($target_domain, $options) {
  52. // Run our own deletion routine here.
  53. if (is_null($options['content-assign'])) {
  54. $policy_content = 'prompt';
  55. }
  56. if (!empty($options['content-assign'])) {
  57. if (in_array($options['content-assign'], $this->reassignment_policies, TRUE)) {
  58. $policy_content = $options['content-assign'];
  59. }
  60. }
  61. $delete_options = [
  62. 'entity_filter' => 'node',
  63. 'policy' => $policy_content,
  64. 'field' => DOMAIN_ACCESS_FIELD,
  65. ];
  66. return $this->doReassign($target_domain, $delete_options);
  67. }
  68. }