Browse Source

Fixed a bug where validation is required setting default values when editing a field settings

Stephen Ficklin 7 năm trước cách đây
mục cha
commit
48c4370467

+ 9 - 0
tripal_chado/includes/TripalFields/data__accession/data__accession.inc

@@ -120,6 +120,15 @@ class data__accession extends ChadoField {
    */
   public function validate($entity_type, $entity, $langcode, $items, &$errors) {
 
+    // If we don't have an entity then we don't want to validate.  The case
+    // where this could happen is when a user is editing the field settings
+    // and trying to set a default value. In that case there's no entity and
+    // we don't want to validate.  There will always be an entity for creation
+    // and update operations of a content type.
+    if (!$entity) {
+      return;
+    }
+
     $field_name = $this->field['field_name'];
     $settings = $this->field['settings'];
     $field_type = $this->field['type'];

+ 11 - 8
tripal_chado/includes/TripalFields/obi__organism/obi__organism.inc

@@ -42,6 +42,14 @@ class obi__organism extends ChadoField {
    */
   public function validate($entity_type, $entity, $langcode, $items, &$errors) {
 
+    // If we don't have an entity then we don't want to validate.  The case
+    // where this could happen is when a user is editing the field settings
+    // and trying to set a default value. In that case there's no entity and
+    // we don't want to validate.  There will always be an entity for creation
+    // and update operations of a content type.
+    if (!$entity) {
+      return;
+    }
     $settings = $this->field['settings'];
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
@@ -116,11 +124,10 @@ class obi__organism extends ChadoField {
   /**
    * @see TripalField::globalSettingsForm()
    */
-  public function settingsForm($has_data) {
-    $element = parent::globalSettingsForm($has_data);
-
-    $settings = $this->field['settings'];
+  public function instanceSettingsForm() {
+    $element = parent::instanceSettingsForm();
 
+    $settings = $this->instance['settings'];
     $element['instructions'] = array(
       '#type' => 'item',
       '#markup' => 'You may rewrite the way this field is presented to the end-user.
@@ -173,10 +180,6 @@ class obi__organism extends ChadoField {
       '#markup' => theme_table($table_vars),
     );
 
-    // Add in the semantic web fields.
-    $parent_elements = parent::settings_form($field, $instance, $has_data);
-    $element = array_merge($element, $parent_elements);
-
     return $element;
   }
 

+ 9 - 0
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference.inc

@@ -226,6 +226,15 @@ class sbo__database_cross_reference extends ChadoField {
    */
   public function validate($entity_type, $entity, $langcode, $items, &$errors) {
 
+    // If we don't have an entity then we don't want to validate.  The case
+    // where this could happen is when a user is editing the field settings
+    // and trying to set a default value. In that case there's no entity and
+    // we don't want to validate.  There will always be an entity for creation
+    // and update operations of a content type.
+    if (!$entity) {
+      return;
+    }
+
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
     $table_name = $this->instance['settings']['chado_table'];

+ 10 - 0
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship.inc

@@ -769,6 +769,16 @@ class sbo__relationship extends ChadoField {
    * @see TripalField::validate()
    */
   public function validate($entity_type, $entity, $langcode, $items, &$errors) {
+
+    // If we don't have an entity then we don't want to validate.  The case
+    // where this could happen is when a user is editing the field settings
+    // and trying to set a default value. In that case there's no entity and
+    // we don't want to validate.  There will always be an entity for creation
+    // and update operations of a content type.
+    if (!$entity) {
+      return;
+    }
+
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
     $field_table = $this->instance['settings']['chado_table'];

+ 1 - 0
tripal_chado/includes/TripalFields/schema__additional_type/schema__additional_type_widget.inc

@@ -88,6 +88,7 @@ class schema__additional_type_widget extends ChadoFieldWidget {
    * @see TripalFieldWidget::submit()
    */
   public function validate($element, $form, &$form_state, $langcode, $delta) {
+
     $settings = $this->field['settings'];
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];

+ 1 - 0
tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name_widget.inc

@@ -127,6 +127,7 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
    * @see TripalFieldWidget::validate()
    */
   public function validate($element, $form, &$form_state, $langcode, $delta) {
+
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
     $table_name = $this->instance['settings']['chado_table'];

+ 1 - 0
tripal_chado/includes/TripalFields/schema__publication/schema__publication_widget.inc

@@ -89,6 +89,7 @@ class schema__publication_widget extends ChadoFieldWidget {
    * @see TripalFieldWidget::submit()
    */
   public function validate($element, $form, &$form_state, $langcode, $delta) {
+
     // Get the FK column that links to the base table.
     $table_name = $this->instance['settings']['chado_table'];
     $base_table = $this->instance['settings']['base_table'];

+ 12 - 0
tripal_chado/includes/TripalFields/sio__annotation/sio__annotation.inc

@@ -50,8 +50,20 @@ class sio__annotation extends ChadoField {
   public static $no_ui = FALSE;
 
 
+  /**
+   * @see TripalField::validate()
+   */
   public function validate($entity_type, $entity, $langcode, $items, &$errors) {
 
+    // If we don't have an entity then we don't want to validate.  The case
+    // where this could happen is when a user is editing the field settings
+    // and trying to set a default value. In that case there's no entity and
+    // we don't want to validate.  There will always be an entity for creation
+    // and update operations of a content type.
+    if (!$entity) {
+      return;
+    }
+
     $field_name = $this->field['field_name'];
 
     foreach ($items as $delta => $item) {

+ 9 - 0
tripal_chado/includes/TripalFields/sio__vocabulary/sio__vocabulary.inc

@@ -40,6 +40,15 @@ class sio__vocabulary extends ChadoField {
    */
   public function validate($entity_type, $entity, $langcode, $items, &$errors) {
 
+    // If we don't have an entity then we don't want to validate.  The case
+    // where this could happen is when a user is editing the field settings
+    // and trying to set a default value. In that case there's no entity and
+    // we don't want to validate.  There will always be an entity for creation
+    // and update operations of a content type.
+    if (!$entity) {
+      return;
+    }
+
     $settings = $this->field['settings'];
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];