It is a real drag having to import the content types yourself, and you need to know to enable Content Copy. It would be best to create these content types using hook_node_info

I will be spending some time creating patches for this module in a month or so, but if anyone wants to get started I'm sure a lot of users would benefit from this.

Comments

SeanBannister’s picture

subscribe

alan d.’s picture

Status: Active » Needs review

I'm working on multiple issues related to this module today, and will supply a full zip of the changes latter today or tomorrow.

To resolve the installation pain and to ensure the types are always present, I wrote an implementation of hook_node_info() and used hook_enable to create the fields:

<?php

/**
 * Implementation of hook_node_info().
 */
function pageflip_node_info() {
  return array(
    'pageflip_page' => array(
      'name' => t('PageFlip Page'),
      'module' => 'node',
      'description' => t("A page in a %chapter.", array('%chapter' => t('PageFlip Chapter'))),
      'title_label' => t('Title'),
      'has_title' => 1,
      'body_label' => '',
      'has_body' => 0,
      'min_word_count' => 0,
      'locked' => 1,
    ),
    'pageflip_chapter' => array(
      'name' => t('PageFlip Chapter'),
      'module' => 'node',
      'description' => t("A page in a %chapter.", array('%chapter' => t('PageFlip Chapter'))),
      'title_label' => t('Title'),
      'has_title' => 1,
      'body_label' => '',
      'has_body' => 0,
      'min_word_count' => 0,
      'locked' => 1,
    ),
    'pageflip_book' => array(
      'name' => t('PageFlip Book'),
      'module' => 'node',
      'description' => t('A comic book, magazine, or other type of book.'),
      'title_label' => t('Title'),
      'has_title' => 1,
      'body_label' => '',
      'has_body' => 0,
      'min_word_count' => 0,
      'locked' => 1,
    ),
  );
}

/**
 * Implementation of hook_enable().
 */
function pageflip_enable() {
  module_load_include('inc', 'pageflip', 'pageflip.import');
  module_load_include('inc', 'imagefield', 'imagefield_widget');
  module_load_include('inc', 'filefield', 'filefield_widget');
  module_load_include('inc', 'content', 'includes/content.crud');

  pageflip_import_page();
  pageflip_import_chapter();
  pageflip_import_book();
}

// ------------- file: pageflip.import.inc -----------------------


function pageflip_import_page() {
  _pageflip_import_image(t('Image (1080)'), 'pageflip_page', 'field_pageflip_page_image_high', 1, 'pageflip/pages');
  _pageflip_import_image(t('Image (720)'), 'pageflip_page', 'field_pageflip_page_image_low', 1, 'pageflip/pages');
  _pageflip_import_text(t('XML Override'), 'pageflip_page', 'field_pageflip_mz3_xml', 0, t('Optional: All MegaZine3 XML code for this page. Leave this empty and the XML will automatically be generated.'));

}
function pageflip_import_chapter() {
  _pageflip_import_reference(t('Pages'), 'pageflip_chapter', 'field_pageflip_pages', array('pageflip_page'));
}
function pageflip_import_book() {
  _pageflip_import_image(t('Icon'), 'pageflip_book', 'field_pageflip_icon', 0, 'pageflip/books');
  _pageflip_import_reference(t('Cover'), 'pageflip_book', 'field_pageflip_cover', array('pageflip_page'), 'nodereference_select', 1, 0);
  _pageflip_import_reference(t('Opening Pages'), 'pageflip_book', 'field_pageflip_opening_pages', array('pageflip_page'), 'nodereference_autocomplete', 0, 1, t('Pages inside the front cover before the first chapter, such as credits and title pages.'));
  _pageflip_import_reference(t('Chapters'), 'pageflip_book', 'field_pageflip_chapters', array('pageflip_chapter'), 'nodereference_autocomplete', 0, 1);
}

function _pageflip_import_reference($label, $type_name, $field_name, $referenceable_types = array(), $widget_type = 'nodereference_autocomplete', $required = 0, $multiple = 1, $description = '') {
  $types = array();
  foreach (node_get_types('names') as $type => $name) {
    if (in_array($type, $referenceable_types)) {
      $types[$type] = $type;
    }
    else {
      $types[$type] = 0;
    }
  }
  $field = array (
    'label' => $label,
    'field_name' => $field_name,
    'type_name' => $type_name,
    'type' => 'nodereference',
    'widget_type' => $widget_type,
    'autocomplete_match' => 'contains',
    'size' => '60',
    'description' => $description,
    'required' => $required,
    'multiple' => $multiple,
    'referenceable_types' => $types,
    'module' => 'nodereference',
    'widget_module' => 'nodereference',
    'columns' => array (
      'nid' => array (
        'type' => 'int',
        'unsigned' => true,
        'not null' => false,
        'index' => true,
      ),
    ),
    'display_settings' => array(
      'label' => array(
        'format' => 'hidden',
      ),
      'teaser' => array(
        'format' => 'hidden',
      ),
      'full' => array(
        'format' => 'hidden',
      ),
      4 => array(
        'format' => 'hidden',
      ),
    ),
  );
  $instances = content_field_instance_read(array('field_name' => $field['field_name'], 'type_name' => $field['type_name']));
  if (count($instances) < 1) {
    // Only add the field if it doesn't exist. Don't overwrite any changes.
    content_field_instance_create($field);
  }
}

function _pageflip_import_text($label, $type_name, $field_name, $required = 0, $description = '') {
  $field = array (
    'label' => $label,
    'field_name' => $field_name,
    'type_name' => $type_name,
    'type' => 'text',
    'widget_type' => 'text_textarea',
    'rows' => '8',
    'size' => 60,
    'description' => $description,
    'required' => $required,
    'multiple' => '0',
    'text_processing' => '0',
    'max_length' => '',
    'allowed_values' => '',
    'allowed_values_php' => '',
    'module' => 'text',
    'widget_module' => 'text',
    'columns' => array (
      'value' => array (
        'type' => 'text',
        'size' => 'big',
        'not null' => false,
        'sortable' => true,
        'views' => true,
      ),
    ),
    'display_settings' => array(
      'label' => array(
        'format' => 'hidden',
      ),
      'teaser' => array(
        'format' => 'hidden',
      ),
      'full' => array(
        'format' => 'hidden',
      ),
      4 => array(
        'format' => 'hidden',
      ),
    ),
  );
  $instances = content_field_instance_read(array('field_name' => $field['field_name'], 'type_name' => $field['type_name']));
  if (count($instances) < 1) {
    // Only add the field if it doesn't exist. Don't overwrite any changes.
    content_field_instance_create($field);
  }
}

function _pageflip_import_image($label, $type_name, $field_name, $required = 0, $path = '') {
  $field = array(
    'label' => $label,
    'type_name' => $type_name,
    'field_name' => $field_name,
    'file_path' => $path,
    'type' => 'filefield',
    'widget_type' => 'imagefield_widget',
    'weight' => 0,
    'file_extensions' => 'gif jpg jpeg png',
    'custom_alt' => 1,
    'custom_title' => 1,
    'description' => '',
    'required' => $required,
    'multiple' => '0',
    'list_field' => '0',
    'list_default' => 1,
    'description_field' => '0',
    'module' => 'filefield',
    'widget_module' => 'imagefield',
    'columns' => array(
      'fid' => array(
        'type' => 'int',
        'not null' => FALSE,
      ),
      'list' => array(
        'type' => 'int',
        'size' => 'tiny',
        'not null' => FALSE,
      ),
      'data' => array(
        'type' => 'text',
        'serialize' => TRUE,
      ),
    ),
    'display_settings' => array(
      'label' => array(
        'format' => 'hidden',
      ),
      'teaser' => array(
        'format' => 'hidden',
      ),
      'full' => array(
        'format' => 'hidden',
      ),
      4 => array(
        'format' => 'hidden',
      ),
    ),
  );
  $instances = content_field_instance_read(array('field_name' => $field['field_name'], 'type_name' => $field['type_name']));
  if (count($instances) < 1) {
    // Only add the field if it doesn't exist. Don't overwrite any changes.
    content_field_instance_create($field);
  }
}

?>
alan d.’s picture

adamdicarlo’s picture

Assigned: Unassigned » adamdicarlo
adamdicarlo’s picture

Status: Needs review » Fixed

This was fixed a while back.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.