Browse Source

initial commit with new ds module

Shawna Spoor 8 years ago
parent
commit
cc1f2510cc

+ 2 - 0
tripal/api/tripal.entities.api.inc

@@ -298,6 +298,8 @@ function tripal_create_bundle($args, &$error = '') {
         $instance = field_create_instance($details);
       }
     }
+  //build the display suite field settings
+  tripal_ds_content_type_fields($bundle_name);
   }
   catch (Exception $e) {
     $transaction->rollback();

+ 3 - 0
tripal_chado/includes/tripal_chado.fields.inc

@@ -564,6 +564,8 @@ function tripal_chado_bundle_create_instances($entity_type, $bundle) {
   return $info;
 
 }
+
+
 /**
  * Helper function for the hook_create_tripalfield_instance().
  *
@@ -648,6 +650,7 @@ function tripal_chado_bundle_create_instances_base(&$info, $entity_type, $bundle
       'display' => array(
         'default' => array(
           'label' => 'inline',
+          'region' =>'Left',
           'settings' => array(),
         ),
       ),

+ 261 - 0
tripal_ds/includes/tripal_ds.ds.inc

@@ -0,0 +1,261 @@
+<?php
+/**
+ * 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',
+      ),
+      '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;
+}
+
+
+function tripal_ds_content_type_fields($bundle_name){
+  $base_fields = array();
+  $all_fields = array();
+  $custom_fields = array();
+
+  $fields = db_select('field_config_instance', 'i')
+    ->fields('i', array('field_name'))
+    ->condition('bundle', $bundle_name)
+    ->execute()
+    ->fetchAll();
+
+  //break apart each field to grab the base table identifiers
+  foreach ($fields as $fields => $field) {
+    $field_parts = explode('__', $field->field_name, 2);
+
+    if(count($field_parts) > 1) {
+      $base_field = $field_parts[0];
+      $nonbase_field = $field_parts[1];
+    } else {
+      $base_field = $field_parts[0];
+    }
+    array_push($base_fields, $base_field);
+    array_push($all_fields, $field->field_name);
+
+  }
+  //create the left base table fields based on the previous foreach loop
+  if ($base_fields) {
+      $base_fields = array_unique($base_fields);
+      foreach($base_fields as $base_fields => $basefield){
+        $custom_field = tripal_ds_ds_custom_fields_info($basefield);
+        array_push($custom_fields, $custom_field);
+
+      }
+  }
+
+  $all_fields = array(
+    array($base_fields),
+    array($all_fields),
+    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;
+
+}
+
+/*
+ * Implements hook_ds_custom_fields_info().
+ */
+
+function tripal_ds_ds_custom_fields_info($field) {
+  $export = array();
+
+  $ds_field = new stdClass;
+  $ds_field->api_version = 1;
+  $ds_field->field = $field;
+  $ds_field->label = $field;
+  $ds_field->field_type = 6;
+  $ds_field->entities = array(
+    'TripalEntity' => 'TripalEntity',
+  );
+  $ds_field->ui_limit = '';
+  $ds_field->properties = array(
+    'block' => 'node|recent',
+    'block_render' => '2',
+  );
+  $export[$field] = $ds_field;
+
+  return $export;
+}

+ 10 - 0
tripal_ds/includes/tripal_ds.inc

@@ -0,0 +1,10 @@
+<?php
+
+/**
+ * Implements hook_ctools_plugin_api().
+ */
+function tripal_ds_ctools_plugin_api($module = NULL, $api = NULL){
+    if ($module == "ds" && $api == "ds") {
+        return array("version" => "1");
+    }
+}

+ 20 - 0
tripal_ds/theme/css/tripaldsfeature.css

@@ -0,0 +1,20 @@
+.ds-top {
+  width: 100%;
+  border-bottom: 1px solid grey;
+}
+
+.ds-left {
+  width: 25%;
+  float: left;
+  border-right: 1px solid grey;
+
+}
+
+.ds-right {
+  width: 73%;
+  float: right;
+}
+
+.ds-bottom {
+  width: 100%;
+}

+ 9 - 0
tripal_ds/theme/js/tripal_ds.js

@@ -0,0 +1,9 @@
+(function($) {
+
+  Drupal.behaviors.tripal_ds = {
+    attach: function (context, settings){
+
+    },
+  };
+
+})(jQuery);

+ 29 - 0
tripal_ds/theme/templates/tripal-ds-feature.tpl.php

@@ -0,0 +1,29 @@
+<?php
+
+/**
+ * This template file provides the layout for the Tripal DS modules.
+ *
+ */
+?>
+ <<?php print $layout_wrapper; print $layout_attributes; ?> class="<?php print $classes;?> clearfix">
+
+   <?php if (isset($title_suffix['contextual_links'])): ?>
+   <?php print render($title_suffix['contextual_links']); ?>
+   <?php endif; ?>
+   <<?php print $top_wrapper ?> class="ds-top<?php print $top_classes; ?>">
+     <?php print $top; ?>
+   </<?php print $top_wrapper ?>>
+
+   <<?php print $left_wrapper ?> class="ds-left<?php print $left_classes; ?>">
+     <?php print $left; ?>
+   </<?php print $left_wrapper ?>>
+
+   <<?php print $right_wrapper ?> class="ds-right<?php print $right_classes; ?>">
+     <?php print $right; ?>
+   </<?php print $right_wrapper ?>>
+
+   <<?php print $bottom_wrapper ?> class="ds-bottom<?php print $bottom_wrapper; ?>">
+     <?php print $bottom; ?>
+   </<?php print $bottom_wrapper ?>>
+
+ </<?php print $layout_wrapper ?>>

+ 14 - 0
tripal_ds/tripal_ds.info

@@ -0,0 +1,14 @@
+name = Tripal DS
+description = Provides display options for Tripal Entities through extending Display Suite.
+core = 7.x
+project = tripal
+package = Tripal
+version = 7.x-3.0-alpha1
+
+stylesheets[all][] = theme/css/tripaldsfeature.css
+
+dependencies[] = ds
+dependencies[] = field_group
+dependencies[] = field_group_table
+dependencies[] = tripal
+dependencies[] = ctools

+ 55 - 0
tripal_ds/tripal_ds.module

@@ -0,0 +1,55 @@
+<?php
+
+require_once "includes/tripal_ds.inc";
+require_once "includes/tripal_ds.ds.inc";
+
+function tripal_ds_init() {
+  drupal_add_css(drupal_get_path('module', 'tripal_ds') . '/theme/css/tripaldsfeature.css');
+}
+
+/**
+ * Implements hook_ds_layout_info() to define layouts from code in a module for
+ * display suite
+ */
+function tripal_ds_ds_layout_info() {
+  $path = drupal_get_path('module', 'tripal_ds');
+
+  $layouts = array(
+    'tripal_ds_feature' => array(
+      'label' => t('Tripal Feature Layout'),
+      'path' => $path . '/theme/templates',
+      'regions' => array(
+        'top' => t('Top'),
+        'left' => t('Left'),
+        'right' => t('Right'),
+        'bottom' => t('Bottom'),
+      ),
+      'css' => TRUE,
+    ),
+  );
+
+  return $layouts;
+}
+
+/*
+* General preprocess function to determine the HOOK for the subsequent preprocess functions
+* to target fields
+
+function tripal_ds_preprocess(&$vars, $hook) {
+  if (isset($vars['elements']['#entity_type'])) { 
+    $function = __FUNCTION__ . '_' . $vars['elements']['#entity_type'];
+    if (function_exists($function)) {
+      $function($vars, $hook);
+    }
+  }
+}*/
+/*
+ * Implements hook_bundle_create().
+ *
+ * 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_create($bundle, $args) {
+    _ds_layout_settings_info($bundle);
+} */
+