New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return field objects for user data (especially user structure fields) #524

Open
texnixe opened this Issue Dec 9, 2016 · 6 comments

Comments

Projects
None yet
3 participants
@texnixe

texnixe commented Dec 9, 2016

Not sure if this is more of a feature than a bug, but trying to use the yaml() or structure() methods on a structure field in a user file results in an error:

https://forum.getkirby.com/t/structure-field-type-not-working-properly-on-user-fields/2838/9

$user->some_structure_field()

returns an array.

@texnixe texnixe changed the title from User structure field returns array instead of object to User structure field returns array instead of field object Dec 9, 2016

@lukasbestle

This comment has been minimized.

Show comment
Hide comment
@lukasbestle

lukasbestle Dec 12, 2016

Member

A structure is not a page but a collection, so it doesn't return field objects. I agree that fields would sometimes be great, but currently it's sort of a feature.

Edit: I didn't understand the question correctly. This is related to the user class. User files are YAML files and converted to PHP arrays when loading the data. This isn't limited to the "first layer", but also the deeper layers get converted. This is why not a string but an array gets returned. We could return structure objects directly for those arrays, but that would break the old behavior.

Member

lukasbestle commented Dec 12, 2016

A structure is not a page but a collection, so it doesn't return field objects. I agree that fields would sometimes be great, but currently it's sort of a feature.

Edit: I didn't understand the question correctly. This is related to the user class. User files are YAML files and converted to PHP arrays when loading the data. This isn't limited to the "first layer", but also the deeper layers get converted. This is why not a string but an array gets returned. We could return structure objects directly for those arrays, but that would break the old behavior.

@lukasbestle lukasbestle added the idea label Dec 12, 2016

@lukasbestle lukasbestle changed the title from User structure field returns array instead of field object to Return field objects for user data (especially user structure fields) Dec 12, 2016

@texnixe

This comment has been minimized.

Show comment
Hide comment
@texnixe

texnixe Dec 12, 2016

I know that a structure is not a page. Maybe this is a misunderstanding and you mean a user is not a page?

gettype($page->structurefield())

returns "object".

gettype($user->structurefield())

returns "array"

texnixe commented Dec 12, 2016

I know that a structure is not a page. Maybe this is a misunderstanding and you mean a user is not a page?

gettype($page->structurefield())

returns "object".

gettype($user->structurefield())

returns "array"

@lukasbestle

This comment has been minimized.

Show comment
Hide comment
@lukasbestle

lukasbestle Dec 12, 2016

Member

Please see my edit. :)

Member

lukasbestle commented Dec 12, 2016

Please see my edit. :)

@texnixe

This comment has been minimized.

Show comment
Hide comment
@texnixe

texnixe Dec 12, 2016

Yep, I understand that, I posted this, because it is misleading for the user, because he has learned to use yaml() or toStructure() on a structure field and if he does the same with a structure field in the user file, he gets an error. At least, we would have to explain it in the docs, if we don't want to change the behavior.

texnixe commented Dec 12, 2016

Yep, I understand that, I posted this, because it is misleading for the user, because he has learned to use yaml() or toStructure() on a structure field and if he does the same with a structure field in the user file, he gets an error. At least, we would have to explain it in the docs, if we don't want to change the behavior.

@lukasbestle

This comment has been minimized.

Show comment
Hide comment
@lukasbestle

lukasbestle Dec 12, 2016

Member

Yes, that's definitely true. I'm on the side of fixing this, but we need to check the consequences first.

Member

lukasbestle commented Dec 12, 2016

Yes, that's definitely true. I'm on the side of fixing this, but we need to check the consequences first.

@LeBenLeBen

This comment has been minimized.

Show comment
Hide comment
@LeBenLeBen

LeBenLeBen Jul 6, 2017

Any update regarding this topic? I tried to add a custom field method that I could use on a field I added to my users, but the field method return a string instead of a field which prevents me to call my method on it.

I was trying to do that because I cannot add methods directly on users, which would be a awesome feature. For example you could create things like $user->fullName() or more complex functions that takes basic user information to generate more complex data.

Possible duplicate of #333

LeBenLeBen commented Jul 6, 2017

Any update regarding this topic? I tried to add a custom field method that I could use on a field I added to my users, but the field method return a string instead of a field which prevents me to call my method on it.

I was trying to do that because I cannot add methods directly on users, which would be a awesome feature. For example you could create things like $user->fullName() or more complex functions that takes basic user information to generate more complex data.

Possible duplicate of #333

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment