silverstripe-cms icon indicating copy to clipboard operation
silverstripe-cms copied to clipboard

Merge SiteTreeURLSegmentField and SegmentField

Open maxime-rainville opened this issue 2 years ago • 5 comments

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.

maxime-rainville avatar Oct 07 '22 03:10 maxime-rainville

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.

GuySartorelli avatar Oct 07 '22 03:10 GuySartorelli

If this looks like it's going to take more than a day drop it.

maxime-rainville avatar Jan 09 '23 22:01 maxime-rainville

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 image

Click edit image

Modify it - note js changetracker correctly picks up change and CMS "Save" and "Publish" buttons change to solid green image

Click inline save - mistakently has -2 suffixed to it, also has lost the domain prefix and ?stage=Stage suffix image

Click page save button image

emteknetnz avatar Jan 17 '23 02:01 emteknetnz

If this looks like it's going to take more than a day drop it.

Will close issue without doing work

emteknetnz avatar Jan 17 '23 02:01 emteknetnz

I would still like this to happen in some way even if it's not in CMS5.

maxime-rainville avatar Jan 18 '23 09:01 maxime-rainville