Skip to content

Commit 13b01f2

Browse files
committed
SUPP0RT-694: Added id to all paragraphs headers
1 parent 6c5aa8b commit 13b01f2

File tree

4 files changed

+3
-85
lines changed

4 files changed

+3
-85
lines changed

web/profiles/custom/os2loop/modules/os2loop_toc_block/os2loop_toc_block.module

Lines changed: 0 additions & 21 deletions
This file was deleted.

web/profiles/custom/os2loop/modules/os2loop_toc_block/os2loop_toc_block.services.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ services:
55
- '@toc_api.manager'
66
- '@toc_api.builder'
77
- '@entity_type.manager'
8-
- '@renderer'

web/profiles/custom/os2loop/modules/os2loop_toc_block/src/Helper/Helper.php

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
namespace Drupal\os2loop_toc_block\Helper;
44

5-
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
65
use Drupal\Core\Entity\EntityTypeManagerInterface;
7-
use Drupal\Core\Field\EntityReferenceFieldItemList;
8-
use Drupal\Core\Render\RendererInterface;
9-
use Drupal\node\NodeInterface;
106
use Drupal\toc_api\TocBuilder;
117
use Drupal\toc_api\TocManagerInterface;
128

@@ -36,13 +32,6 @@ class Helper {
3632
*/
3733
protected $entityTypeManager;
3834

39-
/**
40-
* Drupal\Core\Render\RendererInterface definition.
41-
*
42-
* @var \Drupal\Core\Render\RendererInterface
43-
*/
44-
protected $renderer;
45-
4635
/**
4736
* Block constructor for table of contents.
4837
*
@@ -52,61 +41,11 @@ class Helper {
5241
* Builder service for table of contents.
5342
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
5443
* The entity manager.
55-
* @param \Drupal\Core\Render\RendererInterface $renderer
56-
* Drupals renderer service.
5744
*/
58-
public function __construct(TocManagerInterface $tocManager, TocBuilder $tocBuilder, EntityTypeManagerInterface $entityTypeManager, RendererInterface $renderer) {
45+
public function __construct(TocManagerInterface $tocManager, TocBuilder $tocBuilder, EntityTypeManagerInterface $entityTypeManager) {
5946
$this->tocManager = $tocManager;
6047
$this->tocBuilder = $tocBuilder;
6148
$this->entityTypeManager = $entityTypeManager;
62-
$this->renderer = $renderer;
63-
}
64-
65-
/**
66-
* Implements hook_node_view().
67-
*
68-
* Adds Ids to headers related to table of contents.
69-
*
70-
* @param array $build
71-
* The node build.
72-
* @param \Drupal\node\NodeInterface $node
73-
* The node entity.
74-
* @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display
75-
* The display of the node.
76-
* @param string $view_mode
77-
* The view mode of the node.
78-
*
79-
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
80-
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
81-
*/
82-
public function nodeView(array &$build, NodeInterface $node, EntityViewDisplayInterface $display, $view_mode) {
83-
// Add lock to prevent the renderer from calling it self indefinitely.
84-
$lock = &drupal_static(__FUNCTION__, FALSE);
85-
if (!$lock) {
86-
$lock = TRUE;
87-
if ('full' === $view_mode) {
88-
$hasToc = FALSE;
89-
if ($node->hasField('os2loop_documents_document_conte')) {
90-
$paragraphsContent = $node->get('os2loop_documents_document_conte');
91-
assert($paragraphsContent instanceof EntityReferenceFieldItemList);
92-
$paragraphs = $paragraphsContent->referencedEntities();
93-
94-
foreach ($paragraphs as $paragraph) {
95-
if ('table_of_contents' == $paragraph->bundle()) {
96-
$hasToc = TRUE;
97-
break;
98-
}
99-
}
100-
if ($hasToc) {
101-
$node_html = (string) $this->renderer->render($build);
102-
$toc = $this->createToc($node_html);
103-
if ($toc->isVisible()) {
104-
$build['#markup'] = $this->tocBuilder->buildContent($toc)['#markup'];
105-
}
106-
}
107-
}
108-
}
109-
}
11049
}
11150

11251
/**

web/profiles/custom/os2loop/themes/os2loop_theme/templates/content-entities/os2loop_documents_title.html.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
{% set rendered_title = content.os2loop_documents_title|render %}
33
{% if rendered_title|trim %}
44
{% set toc_ignore = paragraph.get('os2loop_documents_toc_ignore').value == 1 %}
5-
<h2 class="{{ toc_ignore ? 'toc-ignore' }}">{{ rendered_title }}</h2>
5+
{% set header_id = 'paragraph-' ~ paragraph.id.value %}
6+
<h2 id="{{ header_id }}" class="{{ toc_ignore ? 'toc-ignore' }}">{{ rendered_title }}</h2>
67
{% endif %}

0 commit comments

Comments
 (0)