You are here

bricks_default_blocks.install in Bricks​ 8

Same filename and directory in other branches
  1. 2.x modules/bricks_default_blocks/bricks_default_blocks.install

File

modules/bricks_default_blocks/bricks_default_blocks.install
View source
<?php

/**
 * @file
 * {@inheritdoc}
 */

/**
 * Implements hook_install().
 */
function bricks_default_blocks_install() {
  $entity_manager = \Drupal::entityManager();
  $layout = $entity_manager
    ->getStorage('block_content')
    ->create([
    'type' => 'layout',
    'info' => 'Layout',
  ]);
  $layout
    ->save();
  $data = file_get_contents(drupal_get_path('theme', 'bartik') . '/screenshot.png');
  $file = file_save_data($data, 'public://bartik.png');
  $image = $entity_manager
    ->getStorage('block_content')
    ->create([
    'type' => 'image',
    'info' => 'Image',
    'field_image' => [
      'target_id' => $file
        ->id(),
    ],
  ]);
  $image
    ->save();
  $text = $entity_manager
    ->getStorage('block_content')
    ->create([
    'type' => 'basic',
    'info' => 'Text',
    'body' => [
      'value' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
      'format' => 'basic_html',
    ],
  ]);
  $text
    ->save();
  $wrapper = $entity_manager
    ->getStorage('block_content')
    ->create([
    'type' => 'wrapper',
    'info' => 'Wrapper',
  ]);
  $wrapper
    ->save();
  $page = $entity_manager
    ->getStorage('node')
    ->create([
    'type' => 'bricky_blocks',
    'title' => 'Bricks + Blocks = ♥',
    'field_body_blocks' => [
      [
        'depth' => 0,
        'target_id' => $layout
          ->id(),
        'options' => [
          'layout' => 'layout_twocol',
        ],
      ],
      [
        'depth' => 1,
        'target_id' => $text
          ->id(),
      ],
      [
        'depth' => 1,
        'target_id' => $image
          ->id(),
      ],
      [
        'depth' => 1,
        'target_id' => $text
          ->id(),
        'options' => [
          'css_class' => 'text-align-right',
        ],
      ],
      [
        'depth' => 1,
        'target_id' => $text
          ->id(),
      ],
    ],
  ]);
  $page
    ->save();
}

Functions

Namesort descending Description
bricks_default_blocks_install Implements hook_install().