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

CMS 5 beta regression: setter method not called when saving field through edit form #10707

Closed
chrispenny opened this issue Feb 27, 2023 · 2 comments
Assignees

Comments

@chrispenny
Copy link
Contributor

chrispenny commented Feb 27, 2023

Affected Version

5.0.0-beta3

Description

  • I have set up my Page with a basic text field
  • I then create a setter method for that field
  • Saving a value for this field through a CMS edit form should trigger the setter method(?)

Is Silverstripe 4 it does, but in Silverstripe 5 it does not.

Set up

Page.php:

class Page extends SiteTree
{
    private static array $db = [
        'MyTestField' => 'Varchar',
    ];

    public function setMyTestField($val)
    {
        $this->setField('MyTestField', strtolower($val));
    }

    public function getCMSFields()
    {
        $fields = parent::getCMSFields();

        $fields->insertAfter('Title', TextField::create('MyTestField'));

        return $fields;
    }
}

Silverstripe 4

Input value into field:
Screen Shot 2023-02-27 at 1 44 54 PM

Value after page is saved:
Screen Shot 2023-02-27 at 1 45 42 PM

Silverstripe 5

Input value into field:
Screen Shot 2023-02-27 at 1 47 22 PM

Value after page is saved:
[no change to field value]

Working in both Silverstripe 4 and 5

Interestingly, if I create a test that explicitly sets a value to my field, then this correctly call my setter in both Silverstripe 4 and 5.

class PageTest extends SapphireTest
{
    public function testSetMyTestField(): void
    {
        $page = Page::create();
        $page->MyTestField = 'Uppercase Words Here';

        Debug::dump($page->MyTestField);
    }
}

Output in both major versions:

====================================================
PageTest.php:16 - App\Tests\PageTest::testSetMyTestField()

uppercase words here
====================================================

PRs

@GuySartorelli
Copy link
Member

This is a direct result of #10614

Where saving values from formfields used to go through the full __set() pipeline, it's now only going through setField() which has caused this regression, since it's no longer checking for and subsequently calling the setter methods.

@emteknetnz
Copy link
Member

Linked PR has been merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants