loadEntities example

case 'query':
        // Not supported currently, but this is certainly where we'd put it.         return FALSE;

      case 'results':
        // Values to set: $view->result, $view->total_rows, $view->execute_time,         // $view->current_page.         if ($cache = \Drupal::cache($this->resultsBin)->get($this->generateResultsKey())) {
          if (!$cutoff || $cache->created > $cutoff) {
            $this->view->result = $cache->data['result'];
            // Load entities for each result.             $this->view->query->loadEntities($this->view->result);
            $this->view->total_rows = $cache->data['total_rows'];
            $this->view->setCurrentPage($cache->data['current_page'], TRUE);
            $this->view->execute_time = 0;
            return TRUE;
          }
        }
        return FALSE;
    }
  }

  /** * Clear out cached data for a view. */
// Setup the result row objects.         $view->result = iterator_to_array($result);
        array_walk($view->result, function DResultRow $row$index) {
          $row->index = $index;
        });

        $view->pager->postExecute($view->result);
        $view->pager->updatePageInfo();
        $view->total_rows = $view->pager->getTotalItems();

        // Load all entities contained in the results.         $this->loadEntities($view->result);
      }
      catch (DatabaseExceptionWrapper $e) {
        $view->result = [];
        if (!empty($view->live_preview)) {
          $this->messenger->addError($e->getMessage());
        }
        else {
          throw new DatabaseExceptionWrapper("Exception in {$view->storage->label()}[{$view->storage->id()}]: {$e->getMessage()}");
        }
      }

    }
$view->storage = $view_entity->reveal();

    $entity_type_manager = $this->setupEntityTypes();
    $date_sql = $this->prophesize(DateSqlInterface::class);
    $messenger = $this->prophesize(MessengerInterface::class);

    $query = new Sql([], 'sql', []$entity_type_manager->reveal()$date_sql->reveal()$messenger->reveal());
    $query->view = $view;

    $result = [];
    $query->addField('entity_first', 'id', 'id');
    $query->loadEntities($result);
    $this->assertEmpty($result);
  }

  /** * @covers ::loadEntities * @covers ::assignEntitiesToResult */
  public function testLoadEntitiesWithNoRelationshipAndNoRevision() {
    $view = $this->prophesize('Drupal\views\ViewExecutable')->reveal();
    $view_entity = $this->prophesize(ViewEntityInterface::class);
    $view_entity->get('base_table')->willReturn('entity_first');
    
Home | Imprint | This part of the site doesn't use cookies.