Skip to content

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

Open
@jlahijani

Description

@jlahijani

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions