views_slideshow_examples.install in Views Slideshow Xtra 8.4
Installation functions for Views Slideshow Example module. views.views_slideshow.yml
File
modules/views_slideshow_examples/views_slideshow_examples.installView source
<?php
/**
* @file
* Installation functions for Views Slideshow Example module.
* views.views_slideshow.yml
*/
use Drupal\taxonomy\Entity\Term;
use Drupal\node\Entity\Node;
/**
* Implements hook_install().
*/
function views_slideshow_examples_install() {
// Create term for Basic Slideshow
$term_basic = Term::create([
'name' => 'Basic',
'vid' => 'views_slideshow',
])
->save();
$terms = taxonomy_term_load_multiple_by_name('Basic', 'views_slideshow');
$term = current($terms);
$term_basic_id = $term
->id();
// Create term for Overlay Slideshow
$term_overlay = Term::create([
'name' => 'Overlay',
'vid' => 'views_slideshow',
])
->save();
$terms = taxonomy_term_load_multiple_by_name('Overlay', 'views_slideshow');
$term = current($terms);
$term_overlay_id = $term
->id();
//$tid_array = taxonomy_term_load_multiple_by_name('Overlay', 'views_slideshow');
//$term_basic_id = reset($tid_array);
// Create term for Single Slide Slideshow
$term_single = Term::create([
'name' => 'Single Slide',
'vid' => 'views_slideshow',
])
->save();
$terms = taxonomy_term_load_multiple_by_name('Single Slide', 'views_slideshow');
$term = current($terms);
$term_single_id = $term
->id();
// Define entity type and bundle
$entity_type = "node";
$bundle = "views_slideshow_slide";
// Slide 1 - Basic Slideshow
// Create file object
$data = file_get_contents(drupal_get_path('module', 'views_slideshow_examples') . '/images/Four Mile.jpg');
$file = file_save_data($data, 'public://Four Mile.jpg', FILE_EXISTS_RENAME);
// $file->status = 1;
// Get definition of target entity type
$entity_def = \Drupal::entityManager()
->getDefinition($entity_type);
// Array for creation
$new_node = array(
// Title
'title' => 'Four Mile',
// Body
'body' => 'A picture of Four Mile nature preserve in Buena Vista, Colorado',
// Slideshow
'field_views_slideshow' => $term_basic_id,
// Order
'field_views_slideshow_order' => 1,
// Image
'field_image' => [
'target_id' => $file
->id(),
'alt' => 'A picture of Four Mile nature preserve in Buena Vista, Colorado',
],
// Use the entity definition to set the appropriate property for the bundle
$entity_def
->get('entity_keys')['bundle'] => $bundle,
);
$new_slide = \Drupal::entityManager()
->getStorage($entity_type)
->create($new_node);
$new_slide
->save();
// Slide 2 - Basic Slideshow
// Create file object
$data = file_get_contents(drupal_get_path('module', 'views_slideshow_examples') . '/images/Mount Princeton.jpg');
$file = file_save_data($data, 'public://Mount Princeton.jpg', FILE_EXISTS_RENAME);
// $file->status = 1;
// Get definition of target entity type
$entity_def = \Drupal::entityManager()
->getDefinition($entity_type);
// Array for creation
$new_node = array(
// Title
'title' => 'Mount Princeton',
// Body
'body' => 'A picture of Mount Princeton near Buena Vista, Colorado',
// Slideshow
'field_views_slideshow' => $term_basic_id,
// Order
'field_views_slideshow_order' => 2,
// Image
'field_image' => [
'target_id' => $file
->id(),
'alt' => 'A picture of Mount Princeton near Buena Vista, Colorado',
],
// Use the entity definition to set the appropriate property for the bundle
$entity_def
->get('entity_keys')['bundle'] => $bundle,
);
$new_slide = \Drupal::entityManager()
->getStorage($entity_type)
->create($new_node);
$new_slide
->save();
// Slide 3 - Basic Slideshow
// Create file object
$data = file_get_contents(drupal_get_path('module', 'views_slideshow_examples') . '/images/Mount Yale Treeline.jpg');
$file = file_save_data($data, 'public://Mount Yale Treeline.jpg', FILE_EXISTS_RENAME);
// $file->status = 1;
// Get definition of target entity type
$entity_def = \Drupal::entityManager()
->getDefinition($entity_type);
// Array for creation
$new_node = array(
// Title
'title' => 'View from Mount Yale Treeline',
// Body
'body' => 'View from Mount Yale treeline at 13,000 feet, near Buena Vista, Colorado',
// Slideshow
'field_views_slideshow' => $term_basic_id,
// Order
'field_views_slideshow_order' => 2,
// Image
'field_image' => [
'target_id' => $file
->id(),
'alt' => 'View from Mount Yale treeline at 13,000 feet, near Buena Vista, Colorado',
],
// Use the entity definition to set the appropriate property for the bundle
$entity_def
->get('entity_keys')['bundle'] => $bundle,
);
$new_slide = \Drupal::entityManager()
->getStorage($entity_type)
->create($new_node);
$new_slide
->save();
// Slide 1 - Overlay Slideshow
// Create file object
$data = file_get_contents(drupal_get_path('module', 'views_slideshow_examples') . '/images/Pete.jpg');
$file = file_save_data($data, 'public://Pete.jpg', FILE_EXISTS_RENAME);
// $file->status = 1;
// Get definition of target entity type
$entity_def = \Drupal::entityManager()
->getDefinition($entity_type);
// Array for creation
$new_node = array(
// Title
'title' => 'Pete the Dog',
// Body
'body' => 'A picture of Pete the Dog, a Norwegian Elkhound mix.',
// Slideshow
'field_views_slideshow' => $term_overlay_id,
// Order
'field_views_slideshow_order' => 1,
// Image
'field_image' => [
'target_id' => $file
->id(),
'alt' => 'A picture of Pete the dog, a Norwegian Elkhound mix.',
],
// Use the entity definition to set the appropriate property for the bundle
$entity_def
->get('entity_keys')['bundle'] => $bundle,
);
$new_slide = \Drupal::entityManager()
->getStorage($entity_type)
->create($new_node);
$new_slide
->save();
// Slide 2 - Overlay Slideshow
// Create file object
$data = file_get_contents(drupal_get_path('module', 'views_slideshow_examples') . '/images/Cricket.jpg');
$file = file_save_data($data, 'public://Cricket.jpg', FILE_EXISTS_RENAME);
// $file->status = 1;
// Get definition of target entity type
$entity_def = \Drupal::entityManager()
->getDefinition($entity_type);
// Array for creation
$new_node = array(
// Title
'title' => 'Cricket the Dog',
// Body
'body' => 'A picture of Cricket the dog, a Yorkie-Poo mix',
// Slideshow
'field_views_slideshow' => $term_overlay_id,
// Order
'field_views_slideshow_order' => 2,
// Image
'field_image' => [
'target_id' => $file
->id(),
'alt' => 'A picture of Cricket the dog, a Yorkie-Poo mix',
],
// Use the entity definition to set the appropriate property for the bundle
$entity_def
->get('entity_keys')['bundle'] => $bundle,
);
$new_slide = \Drupal::entityManager()
->getStorage($entity_type)
->create($new_node);
$new_slide
->save();
// Slide 3 - Overlay Slideshow
// Create file object
$data = file_get_contents(drupal_get_path('module', 'views_slideshow_examples') . '/images/Drummer.jpg');
$file = file_save_data($data, 'public://Drummer.jpg', FILE_EXISTS_RENAME);
// $file->status = 1;
// Get definition of target entity type
$entity_def = \Drupal::entityManager()
->getDefinition($entity_type);
// Array for creation
$new_node = array(
// Title
'title' => 'Drummer the Dog',
// Body
'body' => 'A picture of Drummer the dog, an Aussie mix',
// Slideshow
'field_views_slideshow' => $term_overlay_id,
// Order
'field_views_slideshow_order' => 2,
// Image
'field_image' => [
'target_id' => $file
->id(),
'alt' => 'A picture of Drummer the dog, an Aussie mix',
],
// Use the entity definition to set the appropriate property for the bundle
$entity_def
->get('entity_keys')['bundle'] => $bundle,
);
$new_slide = \Drupal::entityManager()
->getStorage($entity_type)
->create($new_node);
$new_slide
->save();
// Slide 1 - Single Slide Slideshow
// Create file object
$data = file_get_contents(drupal_get_path('module', 'views_slideshow_examples') . '/images/Cincinnati Flower Show.jpg');
$file = file_save_data($data, 'public://Cincinnati Flower Show.jpg', FILE_EXISTS_RENAME);
// $file->status = 1;
// Get definition of target entity type
$entity_def = \Drupal::entityManager()
->getDefinition($entity_type);
// Array for creation
$new_node = array(
// Title
'title' => 'Cincinnati Flower Show',
// Body
'body' => 'A picture of blooming flowers and trees at the Cincinnati Flower Shower',
// Slideshow
'field_views_slideshow' => $term_single_id,
// Order
'field_views_slideshow_order' => 1,
// Image
'field_image' => [
'target_id' => $file
->id(),
'alt' => 'A picture of blooming flowers and trees at the Cincinnati Flower Shower',
],
// Use the entity definition to set the appropriate property for the bundle
$entity_def
->get('entity_keys')['bundle'] => $bundle,
);
$new_slide = \Drupal::entityManager()
->getStorage($entity_type)
->create($new_node);
$new_slide
->save();
}
Functions
Name | Description |
---|---|
views_slideshow_examples_install | Implements hook_install(). |