Skip to content

Commit

Permalink
Merge branch '6.x' into this-one-goes-to-11
Browse files Browse the repository at this point in the history
  • Loading branch information
KarinG authored Nov 20, 2024
2 parents b7367c5 + f212472 commit 6e1e72b
Show file tree
Hide file tree
Showing 15 changed files with 793 additions and 127 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install sendmail
# Temp thing
- name: Downgrade chrome
run: |
curl -L -o chrome.deb http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_127.0.6533.119-1_amd64.deb
sudo apt-get install libu2f-udev
sudo dpkg -i chrome.deb
google-chrome-stable --version
- name: Setup Drupal
run: |
COMPOSER_MEMORY_LIMIT=-1 composer create-project drupal/recommended-project:${{ matrix.drupal }} ~/drupal --no-interaction --no-install
Expand Down Expand Up @@ -144,7 +151,7 @@ jobs:
run: |
mkdir -p ~/drupal/web/sites/default/files/civicrm/ext
cd ~/drupal/web/sites/default/files/civicrm/ext
# Allow "unapproved" extensions
# Allow unapproved extensions
/home/runner/civicrm-cv/cv ev '\Civi::settings()->set("ext_repo_url", "https://civicrm.org/extdir/ver={ver}|cms={uf}|ready=");'
/home/runner/civicrm-cv/cv ev '\Civi::settings()->set("http_timeout", 60);'
# Apparently we have to install it, otherwise stripe gives a dependency error even with install=0. I think that's a bug, but let's just do it. This is a fake install anyway.
Expand All @@ -169,8 +176,11 @@ jobs:
git apply 457.diff
git apply 458.diff
- uses: nanasess/setup-chromedriver@master
with:
# temporary to match downgraded chrome
chromedriver-version: '127.0.6533.119'
- name: Run chromedriver
run: chromedriver &
run: chromedriver --port=9515 &
- name: Run php built-in server
run: php -S 127.0.0.1:8080 -t ~/drupal/web &
- name: Run PHPUnit
Expand All @@ -187,6 +197,7 @@ jobs:
DEV_EXTENSION_DIR: /home/runner/drupal/web/sites/default/files/civicrm/ext
DEV_EXTENSION_URL: http://127.0.0.1:8080/sites/default/files/civicrm/ext
- name: Helper to make unique name for upload
if: ${{ failure() || success() }}
run: |
# doing this on multiple lines to avoid quote-hell
cd ${{ runner.temp }}
Expand Down
20 changes: 12 additions & 8 deletions js/webform_civicrm_contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
searchingText: "Searching...",
enableHTML: true
};
wfCivi.existingInit(
field,
field.data('civicrm-contact'),
field.data('form-id'),
autocompleteUrl,
toHide,
tokenValues
);
}
else {
var tokenValues = false;
}

wfCivi.existingInit(
field,
field.data('civicrm-contact'),
field.data('form-id'),
autocompleteUrl,
toHide,
tokenValues
);

field.change(function () {
wfCivi.existingSelect(
Expand Down
1 change: 1 addition & 0 deletions src/ContactComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function wf_crm_contact_search($node, $element, $params, $contacts, $str = NULL)
'country' => ['address', 'country_id:label'],
'county' => ['address', 'county_id:label'],
'postal_code' => ['address', 'postal_code'],
'street_address' => ['address', 'street_address']
];
$joinedTables = [];
foreach ($fieldMappings as $field => $type) {
Expand Down
14 changes: 8 additions & 6 deletions src/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function getSets(array $components): array {
}
}
$conditional_sets = [
'CiviCase' => ['entity_type' => 'case', 'label' => t('Case'), 'max_instances' => 30],
'CiviCase' => ['entity_type' => 'case', 'label' => t('Case'), 'max_instances' => 50],
'CiviEvent' => ['entity_type' => 'participant', 'label' => t('Participant'), 'max_instances' => 9],
'CiviContribute' => ['entity_type' => 'contribution', 'label' => t('Contribution')],
'CiviMember' => ['entity_type' => 'membership', 'label' => t('Membership'), 'custom_fields' => 'combined'],
Expand Down Expand Up @@ -260,11 +260,13 @@ protected function wf_crm_get_fields($var = 'fields') {
'type' => 'select',
'default_value' => $this->utils->wf_crm_get_civi_setting('lcMessages', 'en_US'),
];
$default_communication_style = $this->utils->wf_crm_apivalues('OptionValue', 'get', [
'sequential' => 1,
'option_group_id' => "communication_style",
'is_default' => 1,
], 'value')[0] ?? NULL;
$default_communication_style = $this->utils->wf_civicrm_api4('OptionValue', 'get', [
'where' => [
['option_group_id.name', '=', 'communication_style'],
['is_default', '=', TRUE],
],
'select' => ['value'],
])->first()['value'] ?? NULL;
$fields['contact_communication_style_id'] = [
'name' => t('Communication Style'),
'type' => 'select',
Expand Down
1 change: 1 addition & 0 deletions src/Plugin/WebformElement/CivicrmContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ function wf_crm_results_display_options($contact_type) {
'state_province' => t("State/Province"),
'country' => t("Country"),
'postal_code' => t("Postal Code"),
'street_address' => t("Street Address"),
'phone' => t("Phone"),
];
return $options;
Expand Down
8 changes: 8 additions & 0 deletions src/Plugin/WebformHandler/CivicrmWebformHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ class CivicrmWebformHandler extends WebformHandlerBase {
*/
protected $civicrm;

/**
* The Token Manager service.
*
* @var \Drupal\webform\WebformTokenManager
*/
public $tokenManager;

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance->civicrm = $container->get('civicrm');
$instance->tokenManager = $container->get('webform.token_manager');

return $instance;
}
Expand Down
14 changes: 7 additions & 7 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,15 @@ public function wf_crm_get_states($param = NULL) {
* @return array
*/
function wf_crm_get_events($reg_options, $context) {
$ret = [];
static $ret = [];
if ($ret && $context !== 'config_form') {
return $ret;
}
$format = wf_crm_aval($reg_options, 'title_display', 'title');
$sort_field = wf_crm_aval($reg_options, 'event_sort_field', 'start_date');
$sort_order = ($context == 'config_form' && $sort_field === 'start_date') ? ' DESC' : '';
$params = [
'return' => ['id', 'title', 'start_date', 'end_date', 'event_type_id', 'max_participants'],
'is_template' => 0,
'is_active' => 1,
];
Expand Down Expand Up @@ -628,9 +632,7 @@ function wf_civicrm_api4($entity, $operation, $params, $index = NULL) {
if (!$entity) {
return [];
}
$params += [
'checkPermissions' => FALSE,
];
$params['checkPermissions'] = FALSE;
$result = civicrm_api4($entity, $operation, $params, $index);
return $result;
}
Expand All @@ -654,9 +656,7 @@ function wf_civicrm_api($entity, $operation, $params) {
return [];
}

$params += [
'check_permissions' => FALSE,
];
$params['check_permissions'] = FALSE;
if ($operation == 'transact') {
$utils = \Drupal::service('webform_civicrm.utils');
$result = $utils->wf_civicrm_api3_contribution_transact($params);
Expand Down
9 changes: 7 additions & 2 deletions src/WebformCivicrmBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -779,13 +779,18 @@ function addPaymentJs() {
* Copies a drupal file into the Civi file system
*
* @param int $id: drupal file id
* @param string $filename drupal filename
* @return int|null Civi file id
*/
public static function saveDrupalFileToCivi($id) {
public static function saveDrupalFileToCivi($id, $filename = NULL) {
$file = File::load($id);
if ($file) {
$config = \CRM_Core_Config::singleton();
$path = \Drupal::service('file_system')->copy($file->getFileUri(), $config->customFileUploadDir);
$copyTo = $config->customFileUploadDir;
if(isset($filename)) {
$copyTo .= '/' . $filename;
}
$path = \Drupal::service('file_system')->copy($file->getFileUri(), $copyTo);
if ($path) {
$result = \Drupal::service('webform_civicrm.utils')->wf_civicrm_api('file', 'create', [
'uri' => str_replace($config->customFileUploadDir, '', $path),
Expand Down
42 changes: 38 additions & 4 deletions src/WebformCivicrmPostProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class WebformCivicrmPostProcess extends WebformCivicrmBase implements WebformCiv
*/
private $database;

/**
* @var \Drupal\webform_civicrm\Plugin\WebformHandler
*/
private $handler;

/**
* @var \Drupal\webform\WebformSubmissionInterface
*/
Expand Down Expand Up @@ -85,10 +90,10 @@ function initialize(WebformSubmissionInterface $webform_submission) {

$handler_collection = $this->node->getHandlers('webform_civicrm');
$instance_ids = $handler_collection->getInstanceIds();
$handler = $handler_collection->get(reset($instance_ids));
$this->handler = $handler_collection->get(reset($instance_ids));
$this->database = \Drupal::database();

$this->settings = $handler->getConfiguration()['settings'];
$this->settings = $this->handler->getConfiguration()['settings'];
$this->data = $this->settings['data'];
$this->enabled = $this->utils->wf_crm_enabled_fields($this->node);
$this->all_fields = $this->utils->wf_crm_get_fields();
Expand Down Expand Up @@ -1681,6 +1686,7 @@ private function processGrants() {
* Calculate line-items for this webform submission
*/
private function tallyLineItems() {
$submittedFormValues = $this->form_state->getUserInput();
// Contribution
$fid = 'civicrm_1_contribution_1_contribution_total_amount';
if (isset($this->enabled[$fid]) || $this->getData($fid) > 0) {
Expand All @@ -1698,7 +1704,7 @@ private function tallyLineItems() {
if (isset($this->enabled[$fid])) {
foreach ($this->data['lineitem'][1]['contribution'] as $n => $lineitem) {
$fid = "civicrm_1_lineitem_{$n}_contribution_line_total";
if ($this->getData($fid) != 0) {
if (!isset($submittedFormValues[$fid]) || $this->getData($fid) != 0) {
$this->line_items[] = [
'qty' => 1,
'unit_price' => $lineitem['line_total'],
Expand Down Expand Up @@ -1733,6 +1739,7 @@ private function tallyLineItems() {
};

if ($price) {
$member_name = NULL;
if (!empty($this->data['contact'][$c]['contact'][$n])) {
$member_contact = $this->data['contact'][$c]['contact'][$n];
if (!empty($member_contact['first_name']) && !empty($member_contact['last_name'])) {
Expand Down Expand Up @@ -2122,6 +2129,7 @@ private function submitIPNPayment() {
}
}
}

// Ideally we would pass the correct id for the test processor through but that seems not to be the
// case so load it here.
if (!empty($params['is_test'])) {
Expand All @@ -2131,6 +2139,28 @@ private function submitIPNPayment() {
$i = $this->getContributionContactIndex();
$contact = $this->utils->wf_civicrm_api('contact', 'getsingle', ['id' => $this->ent['contact'][$i]['id']]);
$params += $contact;

// contact provides 'country' and 'country_id', but doPayment using PropertyBag expects 'billingCountry' with an iso_code
$countryName = $params['country'] ?? NULL;
$countryId = $params['country_id'] ?? NULL;
// providing country name throws deprecation warnings,
// which break the transaction so remove it
unset($params['country']);

// country id seems more reliable, so use that first
if ($countryId) {
$params['billingCountry'] = $this->utils->wf_civicrm_api4('Country', 'get', [
'select' => ['iso_code'],
'where' => [['id', '=', $countryId]]
])->first()['iso_code'] ?? '';
}
elseif ($countryName) {
$params['billingCountry'] = $this->utils->wf_civicrm_api4('Country', 'get', [
'select' => ['iso_code'],
'where' => [['name', '=', $countryName]]
])->first()['iso_code'] ?? '';
}

$params['contributionID'] = $params['id'] = $this->ent['contribution'][1]['id'];
if (!empty($this->ent['contribution_recur'][1]['id'])) {
$params['is_recur'] = TRUE;
Expand Down Expand Up @@ -2523,7 +2553,11 @@ private function fillDataFromSubmission() {
}
}
elseif ($dataType == 'File') {
if (empty($val[0]) || !($val = $this->saveDrupalFileToCivi($val[0]))) {
// Replace filename (with tokens) if set.
if (isset($component['#file_name']) && $component['#file_name']) {
$newFilename = $this->handler->tokenManager->replace($component['#file_name'], $this->submission);
}
if (empty($val[0]) || !($val = $this->saveDrupalFileToCivi($val[0], $newFilename))) {
// This field can't be emptied due to the nature of file uploads
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/WebformCivicrmPreProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ private function fillForm(&$elements, $submitted = []) {
if (!is_array($val) && !isset($element['#options'][$val])) {
$val = NULL;
}
if ((empty($val) || (is_array($val) && empty(array_filter($val)))) && !empty($this->form['#attributes']['data-form-defaults'])) {
if ((is_null($val) || (is_array($val) && empty(array_filter($val)))) && !empty($this->form['#attributes']['data-form-defaults'])) {
$formDefaults = Json::decode($this->form['#attributes']['data-form-defaults']);
$key = str_replace('_', '-', $element['#form_key']);
if (isset($formDefaults[$key])) {
Expand Down
Loading

0 comments on commit 6e1e72b

Please sign in to comment.