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.
*/
protected function computeValue() {
$query = \Drupal::entityQuery('node')
// $query = \Drupal::entityQuery('node')
$storage = \Drupal::service('entity_type.manager')->getStorage('node');
$query = $storage->getQuery()
->condition('status', 1)
->condition('type', 'materiau')
->exists('field_materiau_images')
->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++;
}