olajoscs / nestable-generator
A json generator and parser for the nestable structure editor
Installs: 12
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/olajoscs/nestable-generator
Requires
- php: ~7.1
Requires (Dev)
- phpunit/phpunit: ^5.3.0
This package is not auto-updated.
Last update: 2025-12-06 08:11:18 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
Elementinterface. Basic functionality is implemented in theAbstractElementclass, but it can be skipped if own implementation is needed. - An object is needed which implements the
NestedElementinterface - this object is the source of the json generation. TheElementobjects are transformed toNestedElementobjects. TheseNestedElementsobjects have a children property, to make possible the structure building. - The
NestableGeneratorobject needs only one constructor parameter: anElementCollectionobject, which are built with the array ofElementobjects. ThisElementCollectionneeds an array of theElementobjects and an emptyNestableElementobject, 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.