- Add core.entity_view_mode.paragraph.otp_toc.yml to cgov_core/config/install
- Add core.entity_view_display.paragraph.pdq_summary_section.otp_toc.yml to pdq_cancer_information_summary/config/
- add the code in pdq_cancer_information_summary.module to pdq_cancer_information_summary
Last active
February 28, 2019 19:33
-
-
Save bryanpizzillo/52d960697d794313500ab4a524b2eac3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| langcode: en | |
| status: true | |
| dependencies: | |
| config: | |
| - core.entity_view_mode.paragraph.otp_toc | |
| - field.field.paragraph.pdq_summary_section.field_pdq_section_html | |
| - field.field.paragraph.pdq_summary_section.field_pdq_section_id | |
| - field.field.paragraph.pdq_summary_section.field_pdq_section_title | |
| - paragraphs.paragraphs_type.pdq_summary_section | |
| module: | |
| - text | |
| id: paragraph.pdq_summary_section.otp_toc | |
| targetEntityType: paragraph | |
| bundle: pdq_summary_section | |
| mode: otp_toc | |
| content: | |
| field_pdq_section_id: | |
| weight: 0 | |
| label: inline | |
| settings: | |
| link_to_entity: false | |
| third_party_settings: { } | |
| type: string | |
| region: content | |
| field_pdq_section_title: | |
| weight: 1 | |
| label: hidden | |
| settings: | |
| link_to_entity: false | |
| third_party_settings: { } | |
| type: string | |
| region: content | |
| hidden: | |
| - field_pdq_section_html: field_pdq_section_html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| langcode: en | |
| status: true | |
| dependencies: | |
| module: | |
| - paragraphs | |
| id: paragraph.otp_toc | |
| label: 'On this page TOC' | |
| targetEntityType: paragraph | |
| cache: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Other use statements here | |
| use Drupal\Core\Entity\Display\EntityViewDisplayInterface; | |
| // snip | |
| /** | |
| * Implements hook_ENTITY_TYPE_view(). | |
| * | |
| * This is for adding in the On This Page view of the sections for templates. | |
| */ | |
| function pdq_cancer_information_summary_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) { | |
| // We should only do this for summaries in the full display mode. | |
| if ($entity->bundle() != 'pdq_cancer_information_summary' || ($view_mode != 'full' && $view_mode != 'default')) { | |
| return; | |
| } | |
| if (isset($build['field_summary_sections'])) { | |
| // Copy summary sections into a new "field" using TOC display. | |
| $build['otp_toc'] = $build['field_summary_sections']['#items']->view([ | |
| 'type' => 'entity_reference_revisions_entity_view', | |
| 'settings' => [ | |
| 'view_mode' => 'otp_toc', | |
| 'link' => 'link', | |
| ], | |
| ]); | |
| } | |
| } | |
| // snip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment