Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // How to fiend entities when using domain access ?
- //Example 1 : Without changing user session.
- $query = \Drupal::entityQuery('node');
- $query->condition(DOMAIN_ACCESS_FIELD, 'domain_id'); // Set the domain id hear
- $query->condition('type', 'article');
- $query->condition('status', 1);
- $nids = $query->execute();
- print_r($nids);
- // If you can't get all domains data, do as the Example 2.
- // Example 2 : Using admin user session.
- // Call the account switcher service
- $accountSwitcher = \Drupal::service('account_switcher');
- // Switch to the admin user
- $accountSwitcher->switchTo(new \Drupal\Core\Session\UserSession(['uid' => 1]));
- $query = \Drupal::entityQuery('node');
- $query->condition(DOMAIN_ACCESS_FIELD, 'domain_id'); // Set the domain id hear
- $query->condition('type', 'article');
- $query->condition('status', 1);
- $nids = $query->execute();
- print_r($nids);
- // Switch back to old session.
- $accountSwitcher->switchBack();
Add Comment
Please, Sign In to add comment