Skip to content

Instantly share code, notes, and snippets.

@zroger
Last active December 15, 2015 07:09
Show Gist options
  • Save zroger/5221598 to your computer and use it in GitHub Desktop.
Save zroger/5221598 to your computer and use it in GitHub Desktop.
Gist for use on Phase2 blog.
<?php
/**
* @file example.faker.inc
*/
/**
* Implements hook_faker_node_generate().
*/
function example_faker_node_generate($node, $faker) {
if ($node->type == 'bio') {
// For our bio nodes, use a name as the title.
$node->title = $faker->name;
// Generate an opening paragraph, followed by a 2-4 sections comprised of
// a heading followed by 1-3 paragraphs, each with 5-10 sentences.
$body = '<p>' . $faker->paragraph(3,5) .'</p>';
for ($i = 0; $i < rand(2,4); $i++) {
$body .= '<h3>' . $faker->sentence . '</h3>';
for ($j = 0; $j < rand(1,3); $j++) {
$body .= '<p>' . $faker->paragraph(rand(5,10)) . '</p>';
}
}
$node->body['und'][0]['value'] = $body;
$node->body['und'][0]['format'] = 'full_html';
// A text field that should contain an email address.
$node->field_email['und'][0]['value'] = $faker->email;
// A text field that should contain a phone number.
$node->field_phone['und'][0]['value'] = $faker->phoneNumber;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment