silverstripe-cms
silverstripe-cms copied to clipboard
Merge SiteTreeURLSegmentField and SegmentField
There's SiteTreeURLSegmentField in the CMS module and a derivative SegmentField in its own module. The derivative is used by UserForm.
SegmentField
seems generally better in every way and is more flexible since it allows you to use it for any DataObject
.
Acceptance criteria
- [ ] The SegmentField module is folded back in to CMS or SegmentField becomes a dependency of CMS.
- [ ] The SegmentField medule readme is updated accordingly
- [ ] CMS start using SegmentField to manage URLSegment of SiteTrees
- [ ] UserForm's usage of SegmentField is still functional and dependency on
silverstripe/segment-field
. - [ ] Current URLSegment filed UI is retained.
Notes
- By itself, this is pretty low value, but it potentially saves us from having to make the SegmentField module CMS5 compatible.
- Userform has not been made CMS5 compatible yet.
NOTE: The segment field derivative seems more useful than just the way CMS uses it. It should probably be put in framework or admin, so projects which don't use this module can take advantage of it.
If this looks like it's going to take more than a day drop it.
I've spent some time getting SegmentField working on SiteTree and I just don't feel like this is worth doing considering the effort required, particularly when the motivation is "potentially saves us from having to make the SegmentField module CMS5 compatible." which is trivial
There's nothing "bad" about the existing functionality and I see little value consolidating this to only use SegmentField.
Out of the box this does not seem like a suitable substitute for SiteTreeURLSegmentField
which has a bunch of custom functionality such as a hyperlink, automatically gets the domain prefixed + ?stage=Stage suffixed. We'd need to do extra work on SegmentField to make it behave like the existing SiteTreeURLSegmentField. This seems like a waste of effort when we already have working code.
I used the following code in case anyone wants to replicate
SiteTree::getCMSFields():2086
$defaultUrlSegment = $this->generateURLSegment(_t(
'SilverStripe\\CMS\\Controllers\\CMSMain.NEWPAGE',
'New {pagetype}',
['pagetype' => $this->i18n_singular_name()]
));
$urlsegment = SegmentField::create('URLSegment')
->setModifiers([
SlugSegmentFieldModifier::create()->setDefault($defaultUrlSegment),
['-', ''],
IDSegmentFieldModifier::create(),
])
->setPreview($baseLink . $this->URLSegment . '?stage=Stage')
->addExtraClass(($this->isHomePage() ? 'homepage-warning' : ''))
Page load - no hyperlnk
Click edit
Modify it - note js changetracker correctly picks up change and CMS "Save" and "Publish" buttons change to solid green
Click inline save - mistakently has -2 suffixed to it, also has lost the domain prefix and ?stage=Stage suffix
Click page save button
If this looks like it's going to take more than a day drop it.
Will close issue without doing work
I would still like this to happen in some way even if it's not in CMS5.