Merge in 5.27
authorSeamus Lee <seamuslee001@gmail.com>
Tue, 16 Jun 2020 04:19:37 +0000 (14:19 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Tue, 16 Jun 2020 04:19:37 +0000 (14:19 +1000)
1  2 
CRM/Core/DAO/OptionValue.php
api/v3/utils.php

index cebd333f818fc89f58eda60b269d04c69b0efe96,c2418be597769541da34b196f800477ac193c243..7281eee278494b505a499575ca461467f05c5c54
@@@ -6,7 -6,7 +6,7 @@@
   *
   * Generated from xml/schema/CRM/Core/OptionValue.xml
   * DO NOT EDIT.  Generated by CRM_Core_CodeGen
-  * (GenCodeChecksum:83c97e8281f7ceb605ed4e462abf25ee)
+  * (GenCodeChecksum:5997192c77d86867e8d13c353dd02351)
   */
  
  /**
@@@ -160,13 -160,6 +160,13 @@@ class CRM_Core_DAO_OptionValue extends 
      parent::__construct();
    }
  
 +  /**
 +   * Returns localized title of this entity.
 +   */
 +  public static function getEntityTitle() {
 +    return ts('Option Values');
 +  }
 +
    /**
     * Returns foreign keys and entity references.
     *
            'title' => ts('Filter'),
            'description' => ts('Bitwise logic can be used to create subsets of options within an option_group for different uses.'),
            'where' => 'civicrm_option_value.filter',
-           'default' => 'NULL',
+           'default' => '0',
            'table_name' => 'civicrm_option_value',
            'entity' => 'OptionValue',
            'bao' => 'CRM_Core_BAO_OptionValue',
diff --combined api/v3/utils.php
index f3dc0988b36f0614636d20d7c042a44f69955039,ae9eaa0a18c0fe73e87f66ebcc80a7ee13080849..3aa58b6c8f6f0bbf4f038d0f3e9f327eceeb51c7
@@@ -990,7 -990,7 +990,7 @@@ function _civicrm_api3_dao_to_array($da
    while ($dao->fetch()) {
      $tmp = [];
      foreach ($fields as $key) {
 -      if (array_key_exists($key, $dao)) {
 +      if (property_exists($dao, $key)) {
          // not sure on that one
          if ($dao->$key !== NULL) {
            $tmp[$key] = $dao->$key;
@@@ -1047,8 -1047,8 +1047,8 @@@ function _civicrm_api3_object_to_array(
  
    $fields = _civicrm_api3_build_fields_array($dao, $uniqueFields);
    foreach ($fields as $key => $value) {
 -    if (array_key_exists($key, $dao)) {
 -      $values[$key] = $dao->$key;
 +    if (property_exists($dao, $key)) {
 +      $values[$key] = $dao->$key ?? NULL;
      }
    }
  }
@@@ -2342,6 -2342,16 +2342,16 @@@ function _civicrm_api3_api_match_pseudo
        // CiviMagic syntax for Nulling out the field - let it through.
        return;
      }
+     // Legacy support for custom fields: If matching failed by name, fallback to label
+     // @see https://lab.civicrm.org/dev/core/-/issues/1816
+     if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($fieldName)) {
+       $field = new CRM_Core_BAO_CustomField();
+       $field->id = $customFieldId;
+       $options = array_map("strtolower", $field->getOptions());
+       $newValue = array_search(strtolower($value), $options);
+     }
+   }
+   if ($newValue === FALSE) {
      throw new API_Exception("'$value' is not a valid option for field $fieldName", 2001, ['error_field' => $fieldName]);
    }
    $value = $newValue;