You are here

function isotope_example_install in Isotope (with Masonry and Packery) 7.2

Implements hook_install().

Create sample data.

File

isotope_example/isotope_example.install, line 12
Create sample data to be used in isotope example.

Code

function isotope_example_install() {
  $fields = array(
    'isotope_example_color' => array(
      'field_name' => 'isotope_example_color',
      'cardinality' => 1,
      'type' => 'text',
    ),
    'isotope_example_shape' => array(
      'field_name' => 'isotope_example_shape',
      'cardinality' => 1,
      'type' => 'text',
    ),
    'isotope_example_size' => array(
      'field_name' => 'isotope_example_size',
      'cardinality' => 1,
      'type' => 'text',
    ),
  );
  $instances = array(
    'isotope_example_color' => array(
      'field_name' => 'isotope_example_color',
      'label' => t('Color'),
      'type' => 'text',
      'widget' => array(
        'type' => 'text_textfield',
      ),
    ),
    'isotope_example_shape' => array(
      'field_name' => 'isotope_example_shape',
      'label' => t('Shape'),
      'type' => 'text',
      'widget' => array(
        'type' => 'text_textfield',
      ),
    ),
    'isotope_example_size' => array(
      'field_name' => 'isotope_example_size',
      'label' => t('Size'),
      'type' => 'text',
      'widget' => array(
        'type' => 'text_textfield',
      ),
    ),
  );

  // Create all the fields we are adding to our content type.
  foreach ($fields as $field) {
    field_create_field($field);
  }

  // Create all the instances for our fields.
  foreach ($instances as $instance) {
    $instance['entity_type'] = 'node';
    $instance['bundle'] = 'isotope_example';
    field_create_instance($instance);
  }
  $colors = array(
    'Blue',
    'Red',
    'Yellow',
  );
  $sizes = array(
    'Small',
    'Wide',
    'Big',
    'Tall',
  );
  $shapes = array(
    'Round',
    'Square',
  );

  // Create nodes of every size shape and color.
  $items = array();
  $i = 0;
  foreach ($sizes as $size) {
    foreach ($shapes as $shape) {
      foreach ($colors as $color) {
        $node = new stdClass();
        $node->type = 'isotope_example';
        $node->title = t('Sample !i', array(
          '!i' => $i,
        ));
        $node->language = LANGUAGE_NONE;
        node_object_prepare($node);
        $node->isotope_example_size[$node->language][]['value'] = $size;
        $node->isotope_example_shape[$node->language][]['value'] = $shape;
        $node->isotope_example_color[$node->language][]['value'] = $color;
        $node = node_submit($node);
        node_save($node);
        $i++;
      }
    }
  }
}