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

Relationship cannot parse dynamic category ids #3104

Open
jamesseavers opened this issue Mar 13, 2023 · 13 comments
Open

Relationship cannot parse dynamic category ids #3104

jamesseavers opened this issue Mar 13, 2023 · 13 comments
Labels
Bug: Unconfirmed Bug report that is not yet confirmed and/or is not reproducible.

Comments

@jamesseavers
Copy link
Contributor

Description of the problem

When using the relationship field the category parameter can only accept a hard-coded variable like so:

{related_sessions category="36"}

However, when the category id is passed in as a variable, say from php or by a tested mod result like:

{related_sessions category="{exp:sym_eventcycles:get_year_id}"}

OR

{related_sessions category="<?php echo $year_cat_id; ?>"}

Both of these variables are tested and work as expect in parent tags.

The following error is shown:

InvalidArgumentException Caught

Payload cannot be retrieved.

ee/legacy/libraries/datastructures/Tree.php:173

Stack Trace: Please include when reporting this error

#0 ee/legacy/libraries/relationship_parser/Nodes.php(181): EE_TreeNode->__get('parser')
#1 ee/legacy/libraries/channel_entries_parser/Parser.php(339): ParseNode->callback_tagdata_loop_end('', Array)
#2 ee/legacy/libraries/Channel_entries_parser.php(172): EE_Channel_data_parser->parse(Array, Array)
#3 ee/legacy/libraries/relationship_parser/Parser.php(245): EE_Channel_parser->parse(Object(Channel), Array, Array)
#4 ee/legacy/libraries/relationship_parser/Parser.php(209): EE_Relationship_data_parser->replace(Object(ParseNode), '{related_sessio...', Array)
#5 ee/legacy/libraries/relationship_parser/Parser.php(90): EE_Relationship_data_parser->parse_node(Object(ParseNode), 1950, '\n\n{layout:set n...')
#6 ee/legacy/libraries/channel_entries_parser/components/Relationship.php(124): EE_Relationship_data_parser->parse(1950, '\n\n{layout:set n...', Object(Channel))
#7 ee/legacy/libraries/channel_entries_parser/Parser.php(291): EE_Channel_relationship_parser->replace('\n\n{layout:set n...', Object(EE_Channel_data_parser), Object(EE_Relationship_data_parser))
#8 ee/legacy/libraries/Channel_entries_parser.php(172): EE_Channel_data_parser->parse(Array, Array)
#9 ee/ExpressionEngine/Addons/channel/mod.channel.php(2495): EE_Channel_parser->parse(Object(Channel), Array, Array)
#10 ee/ExpressionEngine/Addons/channel/mod.channel.php(257): Channel->parse_channel_entries()
#11 ee/legacy/libraries/Template.php(1795): Channel->entries()
#12 ee/legacy/libraries/Template.php(1471): EE_Template->process_tags()
#13 ee/legacy/libraries/Template.php(610): EE_Template->tags()
#14 ee/legacy/libraries/Template.php(244): EE_Template->parse('{!-- ra:0000000...', false, 1, false)
#15 ee/legacy/libraries/Template.php(174): EE_Template->fetch_and_parse('listings-detail', Array, false)
#16 ee/legacy/libraries/Core.php(794): EE_Template->run_template_engine('listings-detail', 'speaker')
#17 ee/legacy/controllers/ee.php(53): EE_Core->generate_page()
#18 [internal function]: EE->index()
#19 ee/ExpressionEngine/Core/Core.php(268): call_user_func_array(Array, Array)
#20 ee/ExpressionEngine/Core/Core.php(124): ExpressionEngine\Core\Core->runController(Array)
#21 ee/ExpressionEngine/Boot/boot.php(184): ExpressionEngine\Core\Core->run(Object(ExpressionEngine\Core\Request))
#22 index.php(164): require_once('...')
#22 index.php(164): require_once('...')

Environment Details:

  • Version: 7.2.2 Pro
  • PHP Version: 7.4.12
  • MySQL Version5.7.32
  • OS: Linux
  • Web Server: Apache
@jamesseavers
Copy link
Contributor Author

Just wanted to give this a bump, has anyone seen it?

@intoeetive
Copy link
Contributor

@jamesseavers yes, we have seen it. Not sure whether it should be classified as bug, or limitation - but we have noted it as a thing to consider for improvement on relationship fields. It certainly is related to parsing order, and I think at this point the only way to overcome the limitation would be using embeds.

@jamesseavers
Copy link
Contributor Author

Good to know. I'll revert to an embed.

@jamesseavers
Copy link
Contributor Author

Thinking more about this, should a 'limitation' really end in a fatal error?

@intoeetive
Copy link
Contributor

Well, it is limitation in terms that "the tag is not supported to be used that way". So - the error could certainly provide better information, but - this is still supposed to error out

@intoeetive
Copy link
Contributor

@jamesseavers I just tested the below code (PHP on input) on latest EE 7.2.17 and it's working fine. Can you please confirm that you still have this issue?

<?php $cat_id = 1; ?>

{exp:channel:entries channel="blog" entry_id="10"}

{related_post category="<?=$cat_id?>"}
<h4>{related_post:title}</h4>
{/related_post}

{/exp:channel:entries}

@jamesseavers
Copy link
Contributor Author

@intoeetive Yes, it is still an issue.

@intoeetive
Copy link
Contributor

Can you show how your template looks like? I feel like I must be missing something as I'm not replicating. Also, is PHP set to parse on input?

@jamesseavers
Copy link
Contributor Author

`

    {related_sessions category="<?php echo $cat_id; ?>" show_future_entries="yes"}
    {if related_sessions:count==1}
    <div class="content-area flexible-element">
        <h4 class="speaker-session-header">{title} is speaking at the following session/s</h4>
        {/if}
        <div class="te-wrapper hi-light-section speaker-detail">
            <h3>{related_sessions:title}</h3>
            {if '{exp:sym_eventcycles:programme_state}' == 'y'}
                <div class="detail-session-info"><div class="detail-session-info-item"><span class="fa-regular fa-calendar"></span>{related_sessions:categories show_group="3"}{category_name}{/related_sessions:categories}</div><div class="detail-session-info-item"><span class="fa-regular fa-clock"></span>{related_sessions:entry_date format="%g:%i%a"} - {related_sessions:end format="%g:%i%a"}</div><div class="detail-session-info-item"><span class="fa-solid fa-location-pin"></span>{if related_sessions:room}Room {related_sessions:room}{/if}</div></div>
            {/if}

            {related_sessions:description}
            <p></p>
            {if related_sessions:session_takeaway}
            <p><strong>Session Takeaway</strong></p>
                {related_sessions:session_takeaway}
            {/if}

            {related_sessions:related_speakers}

            {if related_sessions:related_speakers:count == 1}
            <p style="margin-top: 24px;"><span class="hi-light-copy">Session speakers</span></p>
            <div class="additional-speaker-session">
            {/if}
                <div class="speaker detail-session">
                    <a href="{related_sessions:related_speakers:page_uri}">
                        <div class="speaker-image">
                            <div class="speaker-placeholder"><img src="/assets/images/speaker-placeholder.png" alt="Speaker Placeholder"></div>
                            <div class="speaker-image-inner">
                                <img class="speaker-photo" src="{related_sessions:related_speakers:photo:photo-list}" alt="{related_sessions:related_speakers:title} photo">
                            </div>
                            <img class="speaker-mask" src="/assets/images/speaker-mask.png" alt="Speaker Mask">
                        </div>
                        <div class="speaker-name">{related_sessions:related_speakers:title}</div>
                    </a>
                </div>
                {if related_sessions:related_speakers:count==related_sessions:related_speakers:total_results}
            </div>
            {/if}
            {/related_sessions:related_speakers}
            {related_sessions:categories show_group="2"}
                <div class="session-category"><a class="{category_url_title}" href="/conference-programme/category/{category_url_title}">{category_name}</a></div>
            {/related_sessions:categories}
        </div>
        {if related_sessions:count==related_sessions:total_results}
    </div>
    {/if}
    {/related_sessions}`

Yes, php is set to input.

@intoeetive
Copy link
Contributor

Is {related_sessions:related_speakers} referring to another relationship field in related entry?

@jamesseavers
Copy link
Contributor Author

Yes, it is.

I pull a single entry from the Speakers channel. I then access their related sessions. Within each related session, I then pull other related speakers to that session.

Does that make sense?

@intoeetive
Copy link
Contributor

Makes sense, but I'm still unable to replicate the issue :)

Looking at the trace you provided though, I see that the error is happening around {layout:set n... part - can you share that one as well? Hit me in Slack or email if you don't want to post the template publicly

@intoeetive
Copy link
Contributor

Noting that I wasn't able to replicate even using same templates and same Channel Sets imported. Will keep open for some time to see if another reports come in

@intoeetive intoeetive added the Bug: Unconfirmed Bug report that is not yet confirmed and/or is not reproducible. label May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Unconfirmed Bug report that is not yet confirmed and/or is not reproducible.
Projects
None yet
Development

No branches or pull requests

2 participants