Skip to content

Commit

Permalink
Merge pull request #42 from creative-commoners/pulls/2.0/whats-up-docs
Browse files Browse the repository at this point in the history
FIX Registry specific class template overrides, update documentation
  • Loading branch information
NightJar committed Nov 22, 2017
2 parents 45efffe + 9df568f commit c4c649e
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 50 deletions.
13 changes: 7 additions & 6 deletions README.md
@@ -1,11 +1,14 @@
# Registry module

[![Build Status](https://secure.travis-ci.org/silverstripe/silverstripe-registry.png)](http://travis-ci.org/silverstripe/silverstripe-registry)
[![Build Status](http://img.shields.io/travis/silverstripe/silverstripe-registry.svg?style=flat)](https://travis-ci.org/silverstripe/silverstripe-registry)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/silverstripe/silverstripe-registry/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/silverstripe/silverstripe-registry/?branch=master)
[![codecov](https://codecov.io/gh/silverstripe/silverstripe-registry/branch/master/graph/badge.svg)](https://codecov.io/gh/silverstripe/silverstripe-registry)

## Requirements

* SilverStripe 3.1 or newer
* MySQL 5.1+ or SQL Server 2008+ database
* SilverStripe ^4.0

**Note:** For a SilverStripe 3.x compatible version, please use [the 1.x release line](https://github.com/silverstripe/silverstripe-registry/tree/1.0).

## Installation

Expand All @@ -15,9 +18,7 @@ Install with Composer:
composer require silverstripe/registry
```

Alternatively, copy the registry directory into your SilverStripe project.

When the module is installed, append `dev/build?flush=all` to the website URL in your browser. e.g. http://mysite.com/dev/build?flush=all.
When the module is installed, run a `dev/build` in your browser, or from the command line via `vendor/bin/sake dev/build`.

## Instructions

Expand Down
104 changes: 63 additions & 41 deletions docs/en/index.md
Expand Up @@ -21,23 +21,32 @@ A DataObject must implement `RegistryDataInterface` and the

In this example we've created a `StaffMember` class:

:::php
<?php
class StaffMember extends DataObject implements RegistryDataInterface {
public static $db = array(
'Name' => 'Varchar(255)',
'PhoneNumber' => 'Varchar(50)'
);
public function getSearchFields() {
return new FieldList(
new TextField('Name'),
new TextField('PhoneNumber')
);
}
}

Once that's defined, we run `dev/build?flush=1` to build the database with the new class.
```php
<?php

use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataObject;
use SilverStripe\Registry\RegistryDataInterface;

class StaffMember extends DataObject implements RegistryDataInterface
{
public static $db = [
'Name' => 'Varchar(255)',
'PhoneNumber' => 'Varchar(50)',
];

public function getSearchFields()
{
return FieldList::create(
TextField::create('Name'),
TextField::create('PhoneNumber')
);
}
}
```

Once that's defined, we run `dev/build` to build the database with the new class.

### Managing the data

Expand Down Expand Up @@ -68,16 +77,22 @@ SilverStripe has a built-in way of defining summary fields on a DataObject. You
the static `$summary_fields` in the DataObject definition. The array is a map of `$db` column name to
a viewable title the user will see. In this example we're adding the phone number to the summary list.

:::php
<?php
class StaffMember extends DataObject implements RegistryDataInterface {
//...
public static $summary_fields = array(
'Name' => 'Name',
'PhoneNumber' => 'Phone number'
);
//...
}
```php
<?php

use SilverStripe\ORM\DataObject;
use SilverStripe\Registry\RegistryDataInterface;

class StaffMember extends DataObject implements RegistryDataInterface
{
//...
public static $summary_fields = [
'Name' => 'Name',
'PhoneNumber' => 'Phone number',
];
//...
}
```

Now when you view the staff member listing on the **Registry Page** it will show the two columns we
defined above.
Expand All @@ -90,16 +105,23 @@ Sometimes the records listed you'll want a user to click through and see more de

You can do this by defining the `Link` method on your registry class. For example:

:::php
<?php
class StaffMember extends DataObject implements RegistryDataInterface {
//...
public function Link($action = 'show') {
$page = RegistryPage::get()->filter('DataClass', 'StaffMember')->First();
return Controller::join_links($page->Link(), $action, $this->ID);
}
//...
}
```php
<?php

use SilverStripe\ORM\DataObject;
use SilverStripe\Registry\RegistryDataInterface;

class StaffMember extends DataObject implements RegistryDataInterface
{
//...
public function Link($action = 'show')
{
$page = RegistryPage::get()->filter('DataClass', StaffMember::class)->First();
return Controller::join_links($page->Link(), $action, $this->ID);
}
//...
}
```

This method can return a link to any place you wish. The above example will link to
the `show` action on the `RegistryPage` for `StaffMember`. Note that this assumes that there is
Expand All @@ -119,17 +141,17 @@ first look for `Title`, then for `Name`, then default to the `ID`.

While the default template does its best to be functional and easy-to-style, it's quite likely that
you'll need to change the templates. You can do so by placing the templates `RegistryPage.ss` and
`RegistryPage_show.ss` in your themes templates/Layout folder. You can base these off the files found
in registry/templates/Layout.
`RegistryPage_show.ss` in your themes `templates/SilverStripe/Registry/Layout` folder. You can base these off the
files found in `vendor/silverstripe/registry/templates/SilverStripe/Registry/Layout`.

As a further layer of customisation, you can create templates that will be only used when viewing
specific registries. So if you wanted to create a template that would only be used to view the
StaffMember registry, you would create `RegistryPage_StaffMember.ss` and `RegistryPage_StaffMember_show.ss`
StaffMember registry, you would create `My/Namespaced/StaffMember_RegistryPage.ss` and `My/Namespaced/StaffMember_RegistryPage_show.ss`

## Contributing

### Translations

Translations of the natural language strings are managed through a third party translation interface, transifex.com. Newly added strings will be periodically uploaded there for translation, and any new translations will be merged back to the project source code.

Please use [https://www.transifex.com/projects/p/silverstripe-registry](https://www.transifex.com/projects/p/silverstripe-registry) to contribute translations, rather than sending pull requests with YAML files.
Please use [https://www.transifex.com/projects/p/silverstripe-registry](https://www.transifex.com/projects/p/silverstripe-registry) to contribute translations, rather than sending pull requests with YAML files.
Binary file removed docs/en/userguide/_images/registry-admin.jpg
Binary file not shown.
Binary file added docs/en/userguide/_images/registry-admin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en/userguide/_images/registry-page.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/en/userguide/index.md
Expand Up @@ -24,7 +24,7 @@ The built-in features:
A website developer is needed initially to create the “database” that can then be readily managed and interacted with using the CMS.

## Adminstration of registry data
![Registry admin](_images/registry-admin.jpg)
![Registry admin](_images/registry-admin.png)

Pictured above is a summary of the admin area for managing registry data.

Expand Down
4 changes: 2 additions & 2 deletions src/RegistryPageController.php
Expand Up @@ -428,9 +428,9 @@ public function getTemplateList($action)
$actionlessTemplates = [];

if ($action && $action !== 'index') {
array_unshift($templates, $this->DataClass . '_' . $action);
array_unshift($templates, $this->DataClass . '_RegistryPage_' . $action);
}
array_unshift($actionlessTemplates, $this->DataClass);
array_unshift($actionlessTemplates, $this->DataClass . '_RegistryPage');

$parentClass = get_class($this->dataRecord);
while ($parentClass !== RegistryPage::class) {
Expand Down

0 comments on commit c4c649e

Please sign in to comment.