gmz
January 4, 2023, 11:08am
1
In a project page blueprint I use that structure field:
fields:
team:
label: Team
type: structure
duplicate: false
fields:
member:
type: users
query: kirby.users.sortBy("name", "asc")
multiple: false
required: true
role:
type: select
required: true
options:
type: query
query: site.roles.toStructure
text: "{{ item.name }}"
value: "{{ item.id }}"
In a field of another blueprint page I need to use team members as query:
fields:
subscribers:
label: Subscribers
type: users
query: page('project').team.toStructure.????
There is a way to extract a collection of users stored in a structure?
I think you need a custom page method that returns a list of users stored in that structure field.
Or try this:
query: kirby.users.filterBy('uuid', 'in', page('project').team.toStructure.pluck('member', '-', true)
gmz
January 4, 2023, 11:29am
3
Thanks for quick response!
Can I access to a page model from panel?
Yes, just like any other method. Does the suggested query not work? Are you using uuids?
gmz
January 4, 2023, 5:06pm
5
yes I use uuids but suggested query returns:
Your query must return a set of users
using info field for debug: page('project').team.toStructure
displays
member:
user://jKLL2vzB
role: coworker
member:
user://EUjmXz9H
role: client
this is the field value in txt file:
Team:
-
member:
- user://jKLL2vzB
role: coworker
-
member:
- user://EUjmXz9H
role: client
I also created in project page model this method:
public function users(){
$users = new Collection();
foreach ($this->team()->toStructure() as $user) {
$users->append($user->member()->toUser());
}
return $users;
}
Accessing page('project')->users()
from template no problems, but using page('project').users
as query blueprint I get same error:
Your query must return a set of users
Suggestions?
Your users()
method returns a collection, not a users object. So define $users = new Users()