wolfcms/wolfcms — pull request #556 by nicwortel (2013-10-07 21:07:53+00:00)
Title: Improves the Node class

This pull request includes a couple of improvements to the Node class.

A number of methods that were previously only defined in `Page`, have been added to `Node` as abstract methods, so they are required for any class that extends Node. The idea is that plugins that serve frontend content that isn't saved in the DB's `page` table can create classes that extend the Node class. Functionality that `Page`s have in common with other `Node`s, can be moved to the `Node` class in order to prevent duplication of code.

Certain `Page` methods cannot be implemented by `Node` because their implementation is specific to the Page model (for instance because the values are retrieved from the database). However, by defining them as `abstract` in `Node`, we ensure that they are implemented by all classes that extend `Node`, without having to implement them already in `Node`. This way we can rely on their existance when we are handling a node object, for instance in a layout.

* `breadcrumb()`
* `children()`
* `content($part, $inherit)`
* `description()`
* `hasContent($part, $inherit)`
* `keywords()`
* `parent($level)`
* `slug()`
* `title()`

Furthermore, a number of methods that were defined by `Page` but could apply to other `Node`-extending classes as well, have been moved to the `Node` class:

* `level()`
* `path()`
* `url()`
* `link()`

None of the above methods are declared `final`, so they can be overruled by nodes that require different behavior / output.

Another functionality that has moved to the `Node` class, is the `breadcrumbs()` method. The method has been refactored using another new method, `ancestors()`, that returns an array of all parents of the current node, starting with the Home page. This refactoring was required to make the method page-agnostic. The `ancestors()` method is also being used to simplify the `level()` method.

Although `breadcrumbs()` has remained mostly the same, users can use `ancestors()` instead to create custom breadcrumb trails (for instance wrapped in a `

` instead of plain text).

## Suggestions ##
It might be a good idea to add/move the following methods to `Node` as well:
- [ ] `author()` (as abstract)
- [ ] `updater()` (as abstract)
- [ ] `previous()` (as abstract)
- [ ] `next()` (as abstract)
- [ ] `tags()`? (should return an empty array by default I think)
- [ ] `date()` (as abstract)
- [ ] `executeLayout()` (with an alias named `_executeLayout()`)
- [ ] `layoutId()` (but protected instead of private, so plugins can override it with a specific layout)