Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page Preview Not Working #136

Closed
stpaultim opened this issue Jun 17, 2022 · 20 comments · Fixed by #190
Closed

Page Preview Not Working #136

stpaultim opened this issue Jun 17, 2022 · 20 comments · Fixed by #190
Labels
bug Something isn't working

Comments

@stpaultim
Copy link
Member

I've just noticed that the node edit PREVIEW button does not seem to be working with my paragraphs.

Is this is known limitation of Paragraphs (if so, is it documented anywhere for folks like me to find) or is this a bug?

Or am I just doing something wrong.

image

@argiepiano
Copy link
Contributor

Can you describe "not working" in more detail please? How to reproduce?

@sudipto68
Copy link

We are using different paragraph types for our content and they work perfectly when we Save and View the page but if we try the Preview button there seen nothing on that Preview page. In Simple, Paragraphs are not working on the Preview page.

@stpaultim
Copy link
Member Author

As @sudipto68 reported. If I click on the preview I see the page title and the blocks that appear below the page content, but the page content is not visible at all - there is no preview of the content contained within the paragraphs on that page.

@argiepiano
Copy link
Contributor

@laryn and @stpaultim, I've done a bit of debugging on why the Preview button doesn't show the Paragraph fields in a node.

So, in Backdrop, Paragraphs implements hook_field_prepare_view() (in file paragraphs.field_formatter.inc). I don't know what the purpose of this implementation is, but I suspect it's related to the experimental modal administration. The issue is that, in that hook, the function assigns a value of 'scratch_paragraph` to the Paragraph item, I think ONLY when you are in editing mode (once the node is saved, the value is actually the paragraph item ID).

So, paragraphs_field_formatter_view(), which produces the output, finds that flag scratch_paragraph and effectively skips rendering the field. Again, this only happens while editing and pressing Preview.

I commented out hook_field_prepare_view() and slightly modified paragraphs_field_formatter_view() and the Preview works, BUT I haven't tried the rest of the functionality - this may mess up the modal admin etc.

I'm not a maintainer of this module and don't quite have the time to thoroughly test, but I thought I mentioned what I've found in case someone wants to fix this.

@argiepiano
Copy link
Contributor

Also tried leaving hook_field_prepare_view() as is, and commenting out lines 101-107 in paragraphs_field_formatter_view() and that also works for the Preview...

@stpaultim
Copy link
Member Author

@argiepiano Thanks. I'm not sure that I'll be able to fix this. But, maybe I can recruit someone who can.

@argiepiano
Copy link
Contributor

argiepiano commented Jun 30, 2022

A couple more thoughts: scratch_paragraph is used to avoid rendering the Paragraph field. @laryn added this is #60 not too long ago. And as I suspected it was added when the modal editing was added. It's unclear to me what @laryn was trying to solve with this.

I have tested by removing BOTH paragraphs_field_prepare_view() AND lines 101-107 (see below), and the modal still works fine in my testing, and the Preview starts working now.

So the key is to figure out if there is any situation when avoiding the rendering of the field, and scratch_paragraph flag are really needed. My guess is that @laryn put it there because he adapted an unmerged D7 change that used it. The difference with that is that, that D7 patch did not use a modal, so my guess is that avoiding rendering the Paragraphs field was somehow needed in that situation.

This is what I removed in paragraphs_field_formatter_view() (in addition to the whole paragraphs_field_prepare_view() function).

      // If we are dealing with an empty paragraphs field, render an insert point.
      if ($items[0]['value'] == 'scratch_paragraph') {
        if (!empty($instance['settings']['modal_admin'])) {
          $entity_ids = entity_extract_ids($entity_type, $entity);
        }
        return $element;
      }

@argiepiano
Copy link
Contributor

Just wanted to add that this has to be looked at carefully. I haven't tested in all situations, e.g. nested paragraphs...

@laryn
Copy link
Member

laryn commented Aug 26, 2022

@argiepiano Thanks for digging into this as much as you have. If memory serves, the scratch_paragraph was intended for front end administration in the case that we have a paragraphs field that is empty, so that we can still add the front end admin options to create a new paragraphs item from the front end. But it's worth testing to make sure it's actually doing that, or needed. You are right that the D7 patch formed the basis for this experimental feature and I'm sure there are still some bugs to be worked out.

@stpaultim I'm not sure when I'll be able to get to this so feel free to recruit someone before then if you are able.

@sudipto68
Copy link

@argiepiano and @laryn thanks for figuring out this issue. We tested commenting out both the paragraphs_field_prepare_view() and lines 101-107 in paragraphs.field_formatter.inc and found preview shows all paragraphs except paragraphs which using paragraphs jquery ui accordion (I guess thats another issue). Nested paragraphs were showing perfectly. But we got some notice as below -
It is a test update _ Friends of the Mississippi River

sudipto68 added a commit to sudipto68/paragraphs that referenced this issue Oct 13, 2022
@sudipto68
Copy link

sudipto68 commented Oct 13, 2022

I have submitted a PR Based on the solution. Here is the PR 136

@herbdool herbdool added the bug Something isn't working label Mar 20, 2024
@herbdool
Copy link
Contributor

I must admit that I don't know if/how the modal admin works (which was part of https://www.drupal.org/files/issues/interdiff-2448677-20-24.txt which was merged). But I can see that the section in paragraphs_field_formatter_view() mentioned above is missing the line: $element[0]['insert_point'] = paragraphs_create_insert_point($entity_type, $entity_ids[0], 'scratch', $instance['field_name']); which calls a function which adds a contextual link. So maybe modal admin isn't working for me - no contextual link? And it returns an empty array.

At any rate, I have also removed it in testing. But I've also changed paragraphs_field_prepare_view() to this:

function paragraphs_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
  if ($field['type'] == 'paragraphs') {
    foreach ($items as $key => $item) {
      foreach ($item as $delta => $instance) {
        if (!isset($instance['value'])) {
          $items[$key][$delta]['value'] = 'scratch_paragraph';
        }
      }
    }
  }
}

Because the node preview seems to ignore paragraphs nested in paragraphs but adding scratch_paragraph prevents it from dropping. But as it is currently it only adds scratch_paragraph to the first item. My change adds it to each item.

This is just a temporary fix though since the preview still doesn't seem to behave the same as a regular render - the preprocess functions are not running properly, somehow, that were required for some paragraphs types I've got in testing.

herbdool added a commit to herbdool/paragraphs that referenced this issue Jul 30, 2024
herbdool added a commit to herbdool/paragraphs that referenced this issue Aug 5, 2024
@herbdool
Copy link
Contributor

herbdool commented Aug 5, 2024

I've now updated the PR to also prevent the modal_admin links from appearing if in node preview. (We want to prevent them from appearing because it breaks the way a preview should work - the user shouldn't be able to edit and save the content while still in preview.)

I've separately figured out the issue I had with modal_admin appearing. It now seems to be fully working for me.

@laryn @olafgrabienski would you like to take a look at the PR? Node preview should work with complex paragraphs types (such as in paragraphs_aplenty) and the modal admin links should not appear on preview.

@olafgrabienski
Copy link
Member

@herbdool, I can probably have a look by end of the week.

@olafgrabienski
Copy link
Member

@herbdool I've had a look at the updated PR. As far as I can see, the node preview works with Paragraphs (even complex types, e.g. Accordion, Cards, Media List). The modal admin links do not appear (as expected).

In DBlog, I see however two warnings after editing and/or saving content with a Paragraphs field:

  • Undefined array key 0 in file_field_widget_form() (line 712 of core/modules/file/file.field.inc).
  • Trying to access array offset on value of type null in file_field_widget_form() (line 712 of core/modules/file/file.field.inc).

@laryn
Copy link
Member

laryn commented Aug 16, 2024

Sounds like we're close here with just a few rough edges turned up by @olafgrabienski -- thanks for your work on this @herbdool and @olafgrabienski! I can do a round of testing after @herbdool sees and responds to the latest findings.

@herbdool
Copy link
Contributor

@olafgrabienski do you see the same errors without the patch?

@olafgrabienski
Copy link
Member

do you see the same errors without the patch?

Yes, I do. (Sorry for not checking before.) No idea about the reason, though. There are some contrib modules on the test site, but not many:

  • backup_migrate 1.x-1.0.26
  • colorbox 1.x-2.17.2
  • entity_plus 1.x-1.0.21
  • expanding_formatter 1.x-1.0.0
  • html5_upload 1.x-1.1.3
  • paragraphs 1.x-1.3.0
  • paragraphs_aplenty 1.x-1.2.1
  • paragraphs_aplenty_gallery 1.x-1.2.1
  • paragraphs_bundle_permissions 1.x-1.3.0

@herbdool
Copy link
Contributor

@laryn sounds like those errors are not due to this PR.

@laryn
Copy link
Member

laryn commented Aug 16, 2024

@herbdool Okay, I'll try to review this soon.
@olafgrabienski If you can reproduce those errors, can you open in a separate issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
6 participants