PHP code example of dynamic / silverstripe-linkable

1. Go to this page and download the library: Download dynamic/silverstripe-linkable 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/ */

    

dynamic / silverstripe-linkable example snippets


class Page extends SiteTree
{
	private static $has_one = [
		'ExampleLink' => 'Link',
	];

	public function getCMSFields()
	{
		$fields = parent::getCMSFields();

		$fields->addFieldToTab('Root.Link', LinkField::create('ExampleLinkID', 'Link to page or file'));

		return $fields;
	}
}

LinkField::create('ExampleLinkID', 'Link Title')->setAllowedTypes(array('URL','Phone'))

class CustomLink extends DataExtension
{
    private static $has_one = [
        'Product' => 'Product',
    ];

    private static $types = [
        'Product' => 'A Product on this site',
    ];

    public function updateCMSFields(FieldList $fields)
    {
		// update the Link Type dropdown to contain your custom Link types
        $fields->dataFieldByName('Type')->setSource($this->owner->config()->types);

		// Add a dropdown field containing your ProductList
		$fields->addFieldToTab(
            'Root.Main',
            DropdownField::create('ProductID', 'Product', Product::get()->map('ID', 'Title')->toArray())
                ->setHasEmptyDefault(true)
                ->displayIf('Type')->isEqualTo('Product')->end()
        );
	}

class Page extends SiteTre
 {
	private static $has_one = [
		'Video' => 'EmbeddedObject',
	];

	public function getCMSFields()
	{
		$fields = parent::getCMSFields();

		$fields->addFieldToTab('Root.Video', EmbeddedObjectField::create('Video', 'Video from oEmbed URL', $this->Video()));

		return $fields;
	}
}
	...