|
@@ -382,24 +382,205 @@ function tripal_entity_load($id, $reset = FALSE) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Implements hook_form_alter().
|
|
|
*
|
|
|
- * @param unknown $form
|
|
|
- * @param unknown $form_state
|
|
|
+ * 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_entities_form_alter(&$form, &$form_state, $form_id) {
|
|
|
-
|
|
|
- switch ($form_id) {
|
|
|
- case 'field_ui_field_edit_form':
|
|
|
- // 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_entities_get_db_names_for_published_vocabularies ();
|
|
|
- if (in_array($form['#instance']['entity_type'], $dbs)) {
|
|
|
- $form['field']['cardinality']['#access'] = FALSE;
|
|
|
- $form['instance']['required']['#access'] = FALSE;
|
|
|
- }
|
|
|
- break;
|
|
|
+function tripal_entities_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_entities_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_entities_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.', '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['tripal_entity_layout'] = array(
|
|
|
+ '#type' => 'fieldset',
|
|
|
+ '#title' => 'Panels',
|
|
|
+ '#collapsible' => TRUE,
|
|
|
+ '#collapsed' => TRUE,
|
|
|
+ '#group' => 'overview_vert_tabs'
|
|
|
+ );
|
|
|
+ $form['tripal_entity_layout']['panel_name'] = array(
|
|
|
+ '#type' => 'textfield',
|
|
|
+ '#title' => 'Add a new Panel',
|
|
|
+ '#description' => t('You may add as many panels to your page layout as
|
|
|
+ desired. Panels can be used to organize fields into categories....')
|
|
|
+ );
|
|
|
+
|
|
|
+ // Make sure our default panels are in the database.
|
|
|
+ _tripal_entities_check_default_field_panels();
|
|
|
+
|
|
|
+ // 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_entities_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_entities_field_ui_validate';
|
|
|
+ $submit = $form['#submit'];
|
|
|
+ $form['#submit'] = array('tripal_entities_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_entities_check_default_field_panels() {
|
|
|
+ // 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_hidden')
|
|
|
+ ->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_hidden',
|
|
|
+ 'label' => 'Hidden',
|
|
|
+ '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_entities_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_entities_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_entities_field_ui_submit($form, &$form_state) {
|
|
|
+
|
|
|
+}
|