Skip to content
Snippets Groups Projects
Select Git revision
  • 1.0.7
  • 1.0.x default
  • 1.1.2
  • 1.1.1
  • 1.1.0
  • previous/3528635-add-gitlab-ci.yml/2025-07-17
  • 1.0.9
  • previous/3529424-allow-users-to/2025-06-10
  • previous/3528635-add-gitlab-ci.yml/2025-06-09-1
  • previous/3528635-add-gitlab-ci.yml/2025-06-09
  • 1.0.8
  • 1.0.5
  • 1.0.6
  • 1.0.4
  • 1.0.3
  • 1.0.2
  • 1.0.1
  • 1.0.0
18 results

paragraph_lineage

  • Clone with SSH
  • Clone with HTTPS
  • Chris Dart's avatar
    Issue #3514531: create a ParagraphIdLinkFormatterTest.php
    Chris Dart authored
    4eee9cde
    History

    Paragraph Lineage Module

    The Paragraph Lineage module provides functionality to display a paragraph entity along with its ancestors in a hierarchical view.

    Features

    • Render a paragraph entity using the default view mode.
    • Display the lineage of a paragraph entity.
    • Retrieve available view modes for a paragraph bundle.

    Installation

    1. Place the paragraph_lineage module in the web/modules/custom directory.
    2. Enable the module using Drush or the Drupal admin interface.
    drush en paragraph_lineage

    Usage

    Rendering a Paragraph with Lineage

    The ParagraphLineageViewController class is responsible for rendering a paragraph entity along with its lineage. The build method loads the paragraph from the route, retrieves its lineage, and renders the paragraph using the default view mode.

    Getting Available View Modes

    The ParagraphViewModes class provides a method to retrieve available view modes for a specific paragraph bundle using the entity_display.repository service.

    Code Examples

    Rendering a Paragraph

    
    public function build(): array {
      // Get the paragraph from the route.
      /** @var \Drupal\paragraphs\ParagraphInterface $paragraph */
      $paragraph = $this->route_match->getParameter('paragraph');
      if (!$paragraph instanceof ParagraphInterface) {
        throw new \InvalidArgumentException('No paragraph found in the route.');
      }
      $lineage = [];
      $this->getLineage($lineage, $paragraph);
    
      // Render the paragraph using the default view mode.
      $rendered_paragraph = $this->entity_type_manager
        ->getViewBuilder('paragraph')
        ->view($paragraph, 'default');
    
      return [
        '#theme' => 'paragraph_lineage',
        '#paragraph' => [
          'type' => $paragraph->getEntityTypeId(),
          'bundle' => $paragraph->bundle(),
          'content' => $rendered_paragraph,
        ],
        '#lineage' => $lineage,
      ];
    }

    Getting Available View Modes

    use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
    use Symfony\Component\DependencyInjection\ContainerInterface;
    
    class ParagraphViewModes {
    
      protected $entityDisplayRepository;
    
      public function __construct(EntityDisplayRepositoryInterface $entity_display_repository) {
        $this->entityDisplayRepository = $entity_display_repository;
      }
    
      public function getViewModes(string $bundle): array {
        return $this->entityDisplayRepository->getViewModes('paragraph', $bundle);
      }
    
      public static function create(ContainerInterface $container): ParagraphViewModes {
        return new static(
          $container->get('entity_display.repository')
        );
      }
    
    }

    Maintainers