dev-master
9999999-devA Drupal 7 ORM as headless version
GPL
The Requires
- php >=5.5.0
The Development Requires
by Juan Lago
orm database php drupal
Wallogit.com
2017 © Pedro Peláez
A Drupal 7 ORM as headless version
The DrupalHeadless project provides the following components as a compatible PSR-4 package:, (*1)
This package was created in order to provide an elegant and suitable way of interact with Drupal 7 databases without the requeriment of install a full Drupal 7 stack. DrupalHeadless can used as with standalone scripts or can be deployed via composer in different solutions like for example Drupal 8., (*2)
If you are familiar with Drupal 7 Database API, then it is going to be easy for you to use the DrupalHeadless database abstraction layer because it is based in the original abstraction layer., (*3)
use \DrupalHeadless\Database\Database;
// Set connection info
Database::addConnectionInfo('default', 'default', [
'driver' => 'mysql',
'database' => 'drupal',
'username' => 'root',
'password' => 'root',
'host' => '127.0.0.1',
'prefix' => 'drupal_'
]);
$query = Database::getConnection('default', 'default');
$st = $query->select('node', 'n');
$result = $st->fields('n')
->range(0, 10)
->execute()
->fetchAll();
As an alternative it is also possible to use the statement helper:, (*4)
use \DrupalHeadless\Database\Database;
use \DrupalHeadless\Database\DatabaseHelper as DH;
// Set connection info
Database::addConnectionInfo('default', 'default', [
'driver' => 'mysql',
'database' => 'drupal',
'username' => 'root',
'password' => 'root',
'host' => '127.0.0.1',
'prefix' => 'drupal_'
]);
$result = DH::select('node', 'n')
->fields('n')
->range(0, 10)
->execute()
->fetchAllAssoc('nid');
use \DrupalHeadless\Database\Database;
use \DrupalHeadless\Entity\EntityController as EC;
use \DrupalHeadless\Entity\Model;
// Set connection info
Database::addConnectionInfo('default', 'default', [
'driver' => 'mysql',
'database' => 'drupal',
'username' => 'root',
'password' => 'root',
'host' => '127.0.0.1',
'prefix' => 'drupal_'
]);
$connection = Database::getConnection('default', 'default');
// Search the first 5 nodes with bundle "article" that contain the word "Test" into the body field
$result_node = EC::entity($connection, new Model\Node(), 'article')
->load()
->select()
->fieldCondition('body', 'value', '%Test%', 'LIKE')
->range(0, 5)
->fetchAll();
// Search the user with UID = 1
$result_user = EC::entity($connection, new Model\Users(), 'user')
->load()
->select()
->propertyCondition('uid', 1)
->fetch();
use \DrupalHeadless\Database\Database;
use \DrupalHeadless\Entity\EntityController as EC;
use \DrupalHeadless\Entity\Model;
// Set connection info
Database::addConnectionInfo('default', 'default', [
'driver' => 'mysql',
'database' => 'drupal',
'username' => 'root',
'password' => 'root',
'host' => '127.0.0.1',
'prefix' => 'drupal_'
]);
$connection = Database::getConnection('default', 'default');
$entity = EC::entity($connection, new Model\Node(), 'article')->load();
// Load entity node and bundle "article" which "title" is equal to "This is a test"
$result_node = $entity->propertyCondition('title', 'This is test')->fetch();
// Insert into the custom/dynamic field the value "myvideo" with delta 0
$entity = $entity->insertFieldset('field_videoid', $result_node->nid, ['value' => 'myvideo'], 0);
A Drupal 7 ORM as headless version
GPL
orm database php drupal