You are here

bibcite_entity_test.install in Bibliography & Citation 8

Module installation hooks.

File

modules/bibcite_entity/tests/bibcite_entity_test/bibcite_entity_test.install
View source
<?php

/**
 * @file
 * Module installation hooks.
 */
use Drupal\bibcite_entity\Entity\Keyword;
use Drupal\bibcite_entity\Entity\Reference;
use Drupal\bibcite_entity\Entity\Contributor;

/**
 * Implements hook_install().
 *
 * Create test content.
 */
function bibcite_entity_test_install() {
  $keywords_data = [
    [
      'name' => 'Ancient artwork',
    ],
    [
      'name' => 'Renaissance literature',
    ],
  ];
  $keywords = [];
  foreach ($keywords_data as $data) {
    $keyword_entity = Keyword::create($data);
    $keyword_entity
      ->save();
    $keywords[] = $keyword_entity;
  }
  $contributors_data = [
    [
      'first_name' => 'John',
      'last_name' => 'Doe',
    ],
    [
      'first_name' => 'Mark',
      'last_name' => 'Twain',
    ],
  ];
  $contributors = [];
  foreach ($contributors_data as $data) {
    $contributor_entity = Contributor::create($data);
    $contributor_entity
      ->save();
    $contributors[] = $contributor_entity;
  }
  $reference_data = [
    [
      'title' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
      'type' => 'journal_article',
      'keyword' => reset($keywords),
      'author' => reset($contributors),
      'bibcite_year' => '1992',
      'bibcite_issue' => '1',
      'bibcite_volume' => '5',
      'bibcite_pages' => '1-13',
      'bibcite_publisher' => 'Journal',
    ],
    [
      'title' => 'Proin ut laoreet purus. Maecenas sed scelerisque leo.',
      'type' => 'journal_article',
      'keyword' => $keywords,
      'author' => $contributors,
      'bibcite_year' => '2001',
      'bibcite_issue' => '15',
      'bibcite_volume' => '2',
      'bibcite_pages' => '5-8',
      'bibcite_publisher' => 'Journal',
    ],
  ];
  $reference = [];
  foreach ($reference_data as $data) {
    $reference_entity = Reference::create($data);
    $reference_entity
      ->save();
    $reference[] = $reference_entity;
  }
}

Functions

Namesort descending Description
bibcite_entity_test_install Implements hook_install().