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 Fields not Parsing #117

Closed
TomJaeger opened this Issue Feb 5, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@TomJaeger
Copy link

TomJaeger commented Feb 5, 2019

Description of the problem
If you have two relationship fields named similarly (ex short name of 'client-example-1' and 'client-example-1-services' in two different channels the longer field (client-example-1-services) doesn't get parsed by the template engine.

How To Reproduce
Steps to reproduce the behavior:

  1. Create relationship field with the short name of client-example-1 assign it to channel 1
  2. Create relationship field with the short name of client-example-1-services assign it to channel 2
  3. Add entry to each channel (including a relationship in the fields above being selected)
  4. Create template like the following
{exp:channel:entries channel="name here" entry_id="XX"}

  {client-example-1-services}
    {client-example-1-services:title}
  {/client-example-1-services}

{/exp:channel:entries}

It will output
{client-example-1-services}{client-example-1-services:title}{/client-example-1-services}

Please note, you have to create the shorter short name version first.
Error Messages
NA

Environment Details:

  • Version: [e.g. 5.1.3]
  • PHP Version [e.g. 7.1]
  • MySQL Version [e.g. 5.7]
  • OS: macOS
  • Web Server: nginx -- valet

Possible Solution
I think if the short name array's that get returned in the Api_channel_fields/fetch_custom_channel_fields could be sorted by length to resolve this.

Additional context
Please note, we just changed the name of the fields and kept moving for now... so not a showstopper for us. It also only happens when we use hyphens in the name and not underscores

@litzinger

This comment has been minimized.

Copy link
Contributor

litzinger commented Feb 6, 2019

Could this be related to the issue I found? #55

@kevincupp

This comment has been minimized.

Copy link
Contributor

kevincupp commented Feb 6, 2019

I think this is the key clue:

It also only happens when we use hyphens in the name and not underscores

Sounds like some regex is using a \b word boundary which will stop at a hyphen. First place I'd look is here:

if ( ! $is_grid)
{
$regex = '\/?((?:(?:'.$all_fields.'):?)+)\b([^}{]*)?';
}
else
{
$force_parent = implode('|', $this->grid_relationship_names);
$regex = '\/?((?:'.$force_parent.')(?:[:](?:(?:'.$all_fields.'):?)+)?)\b([^}{]*)?';
}

@kevincupp kevincupp closed this in a291390 Feb 28, 2019

kevincupp added a commit that referenced this issue Mar 11, 2019

Alternate fix for relationship fields with hyphens
This reverts a291390 because it did not place the last colon in the
proper capture group, and now aims to fix #117 simply by ordering the fields by
most characters to least.

Fixes #152
Fixes #154
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.