PHP code example of heyday / silverstripe-slices

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

    

heyday / silverstripe-slices example snippets




namespace MyProject\DataObjects\Slices;

use Heyday\SilverStripeSlices\DataObjects\Slice;

class ContentSlice extends Slice
{
    protected function getBaseSliceClass()
    {
        return __CLASS__;
    }
}

class VideoSlice extends ContentSlice
{
    // Subclasses of your 'base' subclass don't need anything special
}



namespace MyProject\Extensions;

use MyProject\DataObjects\Slices\ContentSlice;
use Heyday\SilverStripeSlices\Extensions\PageSlicesExtension as BasePageSlicesExtension;

/**
 * Extension to add slice management to Page
 */
class PageSlicesExtension extends BasePageSlicesExtension
{
    /**
     * @var array
     */
    private static $has_many = [
        // update the relation with your sub class
        'Slices' => ContentSlice::class
    ];
}



namespace MyProject\Pages;

use SilverStripe\CMS\Model\SiteTree;

/**
 * Class GenericPage
 */
class GenericPage extends SiteTree
{
    // ...



namespace MyProject\Extensions;

use MyProject\Pages\GenericPage;
use SilverStripe\ORM\DataExtension;

/**
 * Extension to change the parent of a slice
 */
class SliceExtension extends DataExtension
{
    private static $has_one = array(
        'Parent' => GenericPage::class
    );
}

// Re-apply slices config
$config = $this->getCurrentTemplateConfig();
$this->configureFieldsFromConfig($fields, $config);