An open API service indexing awesome lists of open source software.

https://github.com/dynamic/viewable-dataobject

DataExtension that easily allows a DataObject to be viewed like a Page
https://github.com/dynamic/viewable-dataobject

Last synced: 6 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# SilverStripe Viewable Dataobject
[![Build Status](https://travis-ci.org/dynamic/viewable-dataobject.svg?branch=master)](https://travis-ci.org/dynamic/viewable-dataobject)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/dynamic/viewable-dataobject/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/dynamic/viewable-dataobject/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/dynamic/viewable-dataobject/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/dynamic/viewable-dataobject/?branch=master)
[![Build Status](https://scrutinizer-ci.com/g/dynamic/viewable-dataobject/badges/build.png?b=master)](https://scrutinizer-ci.com/g/dynamic/viewable-dataobject/build-status/master)
[![codecov](https://codecov.io/gh/dynamic/viewable-dataobject/branch/master/graph/badge.svg)](https://codecov.io/gh/dynamic/viewable-dataobject)

[![Latest Stable Version](https://poser.pugx.org/dynamic/viewable-dataobject/version)](https://packagist.org/packages/dynamic/viewable-dataobject)
[![Latest Unstable Version](https://poser.pugx.org/dynamic/viewable-dataobject/v/unstable)](//packagist.org/packages/dynamic/viewable-dataobject)
[![Total Downloads](https://poser.pugx.org/dynamic/viewable-dataobject/downloads)](https://packagist.org/packages/dynamic/viewable-dataobject)
[![License](https://poser.pugx.org/dynamic/viewable-dataobject/license)](https://packagist.org/packages/dynamic/viewable-dataobject)
[![Monthly Downloads](https://poser.pugx.org/dynamic/viewable-dataobject/d/monthly)](https://packagist.org/packages/dynamic/viewable-dataobject)
[![Daily Downloads](https://poser.pugx.org/dynamic/viewable-dataobject/d/daily)](https://packagist.org/packages/dynamic/viewable-dataobject)

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

## Requirements

- SilverStripe ^4.0

## Installation

`composer require dynamic/viewable-dataobject`

In config.yml:

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

## Example usage

On the DataObject you'd like to view as a page:

```php
first();
}

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

On the Page_Controller you'd like to view your DataObject:

```php
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.

In config.yml:
```yml
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.

```php
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.