Browse Source

Working on display suite integration

Stephen Ficklin 8 years ago
parent
commit
ce9abafd6d

+ 15 - 3
tripal/api/tripal.entities.api.inc

@@ -173,6 +173,15 @@ function tripal_load_bundle_entity($values) {
  */
 function hook_bundle_create(&$bundle, $storage_args) {
 
+}
+/**
+ * Allows a module to perform tasks after fields are added to a TripalBundle.
+ *
+ * @param $bundle
+ *   The newly created TripalBundle object.
+ */
+function hook_bundle_postcreate(&$bundle) {
+
 }
 /**
  * Creates a new Tripal Entity type (i.e. bundle).
@@ -247,7 +256,6 @@ function tripal_create_bundle($args, &$error = '') {
       $function($bundle, $storage_args);
     }
 
-
     // Clear the entity cache so that Drupal will read our
     // hook_entity_info() implementation.
     global $language;
@@ -298,8 +306,12 @@ function tripal_create_bundle($args, &$error = '') {
         $instance = field_create_instance($details);
       }
     }
-  //build the display suite field settings
-  tripal_ds_content_type_fields($bundle_name);
+
+    $modules = module_implements('bundle_postcreate');
+    foreach ($modules as $module) {
+      $function = $module . '_bundle_postcreate';
+      $function($bundle);
+    }
   }
   catch (Exception $e) {
     $transaction->rollback();

+ 47 - 183
tripal_ds/includes/tripal_ds.ds.inc

@@ -2,192 +2,59 @@
 /**
  * Implements hook_ds_layout_settings_info().
  */
- /*function tripal_ds_ds_layout_settings_info() {
-  $export = array(); 
-  //$bundle_name = $bundle;
-  $region_fields_right;
-  $fields_string;
-
-  //build the string for the regions and fields section from the $fields array
-  $total_fields = count($fields[1][0]);
-  $fields_string = implode(",", $fields[1][0]);
-
-  for ($i=0; $i < $total_fields; $i++) { 
-    //watchdog('debug', '<pre>_ds_layout_settings_info  $fields_string: '. print_r($fields[1][0][$i], TRUE) .'</pre>'); 
-    $region_fields_right .= $i ." => ". $fields[1][0][$i].", ";
-    $fields_string .= $fields[1][0][$i] ." => 'right', ";
-    
-  }
-
-  $ds_layout = new stdClass();
-  $ds_layout->api_version = 1;
-  $ds_layout->id = 'TripalEntity|bio_data_78|default';
-  $ds_layout->entity_type = 'TripalEntity';
-  $ds_layout->bundle = 'bio_data_78';
-  $ds_layout->view_mode = 'default';
-  $ds_layout->layout = 'tripal_ds_feature';
-  $ds_layout->settings = array(
-      'regions' => array(
-          'top' => array(),
-          'left' => array(),
-          'right' => array(
-            0 => 'project_contact', 
-            1 => 'rdfs__type', 
-            2 => 'sbo__database_cross_reference', 
-            3 => 'sbo__relationship', 
-            4 => 'schema__description', 
-            5 => 'schema__name', 
-            6 => 'schema__publication',
-            ),
-          'bottom' => array(),
-      ),
-      'fields' => array(
-        'project_contact' => 'right', 
-        'rdfs__type' => 'right', 
-        'sbo__database_cross_reference' => 'right',
-        'sbo__relationship' => 'right',
-        'schema__description' => 'right',
-        'schema__name' => 'right',
-        'schema__publication' => 'right',
-        ),
-      'classes' => array(),
-      'wrappers' => array(
-          'top' => 'div',
-          'left' => 'div',
-          'right' => 'div',
-          'bottom' => 'div',
-      ),
-      'layout_wrapper' => 'div',
-      'layout_attributes' => '',
-      'layout_attributes_merge' => 1,
-      'layout_link_attribute' => '',
-      'layout_link_custom' => '',
-      'layout_disable_css' => 0,
-  );
-  $export['TripalEntity|bio_data_78|default'] = $ds_layout;
-  
- if($export){
-    // Insert the layout.
-      db_insert('ds_layout_settings')
-        ->fields(array(
-          'id' => $ds_layout->id,
-          'entity_type' => 'TripalEntity',
-          'bundle' => $ds_layout->bundle,
-          'view_mode' => 'default',
-          'layout' => 'tripal_ds_feature',
-        ))
-        ->execute();
-    }
-    watchdog('debug', '<pre>_ds_layout_settings_info  $$ds_layout->settings: '. print_r($ds_layout->settings, TRUE) .'</pre>');
- if($ds_layout->settings ){
-    $record = new stdClass;
-    $record->id ='TripalEntity|bio_data_73|default';
-    $record->entity_type = 'TripalEntity';
-    $record->bundle = ;
-    $record->view_mode = 'default';
-    $record->settings = $ds_layout->settings;
-    drupal_write_record('ds_field_settings', $record);
-  }
-  return $export;
-}*/
-
-/**
- * Implements hook_ds_layout_settings_info().
- */
-function _ds_layout_settings_info($bundle_name, $fields) {
-  $export = array(); 
-  //$bundle_name = $bundle;
-  $region_fields_right;
-  $fields_string;
-
-  //build the string for the regions and fields section from the $fields array
-  $total_fields = count($fields[1][0]);
-  $fields_string = implode(",", $fields[1][0]);
-
-  for ($i=0; $i < $total_fields; $i++) { 
-    //watchdog('debug', '<pre>_ds_layout_settings_info  $fields_string: '. print_r($fields[1][0][$i], TRUE) .'</pre>'); 
-    $region_fields_right .= $i ." => ". $fields[1][0][$i].", ";
-    $fields_string .= $fields[1][0][$i] ." => 'right', ";
-    
-  }
-
-  $ds_layout = new stdClass();
-  $ds_layout->api_version = 1;
-  $ds_layout->id = 'TripalEntity|'.$bundle_name.'|default';
-  $ds_layout->entity_type = 'TripalEntity';
-  $ds_layout->bundle = $bundle_name;
-  $ds_layout->view_mode = 'default';
-  $ds_layout->layout = 'tripal_ds_feature';
-  $ds_layout->settings = array(
-      'regions' => array(
-          'top' => array(),
-          'left' => array(),
-          'right' => array(
-            0 => 'project_contact', 
-            1 => 'rdfs__type', 
-            2 => 'sbo__database_cross_reference', 
-            3 => 'sbo__relationship', 
-            4 => 'schema__description', 
-            5 => 'schema__name', 
-            6 => 'schema__publication',
-            ),
-          'bottom' => array(),
-      ),
-      'fields' => array(
-        'project_contact' => 'right', 
-        'rdfs__type' => 'right', 
-        'sbo__database_cross_reference' => 'right',
-        'sbo__relationship' => 'right',
-        'schema__description' => 'right',
-        'schema__name' => 'right',
-        'schema__publication' => 'right',
-        ),
-      'classes' => array(),
-      'wrappers' => array(
-          'top' => 'div',
-          'left' => 'div',
-          'right' => 'div',
-          'bottom' => 'div',
+function _ds_layout_settings_info($bundle_name, $instances) {
+  $export = array();
+  $record = new stdClass;
+  $record->id ='TripalEntity|' . $bundle_name . '|default';
+  $record->entity_type = 'TripalEntity';
+  $record->bundle = $bundle_name;
+  $record->view_mode = 'default';
+  $record->layout = 'tripal_ds_feature';
+  $settings = array(
+    'regions' => array(
+      'top' => array(),
+      'left' => array(),
+      'right' => array(
+        0 => 'project_contact',
+        1 => 'rdfs__type',
+        2 => 'sbo__database_cross_reference',
+        3 => 'sbo__relationship',
+        4 => 'schema__description',
+        5 => 'schema__name',
+        6 => 'schema__publication',
       ),
-      'layout_wrapper' => 'div',
-      'layout_attributes' => '',
-      'layout_attributes_merge' => 1,
-      'layout_link_attribute' => '',
-      'layout_link_custom' => '',
-      'layout_disable_css' => 0,
+      'bottom' => array(),
+    ),
+    'fields' => array(
+      'project_contact' => 'right',
+      'rdfs__type' => 'right',
+      'sbo__database_cross_reference' => 'right',
+      'sbo__relationship' => 'right',
+      'schema__description' => 'right',
+      'schema__name' => 'right',
+      'schema__publication' => 'right',
+    ),
+    'classes' => array(),
+    'wrappers' => array(
+      'top' => 'div',
+      'left' => 'div',
+      'right' => 'div',
+      'bottom' => 'div',
+    ),
+    'layout_wrapper' => 'div',
+    'layout_attributes' => '',
+    'layout_attributes_merge' => 1,
+    'layout_link_attribute' => '',
+    'layout_link_custom' => '',
+    'layout_disable_css' => 0,
   );
-  $export['TripalEntity|'.$bundle_name.'|default'] = $ds_layout;
-
-  module_load_include('inc', 'ds', 'ds.registry');
-  _ds_entity_type_update('TripalEntity', $export, 'update');
-
-  /*if($export){
-    // Insert the layout.
-      db_insert('ds_layout_settings')
-        ->fields(array(
-          'id' => $ds_layout->id,
-          'entity_type' => 'TripalEntity',
-          'bundle' => $ds_layout->bundle,
-          'view_mode' => 'default',
-          'layout' => 'tripal_ds_feature',
-        ))
-        ->execute();
-    }
-    watchdog('debug', '<pre>_ds_layout_settings_info  $$ds_layout->settings: '. print_r($ds_layout->settings, TRUE) .'</pre>');
- if($ds_layout->settings ){
-    $record = new stdClass;
-    $record->id ='TripalEntity|bio_data_73|default';
-    $record->entity_type = 'TripalEntity';
-    $record->bundle = ;
-    $record->view_mode = 'default';
-    $record->settings = $ds_layout->settings;
-    drupal_write_record('ds_field_settings', $record);
-  }*/
-  return $export;
+  $record->settings = $settings;
+  drupal_write_record('ds_layout_settings', $record);
 }
 
 
 function tripal_ds_content_type_fields($bundle_name){
+  dpm(debug_backtrace());
   $base_fields = array();
   $all_fields = array();
   $custom_fields = array();
@@ -228,9 +95,6 @@ function tripal_ds_content_type_fields($bundle_name){
     array($custom_fields),
   );
 
-  //tripal_ds_ds_layout_settings_info($bundle_name, $all_fields);
-  watchdog('debug', '<pre>tripal_ds_content_type_fields  $all_fields: '. print_r($all_fields, TRUE) .'</pre>');
-
   return $all_fields;
 
 }

+ 64 - 0
tripal_ds/publication.ds.inc

@@ -0,0 +1,64 @@
+<?php
+/**
+ * @file
+ * publication.ds.inc
+ */
+
+/**
+ * Implements hook_ds_layout_settings_info().
+ */
+function publication_ds_layout_settings_info() {
+  $export = array();
+
+  $ds_layout = new stdClass();
+  $ds_layout->api_version = 1;
+  $ds_layout->id = 'TripalEntity|bio_data_45|default';
+  $ds_layout->entity_type = 'TripalEntity';
+  $ds_layout->bundle = 'bio_data_45';
+  $ds_layout->view_mode = 'default';
+  $ds_layout->layout = 'ds_2col';
+  $ds_layout->settings = array(
+    'regions' => array(
+      'left' => array(
+        0 => 'tpub__abstract',
+      ),
+      'right' => array(
+        1 => 'group_citation',
+        2 => 'tpub__citation',
+        3 => 'group_properties',
+        4 => 'group_references',
+        5 => 'sio__references',
+        6 => 'group_property_table',
+        7 => 'tpub__publication_type',
+        8 => 'tpub__doi',
+        9 => 'sbo__database_cross_reference',
+      ),
+    ),
+    'fields' => array(
+      'tpub__abstract' => 'left',
+      'group_citation' => 'right',
+      'tpub__citation' => 'right',
+      'group_properties' => 'right',
+      'group_references' => 'right',
+      'sio__references' => 'right',
+      'group_property_table' => 'right',
+      'tpub__publication_type' => 'right',
+      'tpub__doi' => 'right',
+      'sbo__database_cross_reference' => 'right',
+    ),
+    'classes' => array(),
+    'wrappers' => array(
+      'left' => 'div',
+      'right' => 'div',
+    ),
+    'layout_wrapper' => 'div',
+    'layout_attributes' => '',
+    'layout_attributes_merge' => 1,
+    'layout_link_attribute' => '',
+    'layout_link_custom' => '',
+    'layout_disable_css' => 0,
+  );
+  $export['TripalEntity|bio_data_45|default'] = $ds_layout;
+
+  return $export;
+}

+ 17 - 0
tripal_ds/publication.features.inc

@@ -0,0 +1,17 @@
+<?php
+/**
+ * @file
+ * publication.features.inc
+ */
+
+/**
+ * Implements hook_ctools_plugin_api().
+ */
+function publication_ctools_plugin_api($module = NULL, $api = NULL) {
+  if ($module == "ds" && $api == "ds") {
+    return array("version" => "1");
+  }
+  if ($module == "field_group" && $api == "field_group") {
+    return array("version" => "1");
+  }
+}

+ 138 - 0
tripal_ds/publication.field_group.inc

@@ -0,0 +1,138 @@
+<?php
+/**
+ * @file
+ * publication.field_group.inc
+ */
+
+/**
+ * Implements hook_field_group_info().
+ */
+function publication_field_group_info() {
+  $field_groups = array();
+
+  $field_group = new stdClass();
+  $field_group->disabled = FALSE; /* Edit this to true to make a default field_group disabled initially */
+  $field_group->api_version = 1;
+  $field_group->identifier = 'group_citation|TripalEntity|bio_data_45|default';
+  $field_group->group_name = 'group_citation';
+  $field_group->entity_type = 'TripalEntity';
+  $field_group->bundle = 'bio_data_45';
+  $field_group->mode = 'default';
+  $field_group->parent_name = '';
+  $field_group->data = array(
+    'label' => 'Citation',
+    'weight' => '1',
+    'children' => array(
+      0 => 'tpub__citation',
+    ),
+    'format_type' => 'fieldset',
+    'format_settings' => array(
+      'label' => 'Citation',
+      'instance_settings' => array(
+        'id' => '',
+        'classes' => 'group-citation field-group-fieldset',
+        'description' => '',
+      ),
+      'formatter' => 'open',
+    ),
+  );
+  $field_groups[''] = $field_group;
+
+  $field_group = new stdClass();
+  $field_group->disabled = FALSE; /* Edit this to true to make a default field_group disabled initially */
+  $field_group->api_version = 1;
+  $field_group->identifier = 'group_properties|TripalEntity|bio_data_45|default';
+  $field_group->group_name = 'group_properties';
+  $field_group->entity_type = 'TripalEntity';
+  $field_group->bundle = 'bio_data_45';
+  $field_group->mode = 'default';
+  $field_group->parent_name = '';
+  $field_group->data = array(
+    'label' => 'Properties',
+    'weight' => '2',
+    'children' => array(
+      0 => 'group_property_table',
+    ),
+    'format_type' => 'fieldset',
+    'format_settings' => array(
+      'label' => 'Properties',
+      'instance_settings' => array(
+        'id' => '',
+        'classes' => 'group-properties field-group-fieldset',
+        'description' => '',
+      ),
+      'formatter' => 'open',
+    ),
+  );
+  $field_groups[''] = $field_group;
+
+  $field_group = new stdClass();
+  $field_group->disabled = FALSE; /* Edit this to true to make a default field_group disabled initially */
+  $field_group->api_version = 1;
+  $field_group->identifier = 'group_property_table|TripalEntity|bio_data_45|default';
+  $field_group->group_name = 'group_property_table';
+  $field_group->entity_type = 'TripalEntity';
+  $field_group->bundle = 'bio_data_45';
+  $field_group->mode = 'default';
+  $field_group->parent_name = 'group_properties';
+  $field_group->data = array(
+    'label' => '',
+    'weight' => '30',
+    'children' => array(
+      0 => 'sbo__database_cross_reference',
+      1 => 'tpub__doi',
+      2 => 'tpub__publication_type',
+    ),
+    'format_type' => 'table',
+    'format_settings' => array(
+      'label' => '',
+      'instance_settings' => array(
+        'label_visibility' => '3',
+        'desc' => '',
+        'first_column' => '',
+        'second_column' => '',
+        'empty_label_behavior' => '1',
+        'table_row_striping' => 0,
+        'always_show_field_label' => 0,
+        'classes' => 'group-property-table field-group-table',
+      ),
+    ),
+  );
+  $field_groups[''] = $field_group;
+
+  $field_group = new stdClass();
+  $field_group->disabled = FALSE; /* Edit this to true to make a default field_group disabled initially */
+  $field_group->api_version = 1;
+  $field_group->identifier = 'group_references|TripalEntity|bio_data_45|default';
+  $field_group->group_name = 'group_references';
+  $field_group->entity_type = 'TripalEntity';
+  $field_group->bundle = 'bio_data_45';
+  $field_group->mode = 'default';
+  $field_group->parent_name = '';
+  $field_group->data = array(
+    'label' => 'References',
+    'weight' => '3',
+    'children' => array(
+      0 => 'sio__references',
+    ),
+    'format_type' => 'fieldset',
+    'format_settings' => array(
+      'label' => 'References',
+      'instance_settings' => array(
+        'id' => '',
+        'classes' => 'group-references field-group-fieldset',
+        'description' => 'The following data housed by this site is referred  to by this publication.',
+      ),
+      'formatter' => 'open',
+    ),
+  );
+  $field_groups[''] = $field_group;
+
+  // Translatables
+  // Included for use with string extractors like potx.
+  t('Citation');
+  t('Properties');
+  t('References');
+
+  return $field_groups;
+}

+ 14 - 0
tripal_ds/publication.info

@@ -0,0 +1,14 @@
+name = Publication
+core = 7.x
+package = Features
+dependencies[] = ctools
+dependencies[] = ds
+dependencies[] = field_group
+features[ctools][] = ds:ds:1
+features[ctools][] = field_group:field_group:1
+features[ds_layout_settings][] = TripalEntity|bio_data_45|default
+features[features_api][] = api:2
+features[field_group][] = group_citation|TripalEntity|bio_data_45|default
+features[field_group][] = group_properties|TripalEntity|bio_data_45|default
+features[field_group][] = group_property_table|TripalEntity|bio_data_45|default
+features[field_group][] = group_references|TripalEntity|bio_data_45|default

+ 7 - 0
tripal_ds/publication.module

@@ -0,0 +1,7 @@
+<?php
+/**
+ * @file
+ * Code for the Publication feature.
+ */
+
+include_once 'publication.features.inc';

+ 12 - 7
tripal_ds/tripal_ds.module

@@ -36,20 +36,25 @@ function tripal_ds_ds_layout_info() {
 * to target fields
 
 function tripal_ds_preprocess(&$vars, $hook) {
-  if (isset($vars['elements']['#entity_type'])) { 
+  if (isset($vars['elements']['#entity_type'])) {
     $function = __FUNCTION__ . '_' . $vars['elements']['#entity_type'];
     if (function_exists($function)) {
       $function($vars, $hook);
     }
   }
-}*/
-/*
- * Implements hook_bundle_create().
+}
+*/
+/**
+ * Implements hook_bundle_postcreate().
  *
  * This is a Triapl defined hook and is called in the TripalBundle::create()
  * function to allow modules to perform tasks when a bundle is created.
+ */
+function tripal_ds_bundle_postcreate($bundle, $args) {
+  $bundle_name = $bundle->name;
+  $instances = field_info_instances('TripalEntity', $bundle_name);
+  _ds_layout_settings_info($bundle_name, $instances);
+}
+
 
-function tripal_ds_bundle_create($bundle, $args) {
-    _ds_layout_settings_info($bundle);
-} */