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

ENH Various changes to support SiteTree form field scaffolding #11327

Merged

Conversation

GuySartorelli
Copy link
Member

@GuySartorelli GuySartorelli marked this pull request as draft August 8, 2024 01:47
@GuySartorelli GuySartorelli force-pushed the pulls/6/scaffold-sitetree branch 2 times, most recently from 9ee0b8c to 7394956 Compare August 12, 2024 01:41
*/
public $includeRelations = false;
public bool|array $includeRelations = false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the code that uses this, you could use it to explicitly only allow has_many relations but not many_many relations (or vice versa) - in which case it needs to be an associative array. Hence bool|array.

Copy link
Member Author

@GuySartorelli GuySartorelli Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added strict typing for the properties as a matter of course - it's unrelated refactoring.

Comment on lines -109 to +103
if ($this->restrictFields && !in_array($fieldName, $this->restrictFields ?? [])) {
if (!empty($this->restrictFields) && !in_array($fieldName, $this->restrictFields)) {
Copy link
Member Author

@GuySartorelli GuySartorelli Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be an array, so we can tidy this a little now. Applies to similar changes below as well.

@GuySartorelli GuySartorelli force-pushed the pulls/6/scaffold-sitetree branch 2 times, most recently from 05d5b9f to 0f6c387 Compare August 12, 2024 01:53
Comment on lines 101 to 109
public function setName($name)
{
if ($this->ID() === Convert::raw2htmlid($this->getName())) {
$this->setID(Convert::raw2htmlid($name));
}
return parent::setName($name);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures the id attribute in the HTML markup correctly reflects the name, even if the name is set after the tab was created. This is needed by https://github.com/silverstripe/silverstripe-userforms/pull/1315/files#diff-d659fc65ecb263c36d5428815131e80ef3c1750bf18e18860f1fd9d79d4df3e0R195 because the relation name doesn't match the name we want for the tab.

It's also just a sensible change to make.

Note that we don't set the ID if the ID was manually set to something other than the name.

@GuySartorelli GuySartorelli changed the title TODO: Break this out into appropriate PRs for CMS 5 vs CMS 6 ENH Various changes to support SiteTree form field scaffolding Aug 12, 2024
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes here are to support the new strict types, and removing the deprecated ajaxSafe

@GuySartorelli GuySartorelli marked this pull request as ready for review August 12, 2024 02:30
Comment on lines +12 to +29
public function testNameAndID(): void
{
// ID is set on instantiation based on the name
$tab = new Tab('MyName _-()!@#$');
$this->assertSame('MyName _-()!@#$', $tab->getName());
$this->assertSame('MyName_-', $tab->ID());

// Changing the name changes the ID
$tab->setName('NewName');
$this->assertSame('NewName', $tab->getName());
$this->assertSame('NewName', $tab->ID());

// If ID is explicitly set, changing the name doesn't override it
$tab->setID('Custom-ID');
$tab->setName('AnotherName');
$this->assertSame('AnotherName', $tab->getName());
$this->assertSame('Custom-ID', $tab->ID());
}
Copy link
Member Author

@GuySartorelli GuySartorelli Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't use a data provider for this - the scenarios need to be run sequentially.

@emteknetnz emteknetnz merged commit 64a17e0 into silverstripe:6 Aug 15, 2024
15 checks passed
@emteknetnz emteknetnz deleted the pulls/6/scaffold-sitetree branch August 15, 2024 01:15
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

Successfully merging this pull request may close these issues.

2 participants