You are here

brainstorm_portfolio.install in Brainstorm profile 8

File

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

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

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

  // Save portfolio terms.
  $portfolio_terms = array(
    'Branding identy',
    'Illustration',
    'Photography',
    'Web design',
  );
  foreach ($portfolio_terms as $term_name) {
    $values = array(
      'vid' => 'portfolio',
      'name' => $term_name,
    );
    $term = Term::create($values);
    $term
      ->save();
  }
  $portfolio_titles = array(
    'Miguel Sousa',
    'TATABI Studio Diz-Diz Popcorn',
    'For Brands',
    'Vyacheslav Dronov',
    'Laura Pol',
    'Johanna Zanon',
    'Davide Mancini',
    'Kim Haltermand',
    'Harun Kaymaz',
    'Siri Lackovic',
    'Studio01-JQ',
    'Backbone Branding',
    'Pokras Lampas',
    'Mustafa Çelik',
    'Savin Paris fashion apparel',
  );
  $body = "Newly established fashion apparel store based in Paris, France. " . "The company offers unique appael, and accessories to women and men who" . " value versatility, style, and comfort. Savin prides itself on " . "providing excellent customer service. There is always a friendly " . "face to greet you at the door and help you find whatever you need. " . "That's not even mentioning the great selection of fun and beautiful " . "clothing, shoes, jewelry, handbags and much more.";
  $count = 0;
  foreach ($portfolio_titles as $title) {
    $count = $count + 1;
    $path = _brainstorm_profile_clean_alias($title);
    $node = Node::create(array(
      'type' => 'portfolio',
      'title' => $title,
      'uid' => '1',
      'status' => 1,
      'path' => '/portfolio/' . $path,
    ));
    $file_count = 0;
    $files = array();
    $dir = drupal_get_path('profile', 'brainstorm_profile') . '/images/portfolio_' . $count . '/';
    @mkdir('public://brainstorm-placeholder/portfolio_' . $count);
    $iterator = new FilesystemIterator($dir);
    foreach ($iterator as $entry) {
      $file_count++;
      $output = file_get_contents($dir . $path . '-' . $file_count . '.jpg');
      $file = file_save_data($output, 'public://brainstorm-placeholder/portfolio_' . $count . '/' . $path . '-' . $file_count . '.jpg', FILE_EXISTS_REPLACE);
      $files[] = $file
        ->id();
    }
    $node->field_portfolio_image
      ->setValue($files);
    $node->body->value = $body;
    $node->field_date
      ->generateSampleItems(1);
    $node->field_tags_portfolio
      ->generateSampleItems(1);
    $node->field_time_work
      ->generateSampleItems(1);
    $node
      ->save();
  }
}

Functions

Namesort descending Description
brainstorm_portfolio_install Implements hook_install().