Kirby-index-field for structure data


#1

I have the »kirby-index-field« [https://github.com/jongacnik/kirby-index-field] on the site, this works fine to show fast the children pages.

I want to add the »kirby-index-field« to one page where i have structure data.

Now i added in the options.php on the function items this case:

 case 'structure':
         $items = $page->Mitarbeiter()->toStructure();
         break;

But this will not work…

How i can get the data of the structure field?

The structure in the TXT-File is like this:

Mitarbeiter: 

- 
  mitarbeiter: intern/personen/vorname-nachname
  eintritt: 2000-09-01
  austritt: 2003-05-01
  ma_ansprech: "0"
- 
  mitarbeiter: intern/personen/vorname-nachname
  eintritt: 2003-05-01
  austritt: ""
  ma_ansprech: "1"

The Blueprint is this:

  mitarbeiter:
    label: Mitarbeiter
    type: index
    options: structure
    filter: MyDataFilters::gruppen
    rows: 10
    columns:
      mitarbeiter: Mitarbeiter
      eintritt: Eintritt
      austritt: Austritt
      ma_ansprech: Ansprechperson

#2

That doesn’t make sense. What sort of options would you expect to see? After all, a structure entry consists of of multiple subentries…

Are these “Mitarbeiters” pages?

Then you could try this:

case 'structure':
        $options = [];
        $items = $page->mitarbeiter()->toStructure();
        foreach($items as $item) {
          $options[] = $item->mitarbeiter()->toPage();
        }
        $items = new Collection($options);
        break;

#3

I want to show the structure-content via the »kirby-index-field« because there i can use the data filter.
My Problem is that the Plugin works not for the include structure in the page.
That’s why I want to extend the plugin to the structure.

The page is for a society and this is on a group-page where i can add people to the group.

I would test your Solution…


#4

I see so you want to show all information from the entries in a table. The above will work in a select field, but I don’t know if it makes sense for the index field.

Edit: It should actually work like this:

        case 'structure':
                $items = $page->links()->yaml();
                $items = new Collection($items);
                break;

#5

BINGO! Thats it!
Thank You Sonja!

I have been testing the YAML as well, but forget the Collection!


#6

While this works, it is nevertheless a pretty stupid hack because it doesn’t belong in the page options and also because you have to hardcode a field name. It would make more sense to have an additional options method “optionsFromStructure” or something like that.