silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
722 stars 821 forks source link

restrictfields in scaffoldFormFields does not work as expected #8659

Open sunnysideup opened 5 years ago

sunnysideup commented 5 years ago

Affected Version

phpunit/phpunit                          5.7.27            
silverstripe/recipe-cms                  4.2.2             
silverstripe/recipe-plugin               1.3.0             
sunnysideup/metatags                     dev-master ab5916b
sunnysideup/sswebpack_engine_only        dev-master 5d4a816
sunnysideup/templateoverview             dev-master fc4990a
sunnysideup/typography                   dev-master 74a488c
sunnysideup/webpack_requirements_backend dev-master 77728f2
symbiote/silverstripe-memberprofiles     dev-master fd68e8e
thewebmen/silverstripe-faq               dev-master 2cd8e7b

Description

I was trying to add additional fields via scaffolding in Page:

        private static $has_one = [
            'BackgroundImage' => Image::class
        ];

        public function getCMSFields()
        {
            $fields = parent::getCMSFields();
            $fieldsToAdd = $this->scaffoldFormFields(
                [
                    'tabbed' => false,
                    'includeRelations' => ['has_one' => true],
                    'restrictFields' => ['BackgroundImage'],
                    'ajaxSafe' => true
                ]
            );
            $fields->addFieldsToTab(
                'Root.PageExtras',
                $fieldsToAdd
            );

            return $fields;
        }

The PageExtras tab shows the following fields:

image

So the background image field is missing, but other relation fields show.

If I change the restricted field to "Title" then Title shows and all relations. In other words, relations do not seem to be restricted. To me, this is unexpected behaviour.

I have created a pull request: https://github.com/silverstripe/silverstripe-framework/pull/8658 as a concept. Not sure if it is on the right branch, etc...

Pull Requests

maxime-rainville commented 5 years ago

Looking at the attach PR that is targeted to SS5, I don't think there's any way we can change this without breaking SemVer. I've retagged this issue has an affects/v5