You are here

brainstorm_team.install in Brainstorm profile 8

File

module/features/brainstorm_team/brainstorm_team.install
View source
<?php

/**
 * @file
 */
use Drupal\taxonomy\Entity\Term;
use Drupal\node\Entity\Node;

/**
 * Implements hook_install().
 */
function brainstorm_team_install() {

  // Save profession terms.
  $profession_terms = array(
    'Back-End Developer',
    'Designer',
    'Founder',
    'Internet Marketing',
  );
  foreach ($profession_terms as $term_name) {
    $values = array(
      'vid' => 'profession',
      'name' => $term_name,
    );
    $term = Term::create($values);
    $term
      ->save();
  }
  $team_titles = array(
    'Kate Benke',
    'Ignatiy Alexandrov',
    'Mary Robbins',
    'Maxim Denisov',
  );
  $body = "Nam liber tempor cum soluta nobis eleifend option congue " . "nihilimperdiet doming id quod mazimplacerat facer possim assum. " . "Typinon habent claritatem insitam";
  $social = "<ul class=\"social-team\"> \n    <li ><a class=\"fa fa-facebook\" href=\"#\"></a></li>\n    <li><a  class=\"fa fa-instagram\" href=\"#\"></a></li>\n    <li><a class=\"fa fa-twitter\" href=\"#\"></a></li>\n    <li><a class=\"fa fa-github\" href=\"#\"></a></li>\n    </ul>";
  $count = 0;
  foreach ($team_titles as $title) {
    $count++;
    $path = _brainstorm_profile_clean_alias($title);
    $node = Node::create(array(
      'type' => 'team',
      'title' => $title,
      'uid' => '1',
      'status' => 1,
      'path' => '/' . $path,
    ));
    @mkdir('public://brainstorm-placeholder/');
    $file_name = 'team-' . $count . '.jpg';
    $output = file_get_contents(drupal_get_path('profile', 'brainstorm_profile') . '/images/' . $file_name);
    $file = file_save_data($output, 'public://brainstorm-placeholder/' . $file_name, FILE_EXISTS_REPLACE);
    $node->field_photo_team
      ->setValue($file
      ->id());
    $node->body->value = $body;
    $node->field_profession_team
      ->generateSampleItems();
    $node->field_social->value = $social;
    $node->field_social->format = 'full_html';
    $node
      ->save();
  }
}

Functions

Namesort descending Description
brainstorm_team_install Implements hook_install().