Guest User

Untitled

a guest
Jul 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. // How to fiend entities when using domain access ?
  2.  
  3. //Example 1 : Without changing user session.
  4. $query = \Drupal::entityQuery('node');
  5. $query->condition(DOMAIN_ACCESS_FIELD, 'domain_id'); // Set the domain id hear
  6. $query->condition('type', 'article');
  7. $query->condition('status', 1);
  8. $nids = $query->execute();
  9. print_r($nids);
  10.  
  11. // If you can't get all domains data, do as the Example 2.
  12.  
  13. // Example 2 : Using admin user session.
  14. // Call the account switcher service
  15. $accountSwitcher = \Drupal::service('account_switcher');
  16. // Switch to the admin user
  17. $accountSwitcher->switchTo(new \Drupal\Core\Session\UserSession(['uid' => 1]));
  18.  
  19. $query = \Drupal::entityQuery('node');
  20. $query->condition(DOMAIN_ACCESS_FIELD, 'domain_id'); // Set the domain id hear
  21. $query->condition('type', 'article');
  22. $query->condition('status', 1);
  23. $nids = $query->execute();
  24. print_r($nids);
  25.  
  26. // Switch back to old session.
  27. $accountSwitcher->switchBack();
Add Comment
Please, Sign In to add comment