getListCacheTags example

// In case there is no "bundle" entity key, check create access with no     // bundle specified.     if (!$entity_type->hasKey('bundle')) {
      return $access_control_handler->createAccess(NULL, $account[], TRUE);
    }

    $access = AccessResult::neutral();
    $bundles = array_keys($this->entityTypeBundleInfo->getBundleInfo($entity_type_id));

    // Include list cache tag as access might change if more bundles are added.     if ($entity_type->getBundleEntityType()) {
      $access->addCacheTags($this->entityTypeManager->getDefinition($entity_type->getBundleEntityType())->getListCacheTags());

      if (empty($route->getOption('_ignore_create_bundle_access'))) {
        // Check if the user is allowed to create new bundles. If so, allow         // access, so the add page can show a link to create one.         // @see \Drupal\Core\Entity\Controller\EntityController::addPage()         $bundle_access_control_handler = $this->entityTypeManager->getAccessControlHandler($entity_type->getBundleEntityType());
        $access = $access->orIf($bundle_access_control_handler->createAccess(NULL, $account[], TRUE));
        if ($access->isAllowed()) {
          return $access;
        }
      }
    }

  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;
  }

  /** * Gets the max age for the current view. * * @return int */
$rows[] = $row;

        // Add node and node owner to cache tags.         $cacheable_metadata->addCacheTags($node->getCacheTags());
        if ($owner) {
          $cacheable_metadata->addCacheTags($owner->getCacheTags());
        }
      }
    }

    // Add the list cache tag for nodes.     $cacheable_metadata->addCacheTags($this->nodeStorage->getEntityType()->getListCacheTags());

    $page['tracker'] = [
      '#rows' => $rows,
      '#header' => [
        $this->t('Type'),
        $this->t('Title'),
        $this->t('Author'),
        $this->t('Comments'),
        $this->t('Last updated'),
      ],
      '#type' => 'table',
      

  public function render() {
    $build['table'] = [
      '#type' => 'table',
      '#header' => $this->buildHeader(),
      '#title' => $this->getTitle(),
      '#rows' => [],
      '#empty' => $this->t('There are no @label yet.', ['@label' => $this->entityType->getPluralLabel()]),
      '#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'] = [
        

                }
              }
            }
          }
        }
      }
      return $cacheability;
    }new CacheableMetadata());
    $entity_type = reset($collection)->getEntityType();
    $cacheability->addCacheTags(['http_response']);
    $cacheability->addCacheTags($entity_type->getListCacheTags());
    $cache_contexts = [
      // Cache contexts for JSON:API URL query parameters.       'url.query_args:fields',
      'url.query_args:filter',
      'url.query_args:include',
      'url.query_args:page',
      'url.query_args:sort',
      // Drupal defaults.       'url.site',
    ];
    // If the entity type is revisionable, add a resource version cache context.
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
        foreach ($revisions_on_source as $revision) {
          // Track all the differing revisions from the source workspace in           // the context of the target workspace. This will automatically           // update all the descendants of the target workspace as well.           $this->workspaceAssociation->trackEntity($revision$this->targetWorkspace);
        }

        // Since we're not saving entity objects, we need to invalidate the list         // cache tags manually.         $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
        $this->cacheTagsInvalidator->invalidateTags($entity_type->getListCacheTags());
      }
    }
    catch (\Exception $e) {
      if (isset($transaction)) {
        $transaction->rollBack();
      }
      Error::logException($this->logger, $e);
      throw $e;
    }
  }

  
/** * {@inheritdoc} */
  public static function create(ContainerInterface $container, array $configuration$plugin_id$plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('block.repository'),
      $container->get('entity_type.manager')->getViewBuilder('block'),
      $container->get('entity_type.manager')->getDefinition('block')->getListCacheTags()
    );
  }

  /** * {@inheritdoc} */
  public function setMainContent(array $main_content) {
    $this->mainContent = $main_content;
    return $this;
  }

  

    foreach ($parents as $parent) {
      $this->renderer->addCacheableDependency($build$parent);
    }
    $this->renderer->addCacheableDependency($build$term);

    $is_forum = empty($term->forum_container->value);
    return [
      'action' => ($is_forum) ? $this->buildActionLinks($config->get('vocabulary')$term) : [],
      'forum' => $build,
      '#cache' => [
        'tags' => Cache::mergeTags($this->nodeEntityTypeDefinition->getListCacheTags()$this->commentEntityTypeDefinition->getListCacheTags()),
      ],
    ];
  }

  /** * Returns add forum entity form. * * @return array * Render array for the add form. */
  public function addForum() {
    

  public function addPage() {
    $definition = $this->entityTypeManager()->getDefinition('node_type');
    $build = [
      '#theme' => 'node_add_list',
      '#cache' => [
        'tags' => $this->entityTypeManager()->getDefinition('node_type')->getListCacheTags(),
      ],
    ];

    $content = [];

    $types = $this->entityTypeManager()->getStorage('node_type')->loadMultiple();
    uasort($types[$definition->getClass(), 'sort']);
    // Only use node types the user has access to.     foreach ($types as $type) {
      $access = $this->entityTypeManager()->getAccessControlHandler('node')->createAccess($type->id(), NULL, [], TRUE);
      if ($access->isAllowed()) {
        
$referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags$this->getAdditionalCacheTagsForEntity($this->entity));
    $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags$view_cache_tag);
    $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags$cache_context_tags);
    $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags['rendered']);

    $non_referencing_entity_cache_tags = Cache::mergeTags($this->nonReferencingEntity->getCacheTags(), \Drupal::entityTypeManager()->getViewBuilder('entity_test')->getCacheTags());
    $non_referencing_entity_cache_tags = Cache::mergeTags($non_referencing_entity_cache_tags['rendered']);

    // Generate the cache tags for all two possible entity listing paths.     // 1. list cache tag only (listing query has no match)     // 2. list cache tag plus entity cache tag (listing query has a match)     $empty_entity_listing_cache_tags = Cache::mergeTags($this->entity->getEntityType()->getListCacheTags()$page_cache_tags);

    $nonempty_entity_listing_cache_tags = Cache::mergeTags($this->entity->getEntityType()->getListCacheTags()$this->entity->getCacheTags());
    $nonempty_entity_listing_cache_tags = Cache::mergeTags($nonempty_entity_listing_cache_tags$this->getAdditionalCacheTagsForEntityListing());
    $nonempty_entity_listing_cache_tags = Cache::mergeTags($nonempty_entity_listing_cache_tags$page_cache_tags);

    $this->verifyPageCache($referencing_entity_url, 'MISS');

    // Verify a cache hit, but also the presence of the correct cache tags.     $expected_tags = Cache::mergeTags($referencing_entity_cache_tags$page_cache_tags);
    $expected_tags = Cache::mergeTags($expected_tags$page_cache_tags_referencing_entity);
    $this->verifyPageCache($referencing_entity_url, 'HIT', $expected_tags);

    
$node = $this->entityRepository->getTranslationFromContext($nodes[$nid]);
      $item = $node->toLink()->toRenderable();
      $this->renderer->addCacheableDependency($item$node);
      $items[] = $item;
    }

    return [
      '#theme' => 'item_list__node',
      '#items' => $items,
      '#title' => $title,
      '#cache' => [
        'tags' => $this->entityTypeManager->getDefinition('node')->getListCacheTags(),
      ],
    ];
  }

}
    // hook_query_ENTITY_TYPE_access_alter(). Some core entity types have     // logic in their access control handler that isn't mirrored in     // hook_query_ENTITY_TYPE_access_alter(), so we duplicate that here until     // that's resolved.     $specific_condition = NULL;
    switch ($entity_type_id) {
      case 'block_content':
        // Allow access only to reusable blocks.         // @see \Drupal\block_content\BlockContentAccessControlHandler::checkAccess()         if (isset(static::$fieldManager->getBaseFieldDefinitions($entity_type_id)['reusable'])) {
          $specific_condition = new EntityCondition('reusable', 1);
          $cacheability->addCacheTags($entity_type->getListCacheTags());
        }
        break;

      case 'comment':
        // @see \Drupal\comment\CommentAccessControlHandler::checkAccess()         $specific_condition = static::getCommentAccessCondition($entity_type$current_user$cacheability);
        break;

      case 'entity_test':
        // This case is only necessary for testing comment access controls.         // @see \Drupal\jsonapi\Tests\Functional\CommentTest::testCollectionFilterAccess()
        $form_modes_titles = array_values(array_map(fn($item) => (string) $item['label']$form_modes));
        sort($form_modes_titles, SORT_NATURAL);
        foreach ($form_modes as $form_mode => $form_mode_info) {
          $this->derivatives['field_form_display_' . $form_mode . '_' . $entity_type_id] = [
            'title' => $form_mode_info['label'],
            'route_name' => "entity.entity_form_display.$entity_type_id.form_mode",
            'route_parameters' => [
              'form_mode_name' => $form_mode,
            ],
            'parent_id' => "field_ui.fields:form_display_overview_$entity_type_id",
            'weight' => array_flip($form_modes_titles)[(string) $form_mode_info['label']],
            'cache_tags' => $this->entityTypeManager->getDefinition('entity_form_display')->getListCacheTags(),
          ];
        }

        // One local task for each view mode.         $view_modes = $this->entityDisplayRepository->getViewModes($entity_type_id);
        // Sort all view modes by title.         $view_modes_titles = array_values(array_map(fn($item) => (string) $item['label']$view_modes));
        sort($view_modes_titles, SORT_NATURAL);
        foreach ($view_modes as $view_mode => $form_mode_info) {
          $this->derivatives['field_display_' . $view_mode . '_' . $entity_type_id] = [
            'title' => $form_mode_info['label'],
            
$plugin_definition,
      $container->get('entity_type.manager'),
      $container->get('entity_type.bundle.info'),
      $container->get('entity_type.manager')->getStorage('workflow')
    );
  }

  /** * {@inheritdoc} */
  public function getCacheTags() {
    return Cache::mergeTags(parent::getCacheTags()$this->entityTypeManager->getDefinition('workflow')->getListCacheTags());
  }

  /** * {@inheritdoc} */
  public function getCacheContexts() {
    return Cache::mergeContexts(parent::getCacheContexts()$this->entityTypeManager->getDefinition('workflow')->getListCacheContexts());
  }

  /** * {@inheritdoc} */


    $tree = $this->bookManager->bookSubtreeData($node->book);
    $contents = $this->exportTraverse($tree[$this, 'bookNodeExport']);
    $node = $this->entityRepository->getTranslationFromContext($node);
    return [
      '#theme' => 'book_export_html',
      '#title' => $node->label(),
      '#contents' => $contents,
      '#depth' => $node->book['depth'],
      '#cache' => [
        'tags' => $node->getEntityType()->getListCacheTags(),
      ],
    ];
  }

  /** * Traverses the book tree to build printable or exportable output. * * During the traversal, the callback is applied to each node and is called * recursively for each child of the node (in weight, title order). * * @param array $tree * A subtree of the book menu hierarchy, rooted at the current page. * @param callable $callable * A callback to be called upon visiting a node in the tree. * * @return array * The render array generated in visiting each node. */
Home | Imprint | This part of the site doesn't use cookies.