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

Has one relationship to an Element data object punts user to page 1 #166

Open
dmcb opened this issue Dec 21, 2017 · 5 comments
Open

Has one relationship to an Element data object punts user to page 1 #166

dmcb opened this issue Dec 21, 2017 · 5 comments

Comments

@dmcb
Copy link

dmcb commented Dec 21, 2017

This is an odd one, but it's only when I use Elemental in a unique way.

I have a has_one relationship to an Element data object. For example, the site config has a has_one relationship to a "call to action" element data object, so that this element can be shown globally across all templates on the site (how the project holder edits this has_one relationship on the call to action element is through https://github.com/silvershop/silverstripe-hasonefield - essentially hiding a grid field of 1 with an add/edit button). Everything works great.

But, when doing that same style of has_one relationship to an Element data object from a page in the site tree, everything appears to work, but once I add or edit the Element in the has_one relationship, the form redirects me after a second to Page 1 in the site tree. Every single time.

I've isolated this behaviour to this function: https://github.com/dnadesign/silverstripe-elemental/blob/4c4b9ab1a2b45ba5c994bc3bc6d4f815586da52f/src/Extensions/GridFieldDetailFormItemRequestExtension.php#L38
When I comment out this function's logic, the bad redirect on my form doesn't happen and everything works correctly. But I can't explain what the problem is. Does any one have any ideas?

@robbieaverill
Copy link
Contributor

Thanks for reporting! Are you saying you're setting a has_one from your page to your element, without using an ElementalArea intermediary?

@robbieaverill
Copy link
Contributor

bump @dmcb

@dmcb
Copy link
Author

dmcb commented Jan 31, 2018

Hi @robbieaverill, thanks for taking a look. Yes, that's exactly what I'm saying. This is a common use case for me, where I need some pages to be highly structured and some not, i.e. one one page type I have an accordion that must be here and a carousel that must be there, and the content admin fills out the fields, but on another page type, it may be a loosely structured content page where they can drag and drop around as many accordions and carousels as they would like. Or, I need an element to appear globally across pages, but also want the ability for content admins to use it on ElementalAreas on pages too.

So I don't want to duplicate code and instead leverage the same data objects in both situations.

So in my situation I have a Call To Action Element. I've plugged it in to a DataExtension for SiteConfig, and using HasOneButtonField, I can edit it:

class SiteConfigExtension extends DataExtension
{
    private static $has_one = [
        'ProjectCTA' => CallToActionSmallElement::Class
    ];
...

And I can place it in templates across my site:

<% if SiteConfig.ProjectCTA %>
    $SiteConfig.ProjectCTA
<% end_if %>

Everything is awesome, because that same CallToActionSmallElement class can be used on any page with an ElementalArea.

But when I use a has_one relationship to that same CallToActionSmallElement class from a page, I get the redirection I described above, that appears to be from the function in Elemental that I linked to, and this prevents me from creating highly structured pages that reuse Elemental objects.

@robbieaverill
Copy link
Contributor

Ok - this is not the intended use case for this module. We expect users to go via the ElementalArea ORM relationship. It sounds like a useful enhancement to allow this, so will triage as an enhancement but it is unlikely to be worked on before the 2.0.0 stable release, unless you would like to contribute? =)

@dmcb
Copy link
Author

dmcb commented Feb 1, 2018

Thanks @robbieaverill! Yeah, I know it's not the main use case - though I'm surprised that more people don't want their configurable elements to also be baked into certain places in certain templates when flexibility of layout isn't desired. I can't stand duplicating code.

I'll try to contribute if I can find the time to debug this. It's so close already, like I said, using an element in a has_one relationship works in SiteConfig, it just doesn't work in pages because it appears this piece of code https://github.com/dnadesign/silverstripe-elemental/blob/4c4b9ab1a2b45ba5c994bc3bc6d4f815586da52f/src/Extensions/GridFieldDetailFormItemRequestExtension.php#L38 is somehow redirecting the admin to Page 1 in the editing interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants