olajoscs / nestable-generator
A json generator and parser for the nestable structure editor
1.0.1
2017-09-07 07:54 UTC
Requires
- php: ~7.1
Requires (Dev)
- phpunit/phpunit: ^5.3.0
This package is not auto-updated.
Last update: 2025-01-04 04:08:07 UTC
README
This is a small PHP package, to have a generator and parser for the Nestable2 javascript plugin.
Requirements
- php ~7.1
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 theAbstractElement
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. TheElement
objects are transformed toNestedElement
objects. TheseNestedElements
objects have a children property, to make possible the structure building. - The
NestableGenerator
object needs only one constructor parameter: anElementCollection
object, which are built with the array ofElement
objects. ThisElementCollection
needs an array of theElement
objects and an emptyNestableElement
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.
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.