PHP code example of zauberfisch / silverstripe-uid-dataobject

1. Go to this page and download the library: Download zauberfisch/silverstripe-uid-dataobject library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zauberfisch / silverstripe-uid-dataobject example snippets




class MyDataObject extends \SilverStripe\ORM\DataObject {
	private static $extensions = [
		\zauberfisch\UidDataObject\UuidDataObjectExtension::class,
	];
	private static $uuid_version = 4; // optional, default: 4

    public function getCMSFields() {
        $fields = parent::getCMSFields();
        $fields->removeByName('UUID');
        $fields->addFieldsToTab( 'Root.Main', [
            new \SilverStripe\Forms\ReadonlyField('UUID', "Universally unique identifier"),
        ]);
        return $fields;
    }
}



class MyDataObject extends \SilverStripe\ORM\DataObject {
	private static $extensions = [
		\zauberfisch\UidDataObject\UuidDataObjectExtension::class,
	];
	private static $uuid_version = 1;

    public function getCMSFields() {
        $fields = parent::getCMSFields();
        $fields->removeByName('UUID');
        $fields->addFieldsToTab( 'Root.Main', [
            new \SilverStripe\Forms\ReadonlyField('UUID', "Universally unique identifier"),
        ]);
        return $fields;
    }
}



class MyDataObject extends \SilverStripe\ORM\DataObject {
	private static $extensions = [
		\zauberfisch\UidDataObject\CustomUidDataObjectExtension::class,
	];
		private static $custom_uid_prefix = 'abc-'; // optional: ""
	private static $custom_uid_suffix = ''; // optional, default: ""
	private static $custom_uid_length = 8; // optional, default: 8

    public function getCMSFields() {
        $fields = parent::getCMSFields();
        $fields->removeByName('UID');
        $fields->addFieldsToTab( 'Root.Main', [
            new \SilverStripe\Forms\ReadonlyField('UID', "My Unique ID"),
        ]);
        return $fields;
    }
}