PHP code example of taitava / silverstripe-cmseditlink

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

    

taitava / silverstripe-cmseditlink example snippets


$book = Book::get()->byID(1);
$link = $book->CMSEditLink();

$book = Book::get()->byID(1);
$link = Taitava\CMSEditLink\CMSEditLink::LinkFor($book);

class Book extends DataObject
{
        public function getModelAdminForCMSEditLink()
        {
                return BookAdminWhichHandlesBooksWithSoftGloves::class;
                // Or:
                return BookAdminWhichHandlesBooksWithSoftGloves::create();
        }
}

class BookAdminWhichTearsPagesAndBurnsThemToAshes
{
        $managed_models = [
        	Book::class,
        ];
}

class BookAdminWhichHandlesBooksWithSoftGloves extends ModelAdmin
{
        $managed_models = [
        	Book::class,
        ];
}

$book = Book::get()->byID(1);
$book->CMSEditLink()->via($book->Library(), 'Books');

$library = Library::get()->byID(1);
$library->CMSEditLink()->hereon($library->Books()->first(), 'Books');

$book = Book::get()->byID(1);
$link = $book->CMSEditLink()->action('customAction');

$book = Book::get()->byID(1);
$link = $book->CMSEditLink('customAction');

class Book extends DataObject
{
        private static $has_one = [
                'Library' => Library::class,
        ];

        public function ProvideCMSEditLink($action)
        {
                if ($action == 'edit') $action = 'tagAuthors'; // Switch the default 'edit' action to an author tagging action, or whatever.
                $link = CMSEditLink::LinkFor($this,$action);
                $link->via($this->Library(), 'Books'); // Scaffold the link via the book's holder Library
                return $link; // The alterations made in this function ...
        }
}

class Library extends DataObject
{
        private static $has_many = [
                'Books' => Book::class,
        ];
}

$book = Book::get()->byID(1);
$link = $book->CMSEditLink(); // ... will be in place here.