Search Entities when using Domain Access | Drupal 8

Search Entities when using Domain Access

Submitted by editor on Wed, 05/23/2018 - 22:14
Question

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();

 

Comments

Hugo Marlay (not verified)

Sat, 08/11/2018 - 12:49

I am glad to read your post Thank you so much .keep sharing this Insightful Drupal. It's a happy for me to read your article. Keep spread out information so that everyone will be aware of this. I would like you to recommend high quality essay content from  custom essay writing services it is helpful to students who are studying in higher studies.

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.