diff --git a/web/modules/custom/materio_home/src/Plugin/Field/FieldType/ComputedMaterialsReferences.php b/web/modules/custom/materio_home/src/Plugin/Field/FieldType/ComputedMaterialsReferences.php index 308c5e0e..faccb715 100644 --- a/web/modules/custom/materio_home/src/Plugin/Field/FieldType/ComputedMaterialsReferences.php +++ b/web/modules/custom/materio_home/src/Plugin/Field/FieldType/ComputedMaterialsReferences.php @@ -37,18 +37,23 @@ class ComputedMaterialsReferences extends EntityReferenceFieldItemList * Compute the values. */ protected function computeValue() { - $query = \Drupal::entityQuery('node') - ->condition('status', 1) - ->condition('type', 'materiau') - ->exists('field_materiau_images') - ->condition('field_materiau_images.%delta', 3, '>') - ->sort('created', 'DESC') - ->range(0,200); + // $query = \Drupal::entityQuery('node') + $storage = \Drupal::service('entity_type.manager')->getStorage('node'); + $query = $storage->getQuery() + ->condition('status', 1) + ->condition('type', 'materiau') + ->condition('field_materiau_images.%delta', 3, '>') + ->exists('field_materiau_images') + ->sort('created', 'DESC') + ->range(0,200); $results = $query->execute(); if ($results) { - $nids = array_rand($results, 100); + $nids = array_values($results); + shuffle($nids); + array_slice($nids, 0, 100); + // $nids = $results; $i = 0; - foreach ($nids as $nid) { + foreach ($nids as $key => $nid) { $this->list[$i] = $this->createItem($i, $nid); $i++; }