'help_post' => "text COMMENT 'Description and/or help text to display after this field.'",
],
'civicrm_price_field_value' => [
- 'label' => "varchar(255) NOT NULL COMMENT 'Price field option label'",
+ 'label' => "varchar(255) DEFAULT NULL COMMENT 'Price field option label'",
'description' => "text DEFAULT NULL COMMENT 'Price field option description.'",
'help_pre' => "text DEFAULT NULL COMMENT 'Price field option pre help text.'",
'help_post' => "text DEFAULT NULL COMMENT 'Price field option post field help.'",
'civicrm_price_field_value' => [
'label' => [
'type' => "Text",
- 'required' => "true",
],
'description' => [
'type' => "TextArea",
*
* Generated from xml/schema/CRM/Price/PriceFieldValue.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:28432a14b1b1523380eb41e8e481037d)
+ * (GenCodeChecksum:11a02f3576be10e8c2a0ea47a19e2dac)
*/
/**
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Name'),
'description' => ts('Price field option name'),
- 'required' => TRUE,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'where' => 'civicrm_price_field_value.name',
+ 'default' => 'NULL',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Label'),
'description' => ts('Price field option label'),
- 'required' => TRUE,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'where' => 'civicrm_price_field_value.label',
+ 'default' => 'NULL',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
}
}
+ /**
+ * Upgrade function.
+ *
+ * @param string $rev
+ */
+ public function upgrade_5_28_1($rev) {
+ $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
+ $this->addTask('Make label field non required on price field value', 'priceFieldValueLabelNonRequired');
+ }
+
+ /**
+ * Make the price field value label column non required
+ * @return bool
+ */
+ public static function priceFieldValueLabelNonRequired() {
+ $domain = new CRM_Core_DAO_Domain();
+ $domain->find(TRUE);
+ if ($domain->locales) {
+ $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
+ foreach ($locales as $locale) {
+ CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_price_field_value CHANGE `label_{$locale}` `label_{$locale}` varchar(255) DEFAULT NULL COMMENT 'Price field option label'", [], TRUE, NULL, FALSE, FALSE);
+ CRM_Core_DAO::executeQuery("UPDATE civicrm_price_field_value SET label_{$locale} = NULL WHERE label_{$locale} = 'null'", [], TRUE, NULL, FALSE, FALSE);
+ }
+ }
+ else {
+ CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_price_field_value CHANGE `label` `label` varchar(255) DEFAULT NULL COMMENT 'Price field option label'", [], TRUE, NULL, FALSE, FALSE);
+ CRM_Core_DAO::executeQuery("UPDATE civicrm_price_field_value SET label = NULL WHERE label = 'null'", [], TRUE, NULL, FALSE, FALSE);
+ }
+ return TRUE;
+ }
+
public static function createWpFilesMessage() {
if (!function_exists('civi_wp')) {
return '';
public function modifySpec(RequestSpec $spec) {
// Name will be auto-generated from label if not supplied
$spec->getFieldByName('name')->setRequired(FALSE);
+ // Ensure that label is required this matches v3 API but doesn't match DAO because form fields allow for NULLs
+ $spec->getFieldByName('label')->setRequired(TRUE);
}
/**
$this->assertEquals('visibility', $fields['visibility_id']['pseudoconstant']['optionGroupName']);
}
+ public function testEmptyStringLabel() {
+ // Put stuff here that should happen before all tests in this unit.
+ $priceSetParams = [
+ 'name' => 'default_goat_priceset',
+ 'title' => 'Goat accommodation',
+ 'is_active' => 1,
+ 'help_pre' => "Where does your goat sleep",
+ 'help_post' => "thank you for your time",
+ 'extends' => 2,
+ 'financial_type_id' => 1,
+ 'is_quick_config' => 1,
+ 'is_reserved' => 1,
+ ];
+
+ $price_set = $this->callAPISuccess('price_set', 'create', $priceSetParams);
+ $this->priceSetID = $price_set['id'];
+
+ $priceFieldParams = [
+ 'price_set_id' => $this->priceSetID,
+ 'name' => 'grassvariety',
+ 'label' => 'Grass Variety',
+ 'html_type' => 'Text',
+ 'is_enter_qty' => 1,
+ 'is_active' => 1,
+ ];
+ $priceField = $this->callAPISuccess('price_field', 'create', $priceFieldParams);
+ $this->priceFieldID = $priceField['id'];
+ $this->_params = [
+ 'price_field_id' => $this->priceFieldID,
+ 'name' => 'rye_grass',
+ 'label' => '',
+ 'amount' => 1,
+ 'financial_type_id' => 1,
+ ];
+ $priceFieldValue = CRM_Price_BAO_PriceFieldValue::create($this->_params);
+ $priceFieldValue->find(TRUE);
+ $this->assertEquals('', $priceFieldValue->label);
+ }
+
}
<title>Name</title>
<length>255</length>
<comment>Price field option name</comment>
- <required>true</required>
<html>
<type>Text</type>
</html>
<add>3.3</add>
+ <default>NULL</default>
</field>
<field>
<name>label</name>
<length>255</length>
<localizable>true</localizable>
<comment>Price field option label</comment>
- <required>true</required>
<html>
<type>Text</type>
</html>
<add>3.3</add>
+ <default>NULL</default>
</field>
<field>
<name>description</name>