Răsfoiți Sursa

half of the publication ds and the confirm button on layout application

Shawna Spoor 8 ani în urmă
părinte
comite
1ec79262e8

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

@@ -189,6 +189,120 @@ function _ds_layout_settings_info($bundle_name, $instances) {
 }
 
 
+/**
+ *  Implements hook_ds_layout_settings_info().
+ */
+function _ds_layout_pub_settings_info($bundle_name, $instances) {
+  $region_right = array();
+  $region_left = array();
+  $properties= array();
+  $all_fields = array();
+  $instances_for_field_groups = array();
+  $disabled_instances = array();
+
+  try {
+    // Add Abstract, Citation, DB Cross Reference, Properties.
+    $all_fields['tpub__abstract']= 'right';
+    $all_fields['tpub__citation']= 'right';
+    $all_fields['sbo__database_cross_reference']= 'right';
+    $all_fields['publication_type']= 'right';
+    $all_fields['tpub__doi']= 'right';
+
+
+    // Iterate through the fields of this bundle.
+    foreach ($instances as $key => $instance) {
+      $instance_name = $instance['field_name'];
+
+      if( $instance_name == 'tpub__abstract' || $instance_name == 'tpub__citation' || $instance_name == 'sbo__database_cross_reference'){
+        array_push($instances_for_field_groups, $instance);
+        // Update the display settings so that the title is hidden.
+        $instance['display']['default']['label'] = 'hidden';
+        field_update_instance($instance);
+      }
+      elseif($instance_name == 'publication_type' || $instance_name == 'tpub__doi') {
+        array_push($properties, $instance);
+      }
+      else {
+        array_push($disabled_instances, $instance);
+      }
+
+    }
+    //Publication fields that are not going in the properties table.
+    foreach ($instances_for_field_groups as $key => $other_field) {
+      // Temporary field names.
+      $temporary_field = array();
+      $group_field_name = 'gp_'.$other_field['field_name'];
+      $fieldset_field_name = 'ft_'.$other_field['field_name'];
+
+      // Need to truncate the names because of database field size restrictions,
+      // updating fields here to ensure name consistency.
+      $group_field_name = substr($group_field_name, 0, 27);
+      $fieldset_field_name = substr($fieldset_field_name, 0, 27);
+
+      // Add randomm numbers to ensure the field name is unique within the 32
+      // character limit of the field.
+      $group_field_name = $group_field_name.rand(0, 99999);
+      $fieldset_field_name = $fieldset_field_name.rand(0, 99999);
+
+      // Build the field group.
+      _additional_fields_field_group_info($bundle_name, $other_field['label'], $group_field_name, $fieldset_field_name, $other_field['field_name']);
+
+      // Update arrays.
+      array_push($temporary_field, $group_field_name, $fieldset_field_name, $other_field['field_name']);
+      $region_right = array_merge($region_right, $temporary_field);
+      $all_fields += [ $group_field_name => 'right', $fieldset_field_name => 'right' ];
+    }
+
+    //Properties table fields.
+    if(!empty($properties)){
+      _publication_prop_field_group_info($bundle_name, $properties);
+      array_unshift($properties, 'group_prop_tripalpane', 'group_prop', 'group_prop_table');
+      $region_right = array_merge($region_right, $properties);
+      $all_fields+= [ 'group_prop_tripalpane' => 'right', 'group_prop' => 'right', 'group_prop_table' => 'right' ];
+    }
+
+    // Add blocks to $region_left and build the toc field that is placed within.
+    _ds_fields_info_write($bundle_name);
+    //$region_left += [ 'toc' ];
+    //$fields_with_regions += [ 'toc' => 'left' ];
+    // Build the ds layout.
+    $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(
+        'left' =>
+          $region_left,
+        'right' =>
+          $region_right,
+      ),
+      'fields' =>
+        $all_fields,
+      '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,
+    );
+    $record->settings = $settings;
+    drupal_write_record('ds_layout_settings', $record);
+  }
+  catch (Exception $e) {
+    watchdog_exception('tripal_ds', $e);
+    return FALSE;
+  }
+  return TRUE;
+}
+
 /**
  * Implements hook_ds_fields_info().
  */

+ 104 - 0
tripal_ds/includes/tripal_ds.field_group.inc

@@ -393,4 +393,108 @@ function _additional_fields_field_group_info($bundle_name, $field_label, $group_
   drupal_write_record('field_group', $field_group);
 
 }
+/**
+ * Implements hook_field_group_info().
+ */
+
+function _publication_prop_field_group_info($bundle_name, $fields){
+  //Tripal pane  to nest the fieldset within.
+  $field_group_tripalpane = new stdClass();
+  $field_group_tripalpane->disabled = FALSE; /* Edit this to true to make a default field_group disabled initially*/
+  $field_group_tripalpane->api_version = 1;
+  $field_group_tripalpane->identifier = 'group_prop_tripalpane|TripalEntity|'.$bundle_name.'|default';
+  $field_group_tripalpane->group_name = 'group_prop_tripalpane';
+  $field_group_tripalpane->entity_type = 'TripalEntity';
+  $field_group_tripalpane->bundle = $bundle_name;
+  $field_group_tripalpane->mode = 'default';
+  $field_group_tripalpane->parent_name = '';
+  $field_group_tripalpane->data = array(
+    'label' => 'Tripal Pane Properties',
+    'weight' => '2',
+    'children' => array(
+      0 => 'group_prop',
+    ),
+    'format_type' => 'tripalpane',
+    'format_settings' => array(
+      'label' => 'Tripal Pane Properties',
+      'instance_settings' => array(
+        'id' => 'tripal_ds-fieldset-group_prop_tripalpane',
+        'classes' => 'group-prop-tripalpane field-group-tripalpane',
+        'description' => '',
+      ),
+    ),
+  );
+  drupal_write_record('field_group', $field_group_tripalpane);
+
+  //write to the tripal_ds table to record the new tripal pane.
+  $field_for_table = new stdClass();
+  $field_for_table->tripal_ds_field_name = 'group_prop_tripalpane';
+  $field_for_table->tripal_ds_field_label = 'Properties';
+  $field_for_table->entity_type = 'TripalEntity';
+  $field_for_table->bundle = $bundle_name;
+
+  drupal_write_record('tripal_ds', $field_for_table);
+
 
+  //Fieldset field to nest the table within.
+  $field_group_fieldset = new stdClass();
+  $field_group_fieldset->disabled = FALSE; /* Edit this to true to make a default field_group disabled initially*/
+  $field_group_fieldset->api_version = 1;
+  $field_group_fieldset->identifier = 'group_prop|TripalEntity|'.$bundle_name.'|default';
+  $field_group_fieldset->group_name = 'group_prop';
+  $field_group_fieldset->entity_type = 'TripalEntity';
+  $field_group_fieldset->bundle = $bundle_name;
+  $field_group_fieldset->mode = 'default';
+  $field_group_fieldset->parent_name = 'group_prop_tripalpane';
+  $field_group_fieldset->data = array(
+    'label' => 'Properties',
+    'weight' => '3',
+    'children' => array(
+      0 => 'group_prop_table',
+    ),
+    'format_type' => 'fieldset',
+    'format_settings' => array(
+      'label' => 'Properties',
+      'instance_settings' => array(
+        'id' => '',
+        'classes' => 'group-prop field-group-fieldset',
+        'description' => '',
+      ),
+      'formatter' => 'collapsible',
+    ),
+  );
+
+  drupal_write_record('field_group', $field_group_fieldset);
+
+  //Table of fields.
+  $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_prop_table|TripalEntity|'.$bundle_name.'|default';
+  $field_group->group_name = 'group_prop_table';
+  $field_group->entity_type = 'TripalEntity';
+  $field_group->bundle = $bundle_name;
+  $field_group->mode = 'default';
+  $field_group->parent_name = 'group_prop';
+  $field_group->data = array(
+    'label' => 'Properties Table',
+    'weight' => '30',
+    'children' => $fields,
+    'format_type' => 'table',
+    'format_settings' => array(
+      'label' => 'Properties Table',
+      'instance_settings' => array(
+        'label_visibility' => '1',
+        'desc' => '',
+        'first_column' => '',
+        'second_column' => '',
+        'empty_label_behavior' => '1',
+        'table_row_striping' => 0,
+        'always_show_field_label' => 0,
+        'classes' => 'group-prop-table field-group-table',
+      ),
+    ),
+  );
+
+  drupal_write_record('field_group', $field_group);
+}

+ 30 - 5
tripal_ds/tripal_ds.module

@@ -34,9 +34,9 @@ function tripal_ds_menu() {
   $items['admin/structure/bio_data/manage/%/display/apply'] = array(
     'title' => 'Apply Default Tripal Layout (will reset current layout)',
     'description' => t('Apply the Tripal Display Suite settings to this content type.'),
-    'page callback' => 'tripal_ds_apply',
+    'page callback' => 'drupal_get_form',
     'access arguments' => array('administer tripal'),
-    'page arguments' => array(4),
+    'page arguments' => array('tripal_ds_update_layout_form', 4),
     'type' => MENU_LOCAL_ACTION,
   );
   return $items;
@@ -49,8 +49,16 @@ function tripal_ds_menu() {
  */
 function tripal_ds_bundle_postcreate($bundle) {
   $bundle_name = $bundle->name;
-  $instances = field_info_instances('TripalEntity', $bundle_name);
-  _ds_layout_settings_info($bundle_name, $instances);
+  $bundle_data_table = $bundle->data_table;
+  if($bundle_data_table == 'pub'){
+    $instances = field_info_instances('TripalEntity', $bundle_name);
+    _ds_layout_pub_settings_info($bundle_name, $instances);
+  }
+  else {
+    $instances = field_info_instances('TripalEntity', $bundle_name);
+    _ds_layout_settings_info($bundle_name, $instances);
+  }
+
 }
 
 function tripal_ds_table_column_delete($bundle){
@@ -85,11 +93,28 @@ function tripal_ds_ds_layout_info() {
   return $layouts;
 }
 
+function tripal_ds_update_layout_form($form, &$form_state, $bundle) {
+  $form = array();
+  $form['bundle_name'] = array(
+    '#type' => 'value',
+    '#value' => $bundle,
+  );
+
+  return confirm_form($form,
+    t('Please confirm you would like to update this layout: '.$bundle),
+    'admin/structure/bio_data/manage/'.$bundle.'/display',
+    t('This action cannot be undone.'),
+    t('Yes, apply layout'),
+    t('No, cancel')
+  );
+}
+
 /**
  *
  * @param $bundle_name
  */
-function tripal_ds_apply($bundle_name) {
+function tripal_ds_update_layout_form_submit($form, &$form_state) {
+  $bundle_name = $form_state['build_info']['args'][0];
   //Build the identifier to check against ds_layout_settings.
   $ds_identifier = 'TripalEntity|'.$bundle_name.'|default';