zauberfisch/silverstripe-urlsegment-extension

SilverStripe module to add an URLSegment to DataObjects. Includes FormField

v1.0.0 2022-01-16 22:11 UTC

This package is auto-updated.

Last update: 2024-09-17 03:44:05 UTC


README

Utility/DataExtension for adding an URLSegment field to a DataObject. Also includes a FormField.

Currently hardcoded to create the field URLSegment and use Title as a source.

Maintainer Contact

Requirements

  • php >=7.4
  • silverstripe/framework >=4

Installation

  • composer require "zauberfisch/silverstripe-urlsegment-extension"
  • rebuild manifest (flush)

Documentation

<?php

/**
* @property string $Title
* @method \SilverStripe\CMS\Model\SiteTree TeamPage()
 */
class TeamMember extends \SilverStripe\ORM\DataObject {
    private static $db = [
        'Title' => \SilverStripe\ORM\FieldType\DBVarchar::class,
    ];
    private static $has_one = [
        'TeamPage' => \SilverStripe\CMS\Model\SiteTree::class,
    ];

    private static $extensions = [
        \zauberfisch\URLSegmentExtension\URLSegmentDataExtension::class,
    ];

    public function getCMSFields() {
        $urlPrefix = $this->TeamPage()->Link();
        $urlSuffix = "";
        $fields = parent::getCMSFields();
        $fields->removeByName('URLSegment');
        $fields->addFieldsToTab( 'Root.Main', [
            new \zauberfisch\URLSegmentExtension\URLSegmentFormField('URLSegment', $this->fieldLabel('URLSegment'), $urlPrefix, $urlSuffix),
        ]);
        return $fields;
    }
}