function api_test_install in Lightning API 8
Same name and namespace in other branches
- 8.2 modules/api_test/api_test.install \api_test_install()
Implements hook_install().
File
- modules/
api_test/ api_test.install, line 15
Code
function api_test_install() {
// Create a sample role to use for testing.
$permissions = [
"access content",
"access contextual links",
"access toolbar",
"bypass node access",
"create page content",
"create url aliases",
"delete page revisions",
"edit any page content",
"edit own page content",
"revert page revisions",
"use text format rich_text",
"view all revisions",
"view own unpublished content",
"view page revisions",
];
$role = Role::create([
'id' => 'test-role-page_creator',
'label' => 'Test Role Page Creator',
]);
$role
->save();
user_role_grant_permissions($role
->id(), $permissions);
// Create a sample user to use with the client.
$edit = [
'name' => 'api-test-user',
'mail' => 'api-test-user@example.com',
'pass' => 'admin',
];
$account = User::create($edit);
$account
->addRole('test-role-page_creator');
$account
->activate();
$account
->save();
$api_test_user_id = $account
->id();
// Create an example client to use for testing.
$data = [
'uuid' => 'api_test-oauth2-client',
'label' => 'API Test Client',
'secret' => 'oursecret',
'confidential' => 1,
'user_id' => $api_test_user_id,
'roles' => 'test-role-page_creator',
];
$client = Consumer::create($data);
$client
->save();
// Create some sample content for testing. One published and one unpublished
// basic page.
$data = [
'title' => 'Unpublished Page',
'type' => 'page',
'uuid' => 'api_test-unpublished-page-content',
'body' => '--TESTING--',
'status' => FALSE,
];
$node = Node::create($data);
$node
->save();
$data = [
'title' => 'Published Page',
'type' => 'page',
'uuid' => 'api_test-published-page-content',
'body' => '--TESTING--',
'status' => TRUE,
];
$node = Node::create($data);
$node
->save();
}