|
@@ -1,25 +1,247 @@
|
|
|
<?php
|
|
|
|
|
|
/**
|
|
|
+ *
|
|
|
* Implements hook_form_FORM_ID_alter().
|
|
|
+ *
|
|
|
+ * The field_ui_field_edit_form is used for customizing the settings of
|
|
|
+ * a field attached to an entity.
|
|
|
*/
|
|
|
-function tripal_fields_layout_form_field_ui_display_overview_form_alter(&$form, &$form_state) {
|
|
|
- $form['tripal_fields'] = array(
|
|
|
+function tripal_fields_layout_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
|
|
|
+ // For entity fields added by Tripal Entities we don't want the
|
|
|
+ // the end-user to change the cardinality and the required fields
|
|
|
+ // such that record can't be saved in Chado.
|
|
|
+ $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;
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO: don't the the maximum length be larger than the field size.
|
|
|
+}
|
|
|
+/**
|
|
|
+ * Implements hook_form_FORM_ID_alter().
|
|
|
+ *
|
|
|
+ * The field_ui_display_overview_form is used for formatting the display
|
|
|
+ * or layout of fields attached to an entity.
|
|
|
+ */
|
|
|
+function tripal_fields_layout_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
|
|
|
+
|
|
|
+ $entity_type = $form['#entity_type'];
|
|
|
+ $bundle_name = $form['#bundle'];
|
|
|
+
|
|
|
+ // Get the bundle record.
|
|
|
+ $bundle = db_select('tripal_bundle', 'tb')
|
|
|
+ ->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' => 'Biological Data Layout',
|
|
|
+ '#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['tripal_fields']['new_pane'] = array(
|
|
|
+ $form['te_add_panels']['panel_label'] = array(
|
|
|
'#type' => 'textfield',
|
|
|
- '#title' => 'Add a new pane',
|
|
|
- '#description' => 'Panes can be used to organize related fields. You may
|
|
|
- create as many panes as desired. Once a pane is created you can use
|
|
|
- the interface above to move fields into an appropriate pane. '
|
|
|
+ '#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'
|
|
|
);
|
|
|
- $form['tripal_fields']['new_pane_button'] = array(
|
|
|
- '#type' => 'button',
|
|
|
- '#name' => 'new_pane_button',
|
|
|
- '#value' => 'Add',
|
|
|
+
|
|
|
+ // 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) {
|
|
|
+
|
|
|
}
|