+ /**
+ * Update a virtualized/deprecated setting.
+ *
+ * Temporary handling for phasing out contribution_invoice_settings.
+ *
+ * Until we have transitioned we need to handle setting & retrieving
+ * contribution_invoice_settings.
+ *
+ * Once removed from core we will add deprecation notices & then remove this.
+ *
+ * https://lab.civicrm.org/dev/core/issues/1558
+ *
+ * @param string $key
+ * @param array $value
+ * @return bool
+ * TRUE if $key is a virtualized setting. FALSE if it is a normal setting.
+ */
+ public function updateVirtual($key, $value) {
+ if ($key === 'contribution_invoice_settings') {
+ foreach (SettingsBag::getContributionInvoiceSettingKeys() as $possibleKeyName => $settingName) {
+ $keyValue = $value[$possibleKeyName] ?? '';
+ if ($possibleKeyName === 'invoicing' && is_array($keyValue)) {
+ $keyValue = $keyValue['invoicing'];
+ }
+ $this->set($settingName, $keyValue);
+ }
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ /**
+ * Determine the values of any virtual/computed settings.
+ *
+ * @return array
+ */
+ public function computeVirtual() {
+ $contributionSettings = [];
+ foreach (SettingsBag::getContributionInvoiceSettingKeys() as $keyName => $settingName) {
+ switch ($keyName) {
+ case 'invoicing':
+ $contributionSettings[$keyName] = $this->get($settingName) ? [$keyName => 1] : 0;
+ break;
+
+ default:
+ $contributionSettings[$keyName] = $this->get($settingName);
+ break;
+ }
+ }
+ return ['contribution_invoice_settings' => $contributionSettings];
+ }
+