Similar to #3098138: All footnotes available as block for Layout Builder / Paragraph / ..., about adding an "extra" field using hook_entity_extra_field_info() to display all of the footnotes? I think it'd be worthwhile reusing the service from #3098138 so that all footnotes can be displayed regardless of what entity they come from.

Comments

DamienMcKenna created an issue. See original summary.

damienmckenna’s picture

damienmckenna’s picture

Issue summary: View changes
alexis_mc’s picture

I created a patch following the issue description. It has the https://www.drupal.org/project/footnotes/issues/3098138 custom service in order to make the "extra" field work. Any comments or suggestions are welcome.

damienmckenna’s picture

Status: Active » Needs review
lucuhb’s picture

Hello,

I have tried this patch but I have the impression that the content of this extra field is empty. I can't display the footnotes group on the node.
In the footnotes_preprocess_node() function, the field_footnotes_group is not added because $footnotes_group->buildFooter()['#footnotes'] is empty.

I have tested the patch #29 in issue 3098138 (All footnotes available as block for Layout Builder / Paragraph / ...) in association with this current patch (only a part because patch could not be applied) : the footnotes group block gives some data, but the extra field given by this patch is empty.

Here is the part I used from the current patch, the other parts are already given by the patch in issue 3098138

diff --git a/footnotes.module b/footnotes.module
index ad38ad5..9d50845 100644
--- a/footnotes.module
+++ b/footnotes.module
@@ -89,3 +89,34 @@ function footnotes_theme() {
 function footnotes_is_footnotes_later($format, $caller_filter) {
   return $format['filter_footnotes']['weight'] > $caller_filter['weight'];
 }
+
+/**
+ * Implements hook_entity_extra_field_info().
+ */
+function footnotes_entity_extra_field_info() {
+  $extra = [];
+  $entityTypeManager = \Drupal::service('entity_type.manager');
+
+  $contentTypes = $entityTypeManager->getStorage('node_type')->loadMultiple();
+  foreach ($contentTypes as $contentType) {
+    $extra['node'][$contentType->id()]['display']['field_footnotes_group'] = [
+      'label' => t('Footnotes group'),
+      'description' => t('Footnotes group field.'),
+      'weight' => 102,
+      'visible' => TRUE,
+    ];
+  }
+
+  return $extra;
+}
+
+/**
+ * Implements hook_preprocess().
+ */
+function footnotes_preprocess_node(&$variables) {
+  $footnotes_group = \Drupal::service('footnotes.group');
+
+  if (!empty($footnotes_group->buildFooter()['#footnotes'])) {
+    $variables['content']['field_footnotes_group'] = $footnotes_group->buildFooter();
+  }
+}
damienmckenna’s picture

StatusFileSize
new1.18 KB

This is the bit that lucuhb indicated is all that's necessary in order to have this work in addition to the latest patch from #3098138.

damienmckenna’s picture

StatusFileSize
new1.64 KB

This works, it uses #lazy_builder to generate the output after the service has loaded the data via the text filter. This will also require the latest patch to #3098138 in order for it to work.

damienmckenna’s picture

StatusFileSize
new2.23 KB

Don't display the extra field by default, so that it then doesn't have to be disabled on every view mode.

damienmckenna’s picture

StatusFileSize
new1.64 KB

The correct patch.

jaydip makawana’s picture

StatusFileSize
new1.64 KB

Re-rolled patch against 3.1.0

jaydip makawana’s picture

Removed Patch created. No change. Uploaded same patch by mistake.

scott_euser’s picture

Version: 3.0.1 » 4.0.0-alpha1
scott_euser’s picture

Going to merge this into 4x and created a follow-up here #3413181: Follow-up to all footnotes available as a block to apply to modal plugin to apply it to the new modal version before the old one gets retired. Patches still needed while on 3x until 4x (and its upgrade path are more stable).

scott_euser’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.