123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- <?php
- require_once "includes/tripal_ds.inc";
- require_once "includes/tripal_ds.ds.inc";
- require_once "includes/tripal_ds.field_group.inc";
- require_once "includes/tripal_ds.field_formatter.inc";
- function tripal_ds_init() {
- drupal_add_css(drupal_get_path('module', 'tripal_ds') . '/theme/css/tripaldsfeature.css');
- drupal_add_js(drupal_get_path('module', 'tripal_ds') . '/theme/js/tripal_ds.js');
- $theme_dir = url(drupal_get_path('module', 'tripal_ds') . '/theme');
- drupal_add_js("var ds_theme_dir = '$theme_dir';", 'inline', 'header');
- }
- function tripal_ds_views_api() {
- return array(
- 'api' => 3,
- 'path' => drupal_get_path('module', 'tripal_ds') . '/includes/views',
- );
- }
- function tripal_ds_menu() {
- $items = array();
-
- $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' => 'drupal_get_form',
- 'access arguments' => array('administer tripal'),
- 'page arguments' => array('tripal_ds_update_layout_form', 4),
- 'type' => MENU_LOCAL_ACTION,
- );
- return $items;
- }
- function tripal_ds_bundle_postcreate($bundle) {
- $bundle_name = $bundle->name;
- $bundle_data_table = $bundle->data_table;
- $instances = field_info_instances('TripalEntity', $bundle_name);
- if($bundle_data_table == 'pub'){
- _ds_layout_pub_settings_info($bundle_name, $instances);
- }
- else {
- _ds_layout_settings_info($bundle_name, $instances);
- }
- }
- function tripal_ds_table_column_delete($bundle){
- $bundle_name = $bundle->name;
- db_delete('tripal_ds')
- ->condition('bundle', $bundle_name, '=')
- ->execute();
- }
- function tripal_ds_bundle_delete($bundle){
- tripal_ds_table_column_delete($bundle);
- }
- function tripal_ds_ds_field_settings_alter(&$field_settings, $form, $form_state){
-
- $tripal_entity_object = $form_state['build_info']['args']['1'];
-
- $bundle_id = $tripal_entity_object->name;
-
- $updated_field_groups = $form_state['field_group'];
-
- $fields = $form_state['values']['fields'];
-
- db_delete('tripal_ds')
- ->condition('bundle', $bundle_id, '=')
- ->execute();
-
- $tripal_pane_field_groups = array();
- $i = 0;
- foreach($updated_field_groups as $updated_field_group){
- if($updated_field_group->format_type == 'tripalpane'){
- $tripal_pane_field_groups += [ $i => $updated_field_group->group_name];
- $i++;
- }
- }
-
- foreach($updated_field_groups as $updated_field_group){
- foreach($tripal_pane_field_groups as $tripal_pane_field_group){
- if($updated_field_group->parent_name == $tripal_pane_field_group){
- if($fields[$tripal_pane_field_group]['region'] !== 'hidden'){
- tripal_ds_bundle_menu_item($bundle_id, $updated_field_group->label, $tripal_pane_field_group, 'tripalentity');
- }
- }
- }
- }
- }
- function tripal_ds_bundle_menu_item($bundle_name, $field_label, $field_name, $entity_type){
-
- $tripal_ds_rows = db_select('tripal_ds', 'ds')
- ->fields('ds', array('tripal_ds_field_name', 'tripal_ds_field_label'))
- ->condition('bundle', $bundle_name, '=')
- ->condition('tripal_ds_field_label', $field_label, '=')
- ->condition('tripal_ds_field_name', $field_name, '=')
- ->execute()->fetchAll();
- if(!empty($tripal_ds_rows)){
- foreach ($tripal_ds_rows as $tripal_ds_row){
- if(($field_label == $tripal_ds_row->tripal_ds_field_label) && ($field_name == $tripal_ds_row->tripal_ds_field_name) && ($bundle_name == $tripal_ds_rows->bundle)) {
-
- drupal_set_message("Could not update the bundle menu because that field already exists.", 'error');
- }
- }
- }
- else {
-
- $field_for_table = new stdClass();
- $field_for_table->tripal_ds_field_name = $field_name;
- $field_for_table->tripal_ds_field_label = $field_label;
- $field_for_table->entity_type = $entity_type;
- $field_for_table->bundle = $bundle_name;
- drupal_write_record('tripal_ds', $field_for_table);
- }
- }
- 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(
- 'left' => t('Left'),
- 'right' => t('Right'),
- ),
- 'css' => TRUE,
- ),
- );
- return $layouts;
- }
- function tripal_ds_update_layout_form($form, &$form_state, $bundle_name) {
- $form = array();
- $form['bundle_name'] = array(
- '#type' => 'value',
- '#value' => $bundle_name,
- );
- $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
- $bundle_label = $bundle->label;
- return confirm_form($form,
- t('Please confirm you would like to apply this layout: ' . $bundle_label),
- 'admin/structure/bio_data/manage/' . $bundle_name . '/display',
- t('This action cannot be undone.'),
- t('Yes, apply layout'),
- t('No, cancel')
- );
- }
- function tripal_ds_update_layout_form_submit($form, &$form_state) {
- $bundle_name = $form_state['build_info']['args'][0];
- $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
-
- $ds_identifier = 'TripalEntity|'.$bundle_name.'|default';
-
- $result = db_select('ds_layout_settings', 'ds')
- ->fields('ds')
- ->condition('id', $ds_identifier, '=')
- ->execute()
- ->fetchField();
-
- $result_fg = db_select('field_group', 'fg')
- ->fields('fg')
- ->condition('bundle', $bundle_name, '=')
- ->execute()
- ->fetchField();
-
- $result_tds = db_select('tripal_ds', 'tds')
- ->fields('tds')
- ->condition('bundle', $bundle_name, '=')
- ->execute();
-
- $result_fs = db_select('ds_field_settings', 'fs')
- ->fields('fs')
- ->condition('bundle', $bundle_name, '=')
- ->execute();
-
- if(!empty($result)) {
- db_delete('ds_layout_settings')
- ->condition('id', $ds_identifier, '=')
- ->execute();
- }
-
- if(!empty($result_fg)) {
- db_delete('field_group')
- ->condition('bundle', $bundle_name, '=')
- ->execute();
- }
-
- if(!empty($result_tds)) {
- db_delete('ds_field_settings')
- ->condition('bundle', $bundle_name, '=')
- ->execute();
- }
-
- if(!empty($result_fs)) {
- db_delete('tripal_ds')
- ->condition('bundle', $bundle_name, '=')
- ->execute();
- }
-
- $instances = field_info_instances('TripalEntity', $bundle_name);
- $bundle_data_table = $bundle->data_table;
- if($bundle_data_table == 'pub'){
- $success = _ds_layout_pub_settings_info($bundle_name, $instances);
- }
- else {
- $success = _ds_layout_settings_info($bundle_name, $instances);
- }
- if ($success) {
- drupal_set_message("Layout applied successfully and saved.");
- }
- else {
- drupal_set_message("Could not apply layout.", 'error');
- }
- drupal_goto("admin/structure/bio_data/manage/$bundle_name/display");
- }
|