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.

R HILDAN M (not verified)

Fri, 12/14/2018 - 16:56

ini ke 13 pabrik astm a283 c pabrik pipa boiler pabrik plat abrex 400 pabrik plat asme516 grade70 pabrik plat astm516 70 pabrik plat boiler pabrik plat hb 400 pabrik plat high tensile sm490 yb pabrik plat high tensile sm490ya pabrik plat kapal Distributor besi Wf Baja undangan pernikahan bahasa inggris islam Distributor Besi H beam Toko Besi Beton Supplier pipa besi Toko Wiremesh Besi Toko Wiremesh Besi Pabrik wiremesh Distributor bondek undangan pernikahan amplop surat Distributor Besi Beton Jual Besi Beton Toko pipa besi Jual besi beton Sni Ulir Polos polos ulir Agen Wiremesh Besi Agen Wiremesh Besi Pabrik besi unp Distributor wiremesh undangan pernikahan unik dan murah www.sentrabesibaja.com Harga Besi Beton Agen pipa besi Jual besi beton sii Pabrik Wiremesh Besi Pabrik Wiremesh Besi Pabrik besi cnp Distributor pipa besi baja sch 40 sch 80 undangan pernikahan elegan Jual Welded Beam T beam King Queen Cross Castellated Beam Pabrik Besi Beton Pabrik pipa besi Jual besi beton psi Ulir Polos Distributor Atap Spandek Distributor Atap Spandek Pabrik besi hollow Distributor besi hollow undangan pernikahan animasi Jual Bondek Cor Distributor Besi Wf Baja Distributor sch 40 Jual besi beton perwira Harga Atap Spandek Harga Atap Spandek Pabrik besi beton Sni Ulir Polos Distributor besi beton Sni Ulir Polos undangan pernikahan lucu Jual Atap Spandek Sni Supplier Besi Wf Baja Harga sch 40 Jual besi beton PAS Jual Atap Spandek Jual Atap Spandek ironsteelcenter.com Distributor besi wf baja undangan pernikahan kalender Jual Plat Bordes Kembang Agen Besi Wf Baja Jual sch 40 Jual besi beton master steel ms Supplier Atap Spandek Supplier Atap Spandek Distributor stainless steel Distributor besi unp undangan pernikahan ala india Jual Plat Besi Hitam Toko Besi Wf Baja Supplier sch 40 Jual besi beton ksty

Add new comment