Skip to content
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

trait FormAccessible bug ? (version 5.8.2) #10

Open
ryssbowh opened this issue Apr 12, 2020 · 2 comments
Open

trait FormAccessible bug ? (version 5.8.2) #10

ryssbowh opened this issue Apr 12, 2020 · 2 comments

Comments

@ryssbowh
Copy link

ryssbowh commented Apr 12, 2020

Hi there,
This is probably just a misunderstanding of my part but there's something strange related to the FormAccessible trait when dealing with relations.

First of all, is this trait supposed to be dealing with relations ? Or is the developer expected to write form mutators for relations ? If so, just ignore this :)

So I've got this model that defines a relation :

class Content {

    use FormAccessible;

    public function content_type()
    {
        return $this->belongsTo(ContentType::class);
    }
}

if I call $content->getFormValue('content_type') it returns null, because :
1 - there is no form mutator for content_type in this model
2 -The FormAccessible trait sees 'content_type' as a nested key and forward the call like so :
return \data_get($relatedModel, empty($key) ? null : $key); with, in this case, $relatedModel being a ContentType object and $key being still 'content_type'.
Obviously there is no 'content_type' attribute on the ContentType object.

Moreover, if I call $content->getFormValue('content_type.id') it's searching for a form mutator in ContentType called formContentType.idAttribute on the ContentType object, which isn't a valid php method name.

Wouldn't it make more sense to return the ContentType object when there is no form mutator in that object, or even better the key of the relation if the key isn't a nested key ?

So it would do :

$content->getFormValue('content_type'); //returns the primary key of the ContentType object
$content->getFormValue('content_type.name'); //returns a string or the result of the method formNameAttribute of the ContentType object

What do you think ?

@ryssbowh ryssbowh changed the title triat FormAccessible bug ? trait FormAccessible bug ? Apr 12, 2020
@ryssbowh ryssbowh changed the title trait FormAccessible bug ? trait FormAccessible bug ? (version 5.4.0) Apr 12, 2020
@crynobone
Copy link
Member

return \data_get($relatedModel, empty($key) ? null : $key);

I don't think this code available in v5.4.0.

@ryssbowh
Copy link
Author

Ah yes sorry my bad I've got 5.8.2

@ryssbowh ryssbowh changed the title trait FormAccessible bug ? (version 5.4.0) trait FormAccessible bug ? (version 5.8.2) Apr 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants