Skip to content

trait FormAccessible bug ? (version 5.8.2) #10

@ryssbowh

Description

@ryssbowh

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions