fields('tb') ->condition('bundle', $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'); } // Add a vertical tab fieldset at the bottom of the $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' ); $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' => 'textfield', '#title' => 'Panel Name', '#description' => t('Please provide a computer readable name for this panel. The name should only contain alphanumeric values and underscores. It must not begin with a number.') ); $form['te_add_panels']['panel_label'] = array( '#type' => 'textfield', '#title' => 'Panel Label', '#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']['message'] = array( '#type' => 'textarea', '#title' => 'Empty Message', '#rows' => 2, '#description' => t('When the panel has no fields the following message will be shown in the form above.') ); $form['te_add_panels']['add_button'] = array( '#type' => 'submit', '#value' => 'Add Panel', '#name' => 'add-panel-submit' ); $form['te_layout_panels'] = array( '#type' => 'fieldset', '#title' => 'Order Panels', '#collapsible' => TRUE, '#collapsed' => TRUE, '#group' => 'overview_vert_tabs' ); $form['te_configure_panels'] = array( '#type' => 'fieldset', '#title' => 'Configure Panels', '#collapsible' => TRUE, '#collapsed' => TRUE, '#group' => 'overview_vert_tabs' ); // Make sure our default panels are in the database. _tripal_fields_layout_check_default_field_panels($bundle); // Now add each panel as a region. $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; } // Set the table headers to add a new 'region' column. $form['fields']['#header'] = array( t('Field'), t('Weight'), t('Parent'), t('Label'), array('data' => t('Format'), 'colspan' => 3), t('Region'), ); // Change the region callback for each field to place each field in the // proper "panel" region. Also, set the default region to be the base region. $fields = $form['fields']; foreach (element_children($fields) as $field_name) { $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' => 'te_base', '#attributes' => array( 'class' => array('te-field-region'), ) ); } // Add validate and submit handlers. Rearrange the submit callbacks // so ours is first. $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); } /** * A helper function for checking if the default panels are in the database. */ function _tripal_fields_layout_check_default_field_panels($bundle) { // Make sure we have records for our default regions: te_base and te_hidden. // First check if the base region is in the database. If not, add it. $te_base = db_select('tripal_panels', 'tp') ->fields('tp') ->condition('name', 'te_base') ->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(); } // Next check if the hidden region is in the database. If not, add it. $te_base = db_select('tripal_panels', 'tp') ->fields('tp') ->condition('name', 'te_disabled') ->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(); } } /** * Returns the region to which a row on the Field UI page belongs. * * @param $row * The current row that is being rendered in the Field UI page. */ function tripal_fields_layout_field_ui_row_region($row) { $default_panel = 'te_base'; $panel = ''; $field_name = $row['#parents'][1]; $field = field_info_field($field_name); // First get the panel if (!$panel) { $panel = $default_panel; } // See if there is a record in the tripal_panel_fields for this field. return $default_panel; } /** * Validates the field UI form to ensure proper panel assignments. * * @param $form * @param $form_state */ function tripal_fields_layout_field_ui_validate($form, &$form_state) { } /** * Responds to a submit from the field UI form for saving panel assignments. * * @param $form * @param $form_state */ function tripal_fields_layout_field_ui_submit($form, &$form_state) { }