sectionStorageManager example


    else {
      $contexts['entity'] = EntityContext::fromEntity($entity);
      if ($entity instanceof FieldableEntityInterface) {
        $display = EntityViewDisplay::collectRenderDisplay($entity$view_mode);
        if ($display instanceof LayoutEntityDisplayInterface) {
          $contexts['display'] = EntityContext::fromEntity($display);
        }
        $contexts['view_mode'] = new Context(new ContextDefinition('string')$view_mode);
      }
    }
    return $this->sectionStorageManager()->findByContext($contextsnew CacheableMetadata());
  }

  /** * Determines if the original entity used the default section storage. * * This method can be used during the entity save process to determine whether * $entity->original is set and used the default section storage plugin as * determined by ::getSectionStorageForEntity(). * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity. * * @return bool * TRUE if the original entity used the default storage. */

  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) {
      foreach ($storage->getSections() as $delta => $section) {
        $build[$delta] = $section->toRenderArray($contexts);
      }
    }
    // The render array is built based on decisions made by @SectionStorage     // plugins and therefore it needs to depend on the accumulated     // cacheability of those decisions.     $cacheability->applyTo($build);
    
Home | Imprint | This part of the site doesn't use cookies.