123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865 |
- <?php
- function tripal_fields_layout_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
-
-
-
- $dbs = tripal_fields_layout_get_db_names_for_published_vocabularies();
- if (in_array($form['#instance']['entity_type'], $dbs)) {
- $form['field']['cardinality']['#access'] = FALSE;
- $form['instance']['required']['#access'] = FALSE;
- }
-
- }
- function tripal_fields_layout_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
- drupal_add_css(drupal_get_path('module','tripal_fields_layout') . '/theme/css/tripal_fields_layout_panels.css');
- $entity_type = $form['#entity_type'];
- $bundle_name = $form['#bundle'];
-
- $bundle = db_select('tripal_bundle', 'tb')
- ->fields('tb')
- ->condition('name', $bundle_name)
- ->execute()
- ->fetchObject();
- if (module_exists('ds')) {
- drupal_set_message('Tripal is not compatible with the Display Suite (ds)
- module. If you would like to use Tripal-style panels for the layout
- of your pages please disable the Display Suite module. If you
- prefer to use the Display Suite module then disable the Tripal
- Fields Layout (tripal_fields_layout) module.', 'warning');
- }
-
- $form['overview_vert_tabs'] = array(
- '#type' => 'vertical_tabs'
- );
- $form['modes']['#group'] = 'overview_vert_tabs';
- $form['modes']['#weight'] = 1000;
- $form['te_add_panels'] = array(
- '#type' => 'fieldset',
- '#title' => 'Add a Panel',
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#group' => 'overview_vert_tabs'
- );
-
- _tripal_fields_layout_check_default_field_panels($bundle);
-
- tripal_fields_layout_form_field_ui_display_overview_form_panel_add($form, $form_state);
-
- tripal_fields_layout_form_field_ui_display_overview_form_panel_arrange($form, $form_state, $bundle);
-
- tripal_fields_layout_form_field_ui_display_overview_form_panel_configure($form, $bundle);
-
- $form['fields']['#regions'] = array();
- $panels = db_select('tripal_panels', 'tp')
- ->fields('tp')
- ->condition('bundle_id', $bundle->id)
- ->orderBy('weight', 'ASC')
- ->orderBy('label', 'ASC')
- ->execute();
- $panel_options = array();
- while ($panel = $panels->fetchObject()) {
- $settings = unserialize($panel->settings);
- $form['fields']['#regions'][$panel->name] = array(
- 'title' => t($panel->label),
- 'message' => t($settings['message']),
- );
- $panel_options[$panel->name] = $panel->label;
- }
-
- $form['fields']['#header'] = array(
- t('Field'),
- t('Weight'),
- t('Parent'),
- t('Label'),
- array('data' => t('Format'), 'colspan' => 3),
- t('Region')
- );
-
-
- $fields = $form['fields'];
- $default_panel = 'te_base';
- foreach (element_children($fields) as $field_name) {
- $field_instance = field_info_instance($entity_type, $field_name, $bundle_name);
- $panel_id = db_select('tripal_panel_fields', 'tpf')
- ->fields('tpf', array('panel_id'))
- ->condition('field_id', $field_instance['id'])
- ->execute()
- ->fetchField();
- if ($panel_id) {
- $default_panel = db_select('tripal_panels', 'tp')
- ->fields('tp', array('name'))
- ->condition('panel_id', $panel_id)
- ->execute()
- ->fetchField();
- }
- $form['fields'][$field_name]['#region_callback'] = 'tripal_fields_layout_field_ui_row_region';
- $form['fields'][$field_name]['region'] = array(
- '#type' => 'select',
- '#options' => $panel_options,
- '#default_value' => $default_panel,
- '#attributes' => array(
- 'class' => array('te-field-region'),
- )
- );
- $form['fields'][$field_name]['#field_instance_id'] = array(
- '#type' => 'value',
- '#value' => $field_instance['id']
- );
- }
-
-
- $form['#validate'][] = 'tripal_fields_layout_field_ui_validate';
- $submit = $form['#submit'];
- $form['#submit'] = array('tripal_fields_layout_field_ui_submit');
- $form['#submit'] = array_merge($form['#submit'], $submit);
-
- }
- function tripal_fields_layout_form_field_ui_display_overview_form_panel_add (&$form, &$form_state) {
- $form_state['input']['panel_label'] = key_exists('panel_label', $form_state['input']) ? $form_state['values']['panel_label'] : NULL;
- $form['te_add_panels']['instructions'] = array(
- '#type' => 'item',
- '#markup' => t('You may add as many panels to your page layout as
- desired. Panels can be used to organize fields into categories....')
- );
- $form['te_add_panels']['panel_name'] = array(
- '#type' => 'hidden',
- '#title' => 'Panel Name',
- '#description' => t('The name is automatically generated for a label. it
- contains alphanumeric values and underscores and does not begin with
- a number.')
- );
- $form['te_add_panels']['panel_label'] = array(
- '#type' => 'textfield',
- '#title' => 'Panel Label',
- '#default_value' => '',
- '#description' => t('Please provide a human readable label for this
- panel. This is the name that will appear to site visitors.')
- );
- $form['te_add_panels']['add_button'] = array(
- '#type' => 'submit',
- '#value' => 'Add Panel',
- '#name' => 'add-panel-submit'
- );
- }
- function tripal_fields_layout_form_field_ui_display_overview_form_panel_arrange (&$form, &$form_state, $bundle) {
- $form['te_arrange_panels'] = array(
- '#type' => 'fieldset',
- '#title' => 'Arrange Panels',
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#group' => 'overview_vert_tabs'
- );
- $form['te_arrange_panels']['instructions'] = array(
- '#type' => 'item',
- '#markup' => t('Drag and drop the panel to change its order.')
- );
- $form['te_arrange_panels']['panel_items']['#tree'] = TRUE;
-
- $result = db_select('tripal_panels', 'tp')
- ->fields('tp', array('panel_id', 'name', 'label', 'weight'))
- ->condition('name', 'te_base', '<>')
- ->condition('name', 'te_disabled', '<>')
- ->condition('bundle_id', $bundle->id)
- ->orderby('weight', 'asc')
- ->execute();
- $has_panel = FALSE;
- foreach ($result as $item) {
- $form_state['input']['panel_items'][$item->panel_id]['newlabel'] = key_exists($item->panel_id, $form_state['input']) && $form_state['input'][$item->panel_id]['newlabel'] ? $form_state['values']['panel_items'][$item->panel_id]['newlabel'] : NULL;
- $form['te_arrange_panels']['panel_items'][$item->panel_id] = array(
- 'label' => array(
- '#markup' => check_plain($item->label),
- ),
- 'weight' => array(
- '#type' => 'weight',
- '#title' => t('Weight'),
- '#default_value' => $item->weight,
- '#delta' => 50,
- '#title_display' => 'invisible',
- ),
- 'newlabel' => array(
- '#type' => 'textfield',
- '#default_value' => '',
- '#size' => 10
- ),
- 'rename' => array(
- '#type' => 'submit',
- '#value' => 'Rename',
- '#name' => "arrange-panel-rename-$item->panel_id",
- ),
- 'remove' => array(
- '#type' => 'submit',
- '#value' => 'Remove',
- '#name' => "arrange-panel-remove-$item->panel_id",
- )
- );
- $has_panel = TRUE;
- }
- if ($has_panel) {
- $form['te_arrange_panels']['panel_items']['#theme_wrappers'] = array('tripal_fields_layout_form_arrange_panels');
- $form['te_arrange_panels']['save_button'] = array(
- '#type' => 'submit',
- '#value' => 'Save Panel Order',
- '#name' => 'order-panel-submit'
- );
- }
- else {
- $form['te_arrange_panels']['instructions']['#markup'] = t('You need to add some panel first.');
- }
- }
- function tripal_fields_layout_form_field_ui_display_overview_form_panel_configure (&$form, $bundle) {
- $form['te_configure_panels'] = array(
- '#type' => 'fieldset',
- '#title' => 'Configure Panels',
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#group' => 'overview_vert_tabs'
- );
- $form['te_configure_panels']['instructions'] = array(
- '#type' => 'item',
- '#markup' => t('Group fields into a horizontal or vertical table.')
- );
- $form['te_configure_panels']['panel_items']['#tree'] = TRUE;
-
- $panels = db_select('tripal_panels', 'tp')
- ->fields('tp', array('panel_id', 'name', 'label', 'weight', 'settings'))
- ->condition('name', 'te_disabled', '<>')
- ->condition('bundle_id', $bundle->id)
- ->orderby('weight', 'asc')
- ->execute();
-
- foreach ($panels as $panel) {
-
- }
- $has_panel = FALSE;
- foreach ($panels as $panel) {
- $panel_settings = unserialize($panel->settings);
- $table_layout = key_exists('table_layout', $panel_settings) ? $panel_settings['table_layout'] : array();
- $form['te_configure_panels']['panel_items'][$panel->panel_id] = array(
- '#type' => 'fieldset',
- '#title' => check_plain($panel->label),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- );
-
- $fields = db_select('tripal_panel_fields', 'tpf')
- ->fields('tpf', array('field_id'))
- ->condition('panel_id', $panel->panel_id)
- ->execute();
- $has_field = FALSE;
- foreach ($fields AS $field) {
- $field_obj = db_select('field_config_instance', 'tci')
- ->fields('tci', array('field_name','data'))
- ->condition('id', $field->field_id)
- ->execute()
- ->fetchObject();
- $field_arr = unserialize($field_obj->data);
- $fname = $field_obj->field_name;
- if($fname == 'featureprop') {
- continue;
- }
- $flable = $field_arr['label'];
- $form['te_configure_panels']['panel_items'][$panel->panel_id][$fname] = array(
- '#type' => 'item',
- '#title' => $flable,
- );
- $default_value = 0;
- if (in_array($fname, $table_layout)) {
- $default_value = 1;
- }
- $form['te_configure_panels']['panel_items'][$panel->panel_id][$fname]['table_group'] = array(
- '#type' => 'radios',
- '#options' => array(
- 0 => 'Default',
- 1 => 'Table',
- ),
- '#default_value' => $default_value,
- );
- $has_field = TRUE;
- }
- if (!$has_field) {
- $form['te_configure_panels']['panel_items'][$panel->panel_id]['no_field'] = array(
- '#markup' => 'No field in this panel.',
- );
- } else {
- $form['te_configure_panels']['panel_items'][$panel->panel_id]['#theme_wrappers'] = array('tripal_fields_layout_form_configure_panels');
- }
- $has_panel = TRUE;
- }
- if ($has_panel) {
- $form['te_configure_panels']['save_button'] = array(
- '#type' => 'submit',
- '#value' => 'Save Panel Configuration',
- '#name' => 'configure-panel-submit'
- );
- }
- else {
- $form['te_configure_panels']['instructions']['#markup'] = t('You need to add some panel first.');
- }
- }
- function _tripal_fields_layout_check_default_field_panels($bundle) {
-
-
- $te_base = db_select('tripal_panels', 'tp')
- ->fields('tp')
- ->condition('name', 'te_base')
- ->condition('bundle_id', $bundle->id)
- ->execute()
- ->fetchObject();
- if (!$te_base) {
- $settings = array(
- 'message' => 'Fields that should appear at the top of each page should be placed in the base panel. These fields are always present and help orient the user by at least indicating the necessary information to uniquely identiy the content.',
- );
- db_insert('tripal_panels')
- ->fields(array(
- 'bundle_id' => $bundle->id,
- 'name' => 'te_base',
- 'label' => 'Base Content',
- 'settings' => serialize($settings),
- 'weight' => -9999999
- ))
- ->execute();
- }
-
- $panel_id = db_select('tripal_panels', 'tp')
- ->fields('tp', array('panel_id'))
- ->condition('name', 'te_base')
- ->condition('bundle_id', $bundle->id)
- ->execute()
- ->fetchField();
- if(property_exists($bundle, 'type')) {
- $fields = db_select('field_config_instance', 'fci')
- ->fields('fci', array('id'))
- ->condition('entity_type', $bundle->type)
- ->condition('bundle', $bundle->name)
- ->execute();
- foreach($fields AS $field) {
- $penal_field_id = db_select('tripal_panel_fields', 'tpf')
- ->fields('tpf', array('panel_field_id'))
- ->condition('field_id', $field->id)
- ->execute()
- ->fetchField();
- if (!$penal_field_id) {
- db_insert('tripal_panel_fields')
- ->fields(array(
- 'panel_id' => $panel_id,
- 'field_id' => $field->id
- ))
- ->execute();
- }
- }
- }
-
- $te_base = db_select('tripal_panels', 'tp')
- ->fields('tp')
- ->condition('name', 'te_disabled')
- ->condition('bundle_id', $bundle->id)
- ->execute()
- ->fetchObject();
- if (!$te_base) {
- $settings = array(
- 'message' => 'Place field here to hide them from display.',
- );
- db_insert('tripal_panels')
- ->fields(array(
- 'bundle_id' => $bundle->id,
- 'name' => 'te_disabled',
- 'label' => 'Disabled',
- 'settings' => serialize($settings),
- 'weight' => 9999999
- ))
- ->execute();
- }
- }
- function tripal_fields_layout_field_ui_row_region($row) {
- $default_panel = 'te_base';
- $panel = '';
- $field_instance_id = $row['#field_instance_id']['#value'];
-
- $panel_id = db_select('tripal_panel_fields', 'tpf')
- ->fields('tpf', array('panel_id'))
- ->condition('field_id', $field_instance_id)
- ->execute()
- ->fetchField();
-
- if ($panel_id) {
- $panel = db_select('tripal_panels', 'tp')
- ->fields('tp', array('name'))
- ->condition('panel_id', $panel_id)
- ->execute()
- ->fetchField();
- }
-
- if (!$panel) {
- $panel = $default_panel;
- }
- return $panel;
- }
- function tripal_fields_layout_field_ui_validate($form, &$form_state) {
- }
- function tripal_fields_layout_field_ui_submit($form, &$form_state) {
- if ($form_state ['clicked_button'] ['#name'] == 'add-panel-submit') {
- tripal_fields_layout_action_add_panel($form, $form_state);
- }
-
- else if ($form_state['clicked_button'] ['#name'] == 'order-panel-submit') {
- tripal_fields_layout_action_order_panels($form, $form_state);
- }
-
- else if (preg_match('/^arrange-panel-rename-/', $form_state ['clicked_button'] ['#name'])) {
- tripal_fields_layout_action_rename_panel ($form, $form_state);
- }
-
- else if (preg_match('/^arrange-panel-remove-/', $form_state ['clicked_button'] ['#name'])) {
- tripal_fields_layout_action_remove_panel ($form_state);
- }
-
- else if ($form_state['clicked_button'] ['#name'] == 'configure-panel-submit') {
- tripal_fields_layout_action_configure_panels($form, $form_state);
- }
-
- else if ($form_state['clicked_button'] ['#name'] == 'op') {
- $bundle = $form_state['build_info']['args'][1];
- $fields = $form_state['values']['fields'];
- foreach($fields AS $field_name => $field_data){
-
- $field_instance_id = $form['fields'][$field_name]['#field_instance_id']['#value'];
-
- $region = $field_data['region'];
- $panel_id = db_select('tripal_panels', 'tp')
- ->fields('tp', array('panel_id'))
- ->condition('name', $region)
- ->condition('bundle_id', $bundle->id)
- ->execute()
- ->fetchField();
-
- $penal_field_id = db_select('tripal_panel_fields', 'tpf')
- ->fields('tpf', array('panel_field_id'))
- ->condition('field_id', $field_instance_id)
- ->execute()
- ->fetchField();
- if ($penal_field_id) {
- db_update('tripal_panel_fields')
- ->fields(array(
- 'panel_id' => $panel_id,
- ))
- ->condition('panel_field_id', $penal_field_id)
- ->execute();
- }
- else {
- db_insert('tripal_panel_fields')
- ->fields(array(
- 'panel_id' => $panel_id,
- 'field_id' => $field_instance_id
- ))
- ->execute();
- }
- }
- }
- }
- function tripal_fields_layout_action_add_panel (&$form, &$form_state) {
-
- $label = $form_state ['values'] ['panel_label'];
- if (! $label) {
- form_set_error('panel_label', t ("Please provide a label for the new panel."));
- }
-
-
- $name = strtolower(preg_replace ('/^\d|\s+/', '_', $label));
- $bundle = $form_state['build_info']['args'][1];
- $name_exists = db_select('tripal_panels', 'tp')
- ->fields('tp', array('panel_id'))
- ->condition('name', $name)
- ->condition('bundle_id', $bundle->id)
- ->execute()
- ->fetchField();
- if ($name_exists) {
- form_set_error('panel_label', t('The name is used by another panel. Please use a different label.'));
- }
- else {
- $form_state ['values'] ['panel_name'] = $name;
- $bundle_id = $form_state['build_info']['args'][1]->id;
- $name = $form_state['values']['panel_name'];
- $label = $form_state['values']['panel_label'];
- $settings = array(
- 'message' => 'Place field in this panel.',
- );
- db_insert('tripal_panels')
- ->fields(array(
- 'bundle_id' => $bundle_id,
- 'name' => $name,
- 'label' => $label,
- 'settings' => serialize($settings),
- 'weight' => 0
- ))
- ->execute();
- form_set_value($form['te_add_panels']['panel_label'], '', $form_state);
- }
- }
- function tripal_fields_layout_action_rename_panel (&$form, &$form_state) {
- $button = $form_state ['triggering_element'] ['#name'];
- $panel_id = str_replace ('arrange-panel-rename-', '', $button);
- $newlabel = $form_state['values']['panel_items'][$panel_id]['newlabel'];
- if (!trim($newlabel)) {
- form_set_error ('panel_label', t ("Please provide a label to rename a panel.") );
- }
- else {
- db_update('tripal_panels')
- ->fields(array(
- 'label' => $newlabel,
- 'name' => strtolower(preg_replace ('/^\d|\s+/', '_', $newlabel))
- ))
- ->condition('panel_id', $panel_id)
- ->execute();
- form_set_value($form['te_arrange_panels']['panel_items'][$panel_id]['newlabel'], '', $form_state);
- }
- }
- function tripal_fields_layout_action_remove_panel (&$form_state) {
- $button = $form_state ['triggering_element'] ['#name'];
- $panel_id = str_replace ('arrange-panel-remove-', '', $button);
- db_delete('tripal_panels')
- ->condition ('panel_id', $panel_id)
- ->execute();
- db_delete('tripal_panel_fields')
- ->condition ('panel_id', $panel_id)
- ->execute();
- }
- function tripal_fields_layout_action_order_panels (&$form, &$form_state) {
- $panels = $form_state['values']['panel_items'];
- foreach ($panels AS $id => $panel) {
- if (key_exists('weight', $panel)) {
- db_query('UPDATE {tripal_panels} SET weight = :weight WHERE panel_id = :id',
- array(
- ':weight' => $panel['weight'],
- ':id' => $id
- )
- );
- }
- }
- }
- function theme_tripal_fields_layout_form_arrange_panels ($variables) {
- $element = $variables['element'];
- $rows = array();
- foreach (element_children($element) as $id) {
-
- $element[$id]['weight']['#attributes']['class'] = array('tripal_panel-item-weight');
- $element[$id]['label']['#printed'] = FALSE;
- $element[$id]['weight']['#printed'] = FALSE;
- $element[$id]['newlabel']['#printed'] = FALSE;
- $element[$id]['rename']['#printed'] = FALSE;
- $element[$id]['remove']['#printed'] = FALSE;
- $rows[] = array(
- 'data' => array(
- drupal_render($element[$id]['label']),
- drupal_render($element[$id]['weight']),
- drupal_render($element[$id]['newlabel']),
- drupal_render($element[$id]['rename']),
- drupal_render($element[$id]['remove'])
- ),
-
- 'class' => array('draggable'),
- );
- }
-
- $header = array(t('Panel'), t('Weight'), array('data' => t('Rename'), 'colspan' => 2), t('Action'));
-
- $table_id = 'tripal_panel-arrange_panel_table';
-
- $output = '';
- if (count($rows) > 0) {
- $output = theme('table', array(
- 'header' => $header,
- 'rows' => $rows,
- 'attributes' => array('id' => $table_id),
- ));
- }
-
- drupal_add_tabledrag($table_id, 'order', 'sibling', 'tripal_panel-item-weight');
- return $output;
- }
- function tripal_fields_layout_action_configure_panels (&$form, &$form_state) {
- $panels = $form_state['values']['panel_items'];
- foreach ($panels AS $id => $panel) {
- $table_layout = array();
- foreach($panel AS $key => $value) {
- if (is_array($value) && key_exists('table_group', $value)) {
- if ($value['table_group'] == 1) {
- $table_layout[] = $key;
- }
- }
- }
- $panel_settings = db_select('tripal_panels', 'tp')
- ->fields('tp', array('settings'))
- ->condition('panel_id', $id)
- ->execute()
- ->fetchField();
- $new_settings = unserialize($panel_settings);
- $new_settings['table_layout'] = $table_layout;
- db_update('tripal_panels')
- ->fields(array(
- 'settings' => serialize($new_settings)
- ))
- ->condition('panel_id', $id)
- ->execute();
- }
- }
- function theme_tripal_fields_layout_form_configure_panels ($variables) {
- $element = $variables['element'];
- $rows = array();
- foreach (element_children($element) as $id) {
- $element[$id]['table_group']['#printed'] = FALSE;
- $rows[] = array(
- 'data' => array(
- $element[$id]['#title'],
- drupal_render($element[$id]['table_group']),
- ),
- );
- }
-
- $header = array(t('Field'), t('Layout'));
-
- $table_id = 'tripal_panel-configure_panel_table-' . strtolower(preg_replace('/\s+/', '_', $element['#title']));
- $table_class = 'tripal_panel-configure_panel_table';
-
- $table = '';
- if (count($rows) > 0) {
- $table = theme('table', array(
- 'header' => $header,
- 'rows' => $rows,
- 'attributes' => array('id' => $table_id, 'class' => array($table_class)),
- ));
- }
- $collapsible_item = array('element' => array());
- $collapsible_item['element']['#children'] = '';
- $collapsible_item['element']['#description'] =
- '<div id="tripal_fields_layout-panel_configure-fieldset-instruction">
- Select a group to organize fields into table(s) in this panel.
- <div>'
- . $table;
- $collapsible_item['element']['#title'] = $element['#title'];
-
- $collapsible_item['element']['#attributes']['class'] = array('tripal_fields_layout-panel_configure-fieldset');
- $output = theme('fieldset', $collapsible_item);
- return $output;
- }
- function tripal_fields_layout_theme($existing, $type, $theme, $path) {
- return array(
- 'tripal_fields_layout_form_arrange_panels' => array(
- 'render element' => 'element',
- ),
- 'tripal_fields_layout_form_configure_panels' => array(
- 'render element' => 'element',
- ),
- 'tripal_fields_layout_generic' => array(
- 'render element' => 'element',
- 'template' => 'tripal_fields_layout_generic',
- 'path' => "$path/theme/templates",
- ),
- );
- }
- function tripal_fields_layout_entity_view($entity, $type, $view_mode, $langcode) {
- switch ($type) {
- case 'TripalEntity':
-
- if ($view_mode == 'full') {
- $bundle = db_select('tripal_bundle', 'tb')
- ->fields('tb', array('id', 'name', 'label'))
- ->condition('name', $entity->bundle)
- ->execute()
- ->fetchObject();
- _tripal_fields_layout_check_default_field_panels($bundle);
- $results = db_select('tripal_panels', 'tp')
- ->fields('tp', array('panel_id','name', 'label', 'settings'))
- ->condition('bundle_id', $bundle->id)
- ->orderBy('tp.weight', 'ASC')
- ->execute();
- $panels = array();
- $fields = array();
- $disabled_panel_id = 0;
- foreach ($results AS $row) {
- if ($row->name == 'te_disabled') {
- $disabled_panel_id = $row->panel_id;
- }
- else {
- $panels[$row->panel_id] = $row;
- $fields[$row->panel_id] = array();
- }
- }
-
- foreach (element_children($entity->content) as $field_name) {
- $field_instance = field_info_instance ($type, $field_name, $entity->bundle);
-
- $default_panel_id = db_select('tripal_panels', 'tp')
- ->fields('tp', array('panel_id'))
- ->condition('bundle_id', $bundle->id)
- ->condition('name', 'te_base')
- ->execute()
- ->fetchField();
-
- $panel_id = db_select('tripal_panel_fields', 'tpf')
- ->fields('tpf', array('panel_id'))
- ->condition('field_id', $field_instance['id'])
- ->execute()
- ->fetchField();
- $panel_id = $panel_id ? $panel_id : $default_panel_id;
-
- if ($panel_id != $disabled_panel_id) {
- $fields[$panel_id][$field_name] = $entity->content[$field_name];
- }
-
- unset ($entity->content[$field_name]);
- }
- drupal_add_css(drupal_get_path('module','tripal_fields_layout') . '/theme/css/tripal_fields_layout.css');
- $entity->content['tripal_fields_layout_generic'] = array(
- '#theme' => 'tripal_fields_layout_generic',
- '#panels' => $panels,
- '#fields' => $fields,
- );
- }
- break;
- }
- }
|