2017 © Pedro Peláez
 

silverstripe-vendormodule viewable-dataobject

DataExtension that easily allows a DataObject to be viewed like a Page

image

dynamic/viewable-dataobject

DataExtension that easily allows a DataObject to be viewed like a Page

  • Wednesday, July 25, 2018
  • by dynamic
  • Repository
  • 4 Watchers
  • 2 Stars
  • 4,040 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 4 Forks
  • 3 Open issues
  • 4 Versions
  • 28 % Grown

The README.md

SilverStripe Viewable Dataobject

Build Status Scrutinizer Code Quality Code Coverage Build Status codecov, (*1)

Latest Stable Version Latest Unstable Version Total Downloads License Monthly Downloads Daily Downloads, (*2)

DataExtension that easily allows a dataobject to be viewed like a Page, (*3)

Requirements

  • SilverStripe ^4.0

Installation

composer require dynamic/viewable-dataobject, (*4)

In config.yml:, (*5)

MyDataObject:
    extensions:
        - Dynamic\ViewableDataObject\Extensions\ViewableDataObject

Example usage

On the DataObject you'd like to view as a page:, (*6)

<?php

use Dynamic\ViewableDataObject\VDOInterfaces\ViewableDataObjectInterface;

class MyDataObject extends DataObject implements ViewableDataObjectInterface
{
    public function getParentPage()
    {
        return MyDisplayPage::get()->first();
    }

    public function getViewAction()
    {
        return 'myobject';
    }
}

On the Page_Controller you'd like to view your DataObject:, (*7)

<?php

use SilverStripe\Control\HTTPRequest;
use SilverStripe\View\ArrayData;

class MyDisplayPageController extends \PageController
{
    public function myobject(HTTPRequest $request)
    {
        $urlSegment = $request->latestParam('ID');

        if (!$object = MyDataObject::get()->filter('URLSegment', $urlSegment)->first()) {
            return $this->httpError(404, "The object you're looking for doesn't seem to be here.");
        }

        return $this->customise(new ArrayData([
            'Object' => $object,
            'Title' => $object->Title,
            'MetaTags' => $object->MetaTags(false),
            'Breadcrumbs' => $object->Breadcrumbs(),
        ]));
    }
}   

Controller Extension

Adding the controller extension to a class will allow for using custom layout templates., (*8)

In config.yml:, (*9)

MyControler:
    extensions:
        - Dynamic\ViewableDataObject\Extensions\ControllerExtension

Instead of calling render, renderWith, or customize; renderWithLayout can be passed a list of layout templates and extra data., (*10)

<?php

use SilverStripe\Control\HTTPRequest;

class MyDisplayPageController extends \PageController
{
    public function myobject(HTTPRequest $request)
    {
        $urlSegment = $request->latestParam('ID');

        if (!$object = MyDataObject::get()->filter('URLSegment', $urlSegment)->first()) {
            return $this->httpError(404, "The object you're looking for doesn't seem to be here.");
        }

        return $this->renderWithLayout([
            MyDataObject::class,
            MyDisplayPage::class,
        ], [
            'Object' => $object,
            'Title' => $object->Title,
            'MetaTags' => $object->MetaTags(false),
            'Breadcrumbs' => $object->Breadcrumbs(),
        ]);
    }
}   

renderWithLayout will add \Page::class to the end of the template list. The first valid template in the array will be used., (*11)

The Versions

25/07 2018

dev-master

9999999-dev

DataExtension that easily allows a DataObject to be viewed like a Page

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

page silverstripe dataobject viewable

25/07 2017

1.0.x-dev

1.0.9999999.9999999-dev

DataExtension that easily allows a DataObject to be viewed like a Page

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

page silverstripe dataobject viewable

25/07 2017

1.0.0-beta2

1.0.0.0-beta2

DataExtension that easily allows a DataObject to be viewed like a Page

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

page silverstripe dataobject viewable

12/01 2017

1.0.0-beta1

1.0.0.0-beta1

DataExtension that easily allows a DataObject to be viewed like a Page

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

page silverstripe dataobject viewable