getContextsForEntity example

/** * Builds the render array for the sections of a given entity. * * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The entity. * * @return array * The render array representing the sections of the entity. */
  protected function buildSections(FieldableEntityInterface $entity) {
    $contexts = $this->getContextsForEntity($entity);
    // @todo Remove in https://www.drupal.org/project/drupal/issues/3018782.     $label = new TranslatableMarkup('@entity being viewed', [
      '@entity' => $entity->getEntityType()->getSingularLabel(),
    ]);
    $contexts['layout_builder.entity'] = EntityContext::fromEntity($entity$label);

    $cacheability = new CacheableMetadata();
    $storage = $this->sectionStorageManager()->findByContext($contexts$cacheability);

    $build = [];
    if ($storage) {
      
Home | Imprint | This part of the site doesn't use cookies.