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

Live preview issue with relationship child tags #3481

Open
robinsowell opened this issue Jun 1, 2023 · 4 comments
Open

Live preview issue with relationship child tags #3481

robinsowell opened this issue Jun 1, 2023 · 4 comments
Assignees
Labels
Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on.

Comments

@robinsowell
Copy link
Contributor

Problem- live preview differs from actual output in a really obscure case where you are showing a related entry's child' data.

Screenshot 2023-06-01 at 3 24 53 PM

My tag looks like:

{exp:channel:entries channel="tiny"}
<h3>{title}</h3>

{tiny_fluid}
     {tiny_fluid:tiny_group}
        {fields}
   
   {tiny_fluid:my_rel}
   <h4>Relationship - group standalone</h4>
    {content status="open"}
      {if content:count == 1}<h3>Relationships ({content:total_results})</h3>{/if}

      Related entry title: {content:title}<br>
      Related field in the related child entry:<br>
      {content:my_related_field_in_child_entry}
        {content:my_related_field_in_child_entry:title}<br>
      {/content:my_related_field_in_child_entry}
      <hr>
    {/content}
  {/tiny_fluid:my_rel}
  
        {/fields}  
    {/tiny_fluid:tiny_group}
{/tiny_fluid}
{/exp:channel:entries}

My 'tiny' channel has 1 field in it called 'tiny_fluid', which has 1 field in it- a relationship field called 'my_rel'.

I make an entry in 'tiny', use the my tiny_fluid group once, select 2 related entries, save:

Screenshot 2023-06-01 at 3 45 32 PM

One of those related entries 'Bandcamp' has 2 related entries in its 'my_related_field_in_child_entry' relationship field. Those children show up when viewing the entry on the frontend, but in the live preview, they do not. I'm thinking one of the two displays must be due to a bug, and I think it's the live preview.

@robinsowell robinsowell added the Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on. label Jun 1, 2023
@intoeetive intoeetive changed the title 7.3 Fieldlet live preview issue with relationship child tags. Fluid live preview issue with relationship child tags. Jun 2, 2023
@intoeetive
Copy link
Contributor

I have tested this and can confirm the issue also exists without using field groups, in 7.3 as well as 7.2.12

Additionally, with front-end editing enabled, unparsed tag shows up in template: {content:related_news:frontedit}

@intoeetive
Copy link
Contributor

Performed investigation. Because LivePreview query is based on POSTed data, it fetches the first level of relationships (because the relationship field is in POST), but it does not know anything further (2, 3 levels of relationships etc). It also happens with "pure" relationship field and not related to Fluid.

We would need to change how LivePreview works in order to get this fixed, and presumably this is going to be big change

@intoeetive intoeetive changed the title Fluid live preview issue with relationship child tags. Live preview issue with relationship child tags Jun 12, 2023
@litzinger
Copy link
Contributor

litzinger commented Nov 3, 2023

Has anyone tested this with Grid yet? I just encountered an issue in Bloqs where Relationship fields were not working in Live Preview. So I tested it in Grid too and got a similar result. I'm 99% sure this used to work because I have code in Bloqs using the relationships_query hook to fetch the data and do some stuff so it worked with Publisher (Publisher would hi-jack the preview data), but now none of that appears to be working.

update: a little more info...

This is what the save method in Bloqs has looked like for... as long as I can remember. Since 2016 it's always returned ' ', but if I return $data when it's an LP request, everything works again.

public function save($data)
    {
        self::$saveData[$this->field_id] = $data;

        // @todo, well something in EE changed? ee('LivePreview')->getEntryData() and hasEntryData()
        // are both false at this point, but if I return $data here the Relationships work in LP, as does everything else.
        // return $data;

        return ' ';
    }

edit again: Did something change in EE so it calls the save() function on field types when performing a LP request?

@litzinger
Copy link
Contributor

litzinger commented Nov 5, 2023

I tracked my last comment down to this commit where now apparently all FTs are getting their save() method called during LP requests, but ee('LivePreview')->getEntryData() and ee('LivePreview')->hasEntryData() are false at this point, so it's impossible, without work arounds (see below), to know how the field type should respond.

007ae46

I had to update the save() method in Bloqs to this:

public function save($data)
    {
        self::$saveData[$this->field_id] = $data;

        if (App::isLivePreviewRequest()) {
            return $data;
        }

        return ' ';
    }

Where the isActionRequest method basically does this check as it's the only way to tell if it's a LP request.

if (self::isGteEE6() && self::isActionRequest()) {
            $action = ee('Model')->get('Action')
                ->filter('class', 'Channel')
                ->filter('method', 'live_preview')
                ->first();

            return $action->action_id && (int) ee()->input->get('ACT') === $action->action_id;
        }

Note: I might just be able to have have $data return and not do this live preview checking, but the method has been returning the blank string since 2016, and I'm not sure what other repercussions there could be if I change that now.

@bryannielsen bryannielsen self-assigned this Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on.
Projects
None yet
Development

No branches or pull requests

4 participants