Skip to content

Allow additional config driven fields in JSONDataFormatter #69

@phptek

Description

@phptek

In JSONDataFormatter line 119 and 151 a baked-in set of three fields are returned for each object in a has_xxx relation which doesn't allow for much in the way of customisation, viz:

                $serobj->$relName = ArrayData::array_to_object(array(
                    "className" => $relClass,
                    "href" => "$href.json",
                    "id" => $obj->$fieldName
                ));

We should allow developers to specify additional fields to return here, declared in YML config viz:

                $serobj->$relName = ArrayData::array_to_object(array_replace([
                    "className" => $relClass,
                    "href" => "$href.json",
                    "id" => $obj->$fieldName
                ], $obj->config()->get('api_fields'));

Note the use of array_replace() so that userland config can also override the defaults, not simply append to them (Not completely sure the latter is a good idea...)

PR

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions