-
Notifications
You must be signed in to change notification settings - Fork 3
3. Backend
Antonio De Marco edited this page Jan 22, 2016
·
7 revisions
TBD
To create a Backend programmatically we will make use of the BackendFactory
static class. In order to have a Backend working correctly we need to add at least one Resource Schema object, so we should need to create that first.
The code would look something like the following:
use Drupal\integration\Backend\BackendFactory;
use Drupal\integration\ResourceSchema\ResourceSchemaFactory;
$resource_schema = ResourceSchemaFactory::create('article')
->setField('title', 'Title')
->setField('image', 'Image')
->setField('body', 'Body');
$backend = BackendFactory::create('filesystem')
->setPluginSetting('path', '/path/to/data')
->setResourceSchema('article')
->setResourceSchemaSetting('article', 'folder', 'article');
Note that, at this point, Backend and Resource Schema configuration is only stored in the class static cache. To persist configuration objects in the database use the following:
$backend->getConfiguration()->save();
$resource_schema->getConfiguration()->save();