You are here

function domain_access_domain_insert in Domain Access 8

Implements hook_ENTITY_TYPE_insert().

1 call to domain_access_domain_insert()
domain_access_install in domain_access/domain_access.install
Implements hook_install().

File

domain_access/domain_access.module, line 643
Domain-based access control for content.

Code

function domain_access_domain_insert($entity) {

  /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
  if ($entity
    ->isSyncing()) {

    // Do not fire hook when config sync in progress.
    return;
  }
  $id = 'domain_access_add_action.' . $entity
    ->id();
  $controller = \Drupal::entityTypeManager()
    ->getStorage('action');
  if (!$controller
    ->load($id)) {

    /** @var \Drupal\system\Entity\Action $action */
    $action = $controller
      ->create([
      'id' => $id,
      'type' => 'node',
      'label' => t('Add selected content to the @label domain', [
        '@label' => $entity
          ->label(),
      ]),
      'configuration' => [
        'domain_id' => $entity
          ->id(),
      ],
      'plugin' => 'domain_access_add_action',
    ]);
    $action
      ->trustData()
      ->save();
  }
  $remove_id = 'domain_access_remove_action.' . $entity
    ->id();
  if (!$controller
    ->load($remove_id)) {

    /** @var \Drupal\system\Entity\Action $action */
    $action = $controller
      ->create([
      'id' => $remove_id,
      'type' => 'node',
      'label' => t('Remove selected content from the @label domain', [
        '@label' => $entity
          ->label(),
      ]),
      'configuration' => [
        'domain_id' => $entity
          ->id(),
      ],
      'plugin' => 'domain_access_remove_action',
    ]);
    $action
      ->trustData()
      ->save();
  }
  $id = 'domain_access_add_editor_action.' . $entity
    ->id();
  if (!$controller
    ->load($id)) {

    /** @var \Drupal\system\Entity\Action $action */
    $action = $controller
      ->create([
      'id' => $id,
      'type' => 'user',
      'label' => t('Add editors to the @label domain', [
        '@label' => $entity
          ->label(),
      ]),
      'configuration' => [
        'domain_id' => $entity
          ->id(),
      ],
      'plugin' => 'domain_access_add_editor_action',
    ]);
    $action
      ->trustData()
      ->save();
  }
  $remove_id = 'domain_access_remove_editor_action.' . $entity
    ->id();
  if (!$controller
    ->load($remove_id)) {

    /** @var \Drupal\system\Entity\Action $action */
    $action = $controller
      ->create([
      'id' => $remove_id,
      'type' => 'user',
      'label' => t('Remove editors from the @label domain', [
        '@label' => $entity
          ->label(),
      ]),
      'configuration' => [
        'domain_id' => $entity
          ->id(),
      ],
      'plugin' => 'domain_access_remove_editor_action',
    ]);
    $action
      ->trustData()
      ->save();
  }
}