Skip to content

Add ability for a page/template to know the structure of its repeaters and nested+ repeaters (offspring) #555

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

Open
jlahijani opened this issue Feb 4, 2025 · 0 comments

Comments

@jlahijani
Copy link

jlahijani commented Feb 4, 2025

I'm taking full advantage of repeater nesting as it is a "belongs-to + has-many" type of relationship common in web application design.

Let's say I have the following (note the indentation which represents nesting):

- /some-page/ (basic-page template)
  - foo (repeater; 1 level deep) 
    - bar (repeater; 2 levels deep)
      - baz (repeater; 3 levels deep)
  - boo (repeater; 1 level deep)
    - lol (repeater; 2 levels deep)

Now let's say I want to edit a baz repeater item directly in the page editor as if it were any other page.

When I save the baz item, I also want to ultimately save /some-page/ to which it belongs through the nested relationship to make any changes to that page which would be required based on the changes of the baz item.

I can currently do this with an after save hook that does $baz->getForPage()->getForPage()-getForPage()->save(['noHooks'=>true]);

However, if you think this through much further, I would also want to update boo and lol items as well and even foo and bar
and baz items.

I have currently achieved this by hardcoding a method that drills through the repeater fields and nested repeater fields (let's call them offspring) I've defined of all the repeater items and looping through them and saving each item accordingly.

However, it sure would be nice if that offspring structure could be determined dynamically.

So for example something like this:

$pages->get('/some-page/')->getRepeatersOffspring($options); // $options could have filters to include/exclude fields

Would result in an array or object that looks something like this (with more data ideally):

- foo
  - bar
    - baz
- boo
  - lol
@jlahijani jlahijani changed the title Add ability for a page/template to know it the structure of its repeaters and nested+ repeaters (offspring) Add ability for a page/template to know the structure of its repeaters and nested+ repeaters (offspring) Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant