-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
recovered data from collapsed hard drive
Unfortunately while in the middle of upgrading this project I suffered a hard drive failure. Luckily though data was recoverable. I suppose this half-way state of non-functional code is more a reminder of direction than a finished product.
- Loading branch information
Showing
21 changed files
with
885 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# For more information about the properties used in | ||
# this file, please see the EditorConfig documentation: | ||
# http://editorconfig.org/ | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.{yml,js,json,css,scss,eslintrc}] | ||
indent_size = 2 | ||
|
||
[composer.json] | ||
indent_size = 4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mappings: | ||
Slug: Nightjar\Slug\Slug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,115 @@ | ||
# ssrigging-slug | ||
|
||
##Requirements | ||
* Silverstripe 3.1 | ||
* cms module (optional) | ||
## Requirements | ||
|
||
##Installation | ||
* Simply drop into silverstripe root (using whatever method) | ||
* `dev/build` | ||
* silverstripe/framework ^4 | ||
* silverstripe/cms (optional) | ||
|
||
**Please note:** For a SilverStripe 3 compatible version, please see [the 1.0.0 release](https://github.com/nightjar/ssrigging-slug/tree/1.0.0). | ||
|
||
## Installation | ||
|
||
1. `composer require nightjar/ss-slug` | ||
2. Apply the extensions as desired | ||
3. `dev/build` | ||
|
||
## Usage | ||
|
||
##Usage | ||
It is best to supply parameters with the extension (though not necessary if the defaults are sufficient, see **About:Properties** below), so the easiest method of applying it is by definition in the class itself | ||
|
||
```php | ||
namespace MyVendor\MyNamespace; | ||
|
||
use SilverStripe\ORM\DataObject; | ||
use Nightjar\Slug\Slug; | ||
|
||
class Item extends DataObject { | ||
private static $extensions = array( | ||
'Slug("Title", "ParentID", true)' //Apply Extension! | ||
); | ||
private static $db = array( | ||
'Title' => 'Varchar' | ||
); | ||
private static $has_one = array( | ||
'Parent' => 'ItemsPage' | ||
); | ||
public function Link() { | ||
return $this->Parent()->Link().$this->URLSlug.'/'; | ||
} | ||
private static $extensions = [ | ||
Slug::class . '("Title", "ParentID", true)' // Apply Extension! | ||
]; | ||
private static $db = [ | ||
'Title' => 'Varchar' | ||
]; | ||
private static $has_one = [ | ||
'Parent' => 'ItemsPage' | ||
]; | ||
public function Link() { // Will override extension's Link() method | ||
return $this->Parent()->Link().$this->URLSlug.'/'; | ||
} | ||
} | ||
``` | ||
This part is optional, but is a common pattern (and part of this example as a whole). One does not necessarily have to use Page at all, or any kind of 'parent' type model object. | ||
|
||
Or this could happen via _config yaml files | ||
|
||
```yaml | ||
# Generate URL 'slugs' for Items | ||
MyVendor\MyNamespace\Item | ||
- extensions: | ||
- Nightjar\Slug\Slug('Title','ParentID',true) | ||
``` | ||
This part is optional, but is a common pattern (and part of this example as a whole). One does not necessarily have to use `Page` for this, or any kind of 'parent' type model object (as the slug extension at base simply adds a property to a model). | ||
|
||
```php | ||
namespace MyVendor\MyNamespace; | ||
use Page; | ||
class ItemsPage extends Page { | ||
private static $has_many = array( | ||
'Items' => 'Item' | ||
); | ||
private static $has_many = [ | ||
'Items' => 'Item' | ||
]; | ||
} | ||
``` | ||
|
||
Then comes the much more necessary part where one adds a Controller method to access the items decorated items via a request (provided example here is for a Page_Controller). The method/action names are of course exemplary; So long as the applicable configuration elements are all consistent, the names can of course change. | ||
|
||
```php | ||
class ItemsPage_Controller extends Page_Controller { | ||
private static $url_handlers = array( | ||
'$Item!' => 'viewItem' | ||
); | ||
private static $allowed_actions = array( | ||
'viewItem' | ||
); | ||
public function viewItem() { | ||
$item = $this->getItem(); | ||
if(!$item) $this->httpError(404); | ||
return array('Item' => $this->Items()->filter('URLSlug', $this->request->param('Item'))->first()); | ||
} | ||
//One can use something like this to <% if $Top.activeItem == $Slug %> in a menu | ||
public function activeItem() { | ||
return $this->request->param('Item'); | ||
} | ||
namespace MyVendor\MyNamespace; | ||
use PageController; | ||
use Nightjar\Slug\SlugHandler; | ||
class ItemsPageController extends PageController { | ||
private static $url_handlers = [ | ||
'$Item!' => 'viewItem' | ||
]; | ||
private static $allowed_actions = [ | ||
'viewItem' | ||
]; | ||
public function viewItem() { | ||
$item = $this->getItem(); | ||
if(!$item) $this->httpError(404); | ||
return ['Item' => $this->Items()->filter('URLSlug', $this->request->param('Item'))->first()]; | ||
} | ||
//One can use something like this to <% if $Top.activeItem == $Slug %> in a menu | ||
public function activeItem() { | ||
return $this->request->param('Item'); | ||
} | ||
} | ||
``` | ||
One can then define a template such as ItemsPage_viewItem.ss | ||
|
||
One can then define a template such as MyVendor/MyNamespace/ItemsPage_viewItem.ss | ||
|
||
```html | ||
<% with $Item %> | ||
$Title | ||
... | ||
$Title | ||
... | ||
<% end_with %> | ||
``` | ||
|
||
##About | ||
## About | ||
The holder/child page type pattern is often... potentially unwieldy in undefined numbers. Other modules don't particularly give the flexibility required. ModelAdmin is for managing a type of Model, not for exposing them as pages via a site's front end. Slug provides a much needed a more generic solution, and can be applied easily to multiple objects on a site with minimal fuss. It should even work when they're accessed through the same controller provided one takes care in setting up the access methods. | ||
|
||
###Properties | ||
### Properties | ||
The Extension takes three parameters, all of which are optional: | ||
|
||
1. The name of the field it should use to create a slug. (defaults to 'Title') | ||
2. The name of a relation on the 'parent' object (Page, in the example above), allowing for nested URLs. By default a slug must of course be unique, and this is usually globally to the extended class. However defining a 'parent ID' allows for a slug to be unique under that parent only. Eg. With the page setup above if `ItemsPage`s were set up to list primary colours, one can have both `primary-colours/red` AND `primary-light-colours/red`, rather than `primary-light-colours/red1`. (defaults to null) | ||
3. A parity bit. If set to true, whenever the field the module is bound to (Title by default, see 1.) is updated, the slug will automatically update also (keeping parity). Setting this to true also prevents the slug from being manually altered via the CMS by _not_ applying the field to the EditForm. (defaults to false) | ||
|
||
##Notes | ||
## Notes | ||
- Very simple in code, however an often sought after concept implemented as a great (and flexible) time saver. Concepts also good as a tutorial for learners... uuh, learning. Covers extensions, actions, routing, & request parameters. | ||
- If a DataObject named Lettuce exists, it's data consistency will be compromised. Apply the silverstripe-blitzem extension to protect against this. | ||
- This extension will probably cease to work if the DataObject it is applied to is named [BLITZEM](http://www.yates.co.nz/brand/blitzem/). Untested. | ||
- _The previous two notes are jokes._ :) | ||
- _The previous two notes are jokes._ :) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
Name: sluggy | ||
--- | ||
SilverStripe\Core\Injector\Injector: | ||
# Never register an Extension that takes args as a singleton | ||
# Singleton is default, and the name (without args) is used as the ID. | ||
# @see SilverStripe\Core\Injector\Injector::getNamedService | ||
Nightjar\Slug\Slug: | ||
class: Nightjar\Slug\Slug | ||
type: prototype | ||
# set up convenience & backwards compatiblity references | ||
Slug: | ||
class: Nightjar\Slug\Slug | ||
type: prototype | ||
SlugHandler: Nightjar\Slug\SlugHandler |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,37 @@ | ||
{ | ||
"name": "nightjar/ss-slug", | ||
"description": "Serve DataObjects as pages through an Action on a relation's Page_Controller without referencing the ID", | ||
"type": "silverstripe-module", | ||
"keywords": ["silverstripe","extension"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Nightjar" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/Nightjar/ssrigging-slug/issues", | ||
"irc": "irc://chat.freenode.org/silverstripe" | ||
}, | ||
"require": { | ||
"silverstripe/framework": ">=3.1" | ||
}, | ||
"extra": { | ||
"installer-name": "slug" | ||
} | ||
"name": "nightjar/ss-slug", | ||
"description": "Serve DataObjects as pages through an Action on a relation's Controller without referencing the ID", | ||
"type": "silverstripe-vendormodule", | ||
"keywords": ["silverstripe","extension","slug"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Nightjar" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/Nightjar/ssrigging-slug/issues", | ||
"irc": "irc://chat.freenode.org/silverstripe", | ||
"slack": "https://silverstripe-users.slack.com" | ||
}, | ||
"require": { | ||
"silverstripe/framework": "^4" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^5.7", | ||
"squizlabs/php_codesniffer": "^3.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Nightjar\\Slug\\": "src/", | ||
"Nightjar\\Slug\\Tests\\": "tests/" | ||
} | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "2.x-dev" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ruleset name="SilverStripe"> | ||
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description> | ||
|
||
<rule ref="PSR2" > | ||
<!-- Current exclusions --> | ||
<exclude name="PSR1.Methods.CamelCapsMethodName" /> | ||
</rule> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true"> | ||
<testsuite name="Default"> | ||
<directory>tests/</directory> | ||
</testsuite> | ||
<filter> | ||
<whitelist addUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">code/</directory> | ||
<exclude> | ||
<directory suffix=".php">tests/</directory> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
Oops, something went wrong.