Browse Source

Fixed the manage fields customizations (e.g. don't allow changes to cardinality)

Stephen Ficklin 9 years ago
parent
commit
5ea5c96488

+ 0 - 1
tripal_entities/includes/TripalEntityUIController.inc

@@ -341,7 +341,6 @@ function tripal_entity_form_submit($form, &$form_state) {
  */
 function tripal_entity_delete_form($form, &$form_state, $entity) {
   $form_state['entity'] = $entity;
-dpm($entity);
   $form['#submit'][] = 'tripal_entity_delete_form_submit';
 
   $form = confirm_form($form,

+ 8 - 0
tripal_entities/includes/tripal_entities.field_storage.inc

@@ -12,6 +12,14 @@ function tripal_entities_field_storage_info() {
   );
 }
 
+/**
+ * Implements hook_field_storage_query().
+ *
+ * @param $query
+ */
+function tripal_entities_field_storage_query($query) {
+  // TODO: figure out what this function does.
+}
 /**
  * Implements hook_field_storage_write().
  */

+ 13 - 0
tripal_entities/includes/tripal_entities.fields.inc

@@ -268,6 +268,12 @@ function tripal_entities_field_is_empty($item, $field) {
 function tripal_entities_organism_select_widget_validate($element, &$form_state) {
   $field_name = $element['#field_name'];
 
+  // If the form ID is field_ui_field_edit_form, then the user is editing the
+  // field's values in the manage fields form of Drupal.  We don't want
+  // to validate it as if it were being used in a data entry form.
+  if ($form_state['build_info']['form_id'] =='field_ui_field_edit_form') {
+    return;
+  }
   $organism_id = tripal_entities_get_field_form_values($field_name, $form_state);
 
   if (count($organism_id) == 0) {
@@ -280,6 +286,13 @@ function tripal_entities_organism_select_widget_validate($element, &$form_state)
 function tripal_entities_primary_dbxref_widget_validate($element, &$form_state) {
   $field_name = $element['#field_name'];
 
+  // If the form ID is field_ui_field_edit_form, then the user is editing the
+  // field's values in the manage fields form of Drupal.  We don't want
+  // to validate it as if it were being used in a data entry form.
+  if ($form_state['build_info']['form_id'] =='field_ui_field_edit_form') {
+    return;
+  }
+
   // Get the field values.
   $db_id = tripal_entities_get_field_form_values($field_name, $form_state, "dbxref__db_id");
   $accession = tripal_entities_get_field_form_values($field_name, $form_state, "dbxref__accession");

+ 17 - 0
tripal_entities/tripal_entities.module

@@ -356,4 +356,21 @@ function tripal_entity_load($id, $reset = FALSE) {
   // Load the entity.
   $entity = entity_load($entity_type, array($id), array(), $reset);
   return reset($entity);
+}
+
+/**
+ * Implements hook_form_alter().
+ *
+ * @param unknown $form
+ * @param unknown $form_state
+ */
+function tripal_entities_form_alter(&$form, &$form_state, $form_id) {
+  switch ($form_id) {
+    case 'field_ui_field_edit_form':
+      if ($form['#instance']['entity_type'] == 'SO') {
+        $form['field']['cardinality']['#default_value'] = 1;
+        $form['field']['#access'] = FALSE;
+      }
+      break;
+  }
 }