getEntityTableInfo example


  public function viewsForm(&$form, FormStateInterface $form_state) {
    // Make sure we do not accidentally cache this form.     // @todo Evaluate this again in https://www.drupal.org/node/2503009.     $form['#cache']['max-age'] = 0;

    // Add the tableselect javascript.     $form['#attached']['library'][] = 'core/drupal.tableselect';
    $use_revision = array_key_exists('revision', $this->view->getQuery()->getEntityTableInfo());

    // Only add the bulk form options and buttons if there are results.     if (!empty($this->view->result)) {
      // Render checkboxes for all rows.       $form[$this->options['id']]['#tree'] = TRUE;
      foreach ($this->view->result as $row_index => $row) {
        $entity = $this->getEntity($row);
        if ($entity !== NULL) {
          $entity = $this->getEntityTranslationByRelationship($entity$row);

          $form[$this->options['id']][$row_index] = [
            
public function summaryTitle() {
    return $this->t('Settings');
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = [];

    foreach ($this->getEntityTableInfo() as $info) {
      if (!empty($info['provider'])) {
        $dependencies['module'][] = $info['provider'];
      }
    }

    return $dependencies;
  }

  /** * Set a LIMIT on the query, specifying a maximum number of results. */
  
/** * Gets an array of cache tags for the current view. * * @return string[] * An array of cache tags based on the current view. */
  public function getCacheTags() {
    $tags = $this->view->storage->getCacheTags();

    // The list cache tags for the entity types listed in this view.     $entity_information = $this->view->getQuery()->getEntityTableInfo();

    if (!empty($entity_information)) {
      // Add the list cache tags for each entity type used by this view.       foreach ($entity_information as $metadata) {
        $tags = Cache::mergeTags($tags, \Drupal::entityTypeManager()->getDefinition($metadata['entity_type'])->getListCacheTags());
      }
    }

    $tags = Cache::mergeTags($tags$this->view->getQuery()->getCacheTags());

    return $tags;
  }
elseif (!$this->hasAggregate) {
      // Allow 'GROUP BY' even no aggregation function has been set.       $this->hasAggregate = $this->view->display_handler->getOption('group_by');
    }
    $groupby = [];
    if ($this->hasAggregate && (!empty($this->groupby) || !empty($non_aggregates))) {
      $groupby = array_unique(array_merge($this->groupby, $non_aggregates));
    }

    // Make sure each entity table has the base field added so that the     // entities can be loaded.     $entity_information = $this->getEntityTableInfo();
    if ($entity_information) {
      $params = [];
      if ($this->hasAggregate) {
        // Handle grouping, by retrieving the minimum entity_id.         $params = [
          'function' => 'min',
        ];
      }

      foreach ($entity_information as $info) {
        $entity_type = \Drupal::entityTypeManager()->getDefinition($info['entity_type']);
        
$result = [];
    $result[] = new ResultRow([
      'id' => 1,
    ]);
    $result[] = new ResultRow([
      'id' => 2,
    ]);

    $query->addField('entity_first', 'id', 'id');
    $query->loadEntities($result);
    $entity_information = $query->getEntityTableInfo();

    $this->assertSame($entities['first'][1]$result[0]->_entity);
    $this->assertSame($entities['first'][2]$result[1]->_entity);

    $this->assertEquals([]$result[0]->_relationship_entities);
    $this->assertEquals([]$result[1]->_relationship_entities);

    // This is an entity table and should be in $entity_information.     $this->assertContains('first', array_keys($entity_information));
    // This is not an entity table and should not be in $entity_information.     $this->assertNotContains('entity_first_field_data__entity_first_field_data', array_keys($entity_information));
  }
Home | Imprint | This part of the site doesn't use cookies.