library nestable-generator
A json generator and parser for the nestable structure editor
olajoscs/nestable-generator
A json generator and parser for the nestable structure editor
- Thursday, September 7, 2017
- by olajoscs
- Repository
- 1 Watchers
- 0 Stars
- 8 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 4 Versions
- 0 % Grown
nestable-generator
This is a small PHP package, to have a generator and parser for the Nestable2 javascript plugin., (*1)
Requirements
Usage
Instantiating the NestableGenerator
class
- First of all, an array of elements are needed, which will be the base to generate the json. These elements must implement the
Element
interface. Basic functionality is implemented in the AbstractElement
class, but it can be skipped if own implementation is needed.
- An object is needed which implements the
NestedElement
interface - this object is the source of the json generation. The Element
objects are transformed to NestedElement
objects. These NestedElements
objects have a children property, to make possible the structure building.
- The
NestableGenerator
object needs only one constructor parameter: an ElementCollection
object, which are built with the array of Element
objects. This ElementCollection
needs an array of the Element
objects and an empty NestableElement
object, which will be used as reference.
Generating json
Once the NestableGenerator
is created with the ElementCollection
, just call generate()
. It returns the JSON which is needed to Nestable to generate the block., (*2)
Parsing JSON
Nestable can send the created structure in json form. To parse this you need to instantiate the NestableGenerator
class and call parse($json)
, where the $json
is the JSON string, generated by Nestable .
It returns the array of the Element
objects., (*3)