Skip to content

Instantly share code, notes, and snippets.

@tynor
Created January 25, 2016 01:13
Show Gist options
  • Save tynor/5001dd4cfdc91e5261d8 to your computer and use it in GitHub Desktop.
Save tynor/5001dd4cfdc91e5261d8 to your computer and use it in GitHub Desktop.
<?php
// HOW TO CREATE A NODE
$node = new stdClass();
$node->title = 'the title';
$node->type = 'node_type';
node_object_prepare($node);
$node->language = LANGUAGE_NONE;
$node->uid = 1;
$node->status = 1;
$node->promote = 0;
$node->comment = 2;
$node = node_submit($node);
node_save($node);
// HOW TO CREATE A USER
$fields = array(
'name' => 'user_name',
'mail' => 'email@example.com',
'pass' => 'password',
'status' => 1,
'init' => 'email address',
'roles' => array(
DRUPAL_AUTHENTICATED_RID => 'authenticated user',
),
);
user_save(null, $fields);
// HOW TO CREATE AN ENTITY THAT USES ENTITY API (for example, commerce_order)
$order = commerce_order_new()
commerce_order_save($order)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment