fixed articles in home base materials grid

This commit is contained in:
Bachir Soussi Chiadmi 2021-08-05 11:57:11 +02:00
parent cc9ceede26
commit d49700753a
1 changed files with 14 additions and 9 deletions

View File

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