/**
  * {@inheritdoc}
  *
  * Builds the entity listing as renderable array for table.html.twig.
  *
  * @todo Add a link to add a new item to the #empty text.
  */
 public function render()
 {
     $build['table'] = array('#type' => 'table', '#header' => $this->buildHeader(), '#title' => $this->getTitle(), '#rows' => array(), '#empty' => $this->t('There is no @label yet.', array('@label' => $this->entityType->getLabel())), '#cache' => ['contexts' => $this->entityType->getListCacheContexts(), 'tags' => $this->entityType->getListCacheTags()]);
     foreach ($this->load() as $entity) {
         if ($row = $this->buildRow($entity)) {
             $build['table']['#rows'][$entity->id()] = $row;
         }
     }
     // Only add the pager if a limit is specified.
     if ($this->limit) {
         $build['pager'] = array('#type' => 'pager');
     }
     return $build;
 }
Example #2
0
 /**
  * Returns a renderable forum index page array.
  *
  * @param array $forums
  *   A list of forums.
  * @param \Drupal\taxonomy\TermInterface $term
  *   The taxonomy term of the forum.
  * @param array $topics
  *   The topics of this forum.
  * @param array $parents
  *   The parent forums in relation this forum.
  * @param array $header
  *   Array of header cells.
  *
  * @return array
  *   A render array.
  */
 protected function build($forums, TermInterface $term, $topics = array(), $parents = array(), $header = array())
 {
     $config = $this->config('forum.settings');
     $build = array('#theme' => 'forums', '#forums' => $forums, '#topics' => $topics, '#parents' => $parents, '#header' => $header, '#term' => $term, '#sortby' => $config->get('topics.order'), '#forums_per_page' => $config->get('topics.page_limit'));
     if (empty($term->forum_container->value)) {
         $build['#attached']['feed'][] = array('taxonomy/term/' . $term->id() . '/feed', 'RSS - ' . $term->getName());
     }
     $this->renderer->addCacheableDependency($build, $config);
     foreach ($forums as $forum) {
         $this->renderer->addCacheableDependency($build, $forum);
     }
     foreach ($topics as $topic) {
         $this->renderer->addCacheableDependency($build, $topic);
     }
     foreach ($parents as $parent) {
         $this->renderer->addCacheableDependency($build, $parent);
     }
     $this->renderer->addCacheableDependency($build, $term);
     return ['action' => $this->buildActionLinks($config->get('vocabulary'), $term), 'forum' => $build, '#cache' => ['tags' => Cache::mergeTags($this->nodeEntityTypeDefinition->getListCacheTags(), $this->commentEntityTypeDefinition->getListCacheTags())]];
 }
Example #3
0
 /**
  * Invalidates an entity's cache tags upon delete.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  *   The entity type definition.
  * @param \Drupal\Core\Entity\EntityInterface[] $entities
  *   An array of entities.
  */
 protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities)
 {
     $tags = $entity_type->getListCacheTags();
     foreach ($entities as $entity) {
         // An entity was deleted: invalidate its own cache tag, but also its list
         // cache tags. (A deleted entity may cause changes in a paged list on
         // other pages than the one it's on. The one it's on is handled by its own
         // cache tag, but subsequent list pages would not be invalidated, hence we
         // must invalidate its list cache tags as well.)
         $tags = Cache::mergeTags($tags, $entity->getCacheTags());
     }
     Cache::invalidateTags($tags);
 }
Example #4
0
 /**
  * {@inheritdoc}
  *
  * Override to never invalidate the individual entities' cache tags; the
  * config system already invalidates them.
  */
 protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities)
 {
     Cache::invalidateTags($entity_type->getListCacheTags());
 }
Example #5
0
  /**
   * {@inheritdoc}
   */
  public function getCacheTags() {
    $cache_tags = Cache::mergeTags(parent::getCacheTags(), $this->view->storage->getCacheTags());
    $cache_tags = Cache::mergeTags($cache_tags, $this->targetEntityType->getListCacheTags());

    return $cache_tags;
  }