bnomei / kirby3-autoid

Automatic unique ID for Pages, Files and Structures including performant helpers to retrieve them. Bonus: Tiny-URL.
https://forum.getkirby.com/t/kirby3-autoid-plugin/23572
MIT License
80 stars 8 forks source link

FilterBy on autoid doesn't work anymore on structurefield #57

Open kgevaert opened 3 years ago

kgevaert commented 3 years ago

blueprint

categories:
 label: Categories
 type: structure
 fields:
  autoid: 
   type: hidden
   translate: false                  
  cat_title:
   label: Title
   type: text

site.txt

Categories:
- 
  cat_title: new
  autoid: r8hqec1g
- 
  cat_title: cool
  autoid: 58lfd99u
- 
  cat_title: project
  autoid: 6uewjsbp

The following code doesn't seem to work anymore on kirby 3.5. I use the latest autoid-plugin. $categories= site()->categories()->toStructure()->filterBy('autoid','58lfd99u'); echo count($categories) gives 0;

But following code works on the 'cat_title' $categories= site()->categories()->toStructure()->filterBy('cat_title','new'); echo count($categories) gives 1;

jonasfeige commented 3 years ago

Have you made sure the IDs have actually been assigned? You can simply check in the panel by removing type: hidden. If not, you might want to re-index.

kgevaert commented 3 years ago

@jonasfeige The IDs are correctly assigned. Tested by removing type:hidden and you see it in site.txt. Does it work for you?

bnomei commented 3 years ago

since i am on parental leave right now i sadly do not have the time to debug this on my own. please try asking this in the forum.

my suspicion would be that the filterBy function tries calling whatever string is in the first parameter and it works for only if that results in a structure object. but i am not sure why it should fail for autoid. the plugin registers a global helper and page method with that name but it does not extend the structure class.

jonasfeige commented 3 years ago

I can confirm that filterBy() does not seem to be working any longer with autoid. As a temporary workaround, you can use filter(). Just tested and it seems to work as expected:

$categories = site()->categories()->toStructure()->filter(function($category) {
   return $category->autoid()  == '58lfd99u';
});