Skip to content

Instantly share code, notes, and snippets.

View aytee's full-sized avatar

Arthur Turlak aytee

View GitHub Profile
@aytee
aytee / UserRestriction.php
Created April 26, 2022 20:33
UserRestriction.php from commerce_product_restriction module /Plugin/Commerce/ProductRestriction/
<?php
namespace Drupal\commerce_product_restriction\Plugin\Commerce\ProductRestriction;
use Drupal\commerce_product_restriction\Plugin\ProductRestrictionPluginBase;
use Drupal\commerce_product_restriction\Plugin\ProductRestrictionPluginInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
@aytee
aytee / gist:7d8523234780ba7f7aba7dc53104cdf7
Last active February 14, 2022 19:07
Drupal 9 Search and Delete Entities
Generic:
// Get all users with email containing "xyz"
$query = \Drupal::entityQuery('user')
->condition('mail', "XYZ", 'CONTAINS');
$uids = $query->execute();
// Load these entities ($uids) in our case using storage controller.
// We call loadMultiple method and give $uids array as argument.
$itemsToDelete = \Drupal::entityTypeManager()->getStorage('user')
->loadMultiple($uids);