Skip to content
This repository has been archived by the owner on Oct 6, 2022. It is now read-only.

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

Open
kgevaert opened this issue Jan 7, 2021 · 4 comments
Open

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

kgevaert opened this issue Jan 7, 2021 · 4 comments
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@kgevaert
Copy link

kgevaert commented Jan 7, 2021

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
Copy link

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
Copy link
Author

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

@bnomei bnomei self-assigned this Jan 22, 2021
@bnomei bnomei added bug Something isn't working question Further information is requested labels Jan 22, 2021
@bnomei
Copy link
Owner

bnomei commented Jan 22, 2021

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
Copy link

jonasfeige commented Jan 23, 2021

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';
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants