Skip to content

Commit

Permalink
attempt to address fuzionnz#2, fuzionnz#3, fuzionnz#4
Browse files Browse the repository at this point in the history
  • Loading branch information
herbdool committed Apr 3, 2023
1 parent 122b24b commit 453b0bd
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/EventSubscriber/WebformCivicrmMigrateSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ public function migrateWebformElementCiviCRMContact(array $element,array $d7_for
'none_prompt' => '',
'show_hidden_contact' => '',
'results_display' => ['display_name' => 'display_name'],
'no_autofill' => ['' => ''],
'hide_fields' => ['' => ''],
'no_autofill' => [],
'hide_fields' => [],
'default' => '',
'contact_sub_type' => '',
'allow_create' => 0,
Expand All @@ -327,10 +327,10 @@ public function migrateWebformElementCiviCRMContact(array $element,array $d7_for
'default_relationship' => '',
'allow_url_autofill' => TRUE,
'dupes_allowed' => FALSE,
'filter_relationship_types' => ['' => ''],
'filter_relationship_contact' => ['' => ''],
'group' => ['' => ''],
'tag' => ['' => ''],
'filter_relationship_types' => [],
'filter_relationship_contact' => [],
'group' => [],
'tag' => [],
'check_permissions' => 1,
'expose_list' => FALSE,
'empty_option' => '',
Expand Down Expand Up @@ -418,6 +418,9 @@ public function migrateWebformElement(array $element, array $d7_form_settings, i
$new_key = WebformCivicrmMigrateSubscriber::fixKey($key);
# Copy child to new key, recurse and delete broken key
# version.
if (!is_array($element[$key])) {
continue;
}
$child_element = $element[$key];
$child_element['#form_key'] = $new_key;
$element[$new_key] = $this->migrateWebformElement($child_element, $d7_form_settings, $nid);
Expand Down Expand Up @@ -482,6 +485,9 @@ public function migrateWebform(\Drupal\migrate\Row $row) {

public function migrateCiviCRMSettings($data, $default_settings) {
$settings = $default_settings;
if (empty($data['contact'])) {
return $settings;
}
$settings['number_of_contacts'] = count($data['contact']);

if (!empty($data['contact'])) {
Expand Down Expand Up @@ -534,6 +540,11 @@ public function addCiviCRMHandler(Webform $webform, int $nid) {
# Get the data from the source webform.
$webformData = WebformCivicrmMigrateSubscriber::getWebformCiviCRMData($nid);

// Skip if CiviCRM processing was turned off.
if (empty($webformData)) {
return;
}

# Create a handler
$manager = \Drupal::service('plugin.manager.webform.handler');
$handler = $manager->createInstance('webform_civicrm');
Expand Down

2 comments on commit 453b0bd

@stesi561
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I can't see why those values for no_autofill, hide_fields, filter_relationship_types, filter_relationship_contact, group, tag were changed when I compare against https://github.com/colemanw/webform_civicrm/blame/fe2258884c9c741aed65665cb3cc8bc73fd75248/src/Plugin/WebformElement/CivicrmContact.php#L50 they are set that way there.

For the fix for the children I believe I adapted the methodology from webform/src/Utility/WebformElementHelper.php hasChildren I think we are probably better updating the getChildKeys function to not return non arrays - but perhaps it should otherwise that would be an easier test. Might need some more digging here. I guess we also need to think about do those attributes that are not children need migration? Or is there a reason they don't start with a hash.

The skip definitely makes sense. Do you want to pull the first and last change in a PR or 2 and we'll merge those in the children I think I want to figure out more about that - can you give me some steps to create a webform that will cause this problem? What elements do I need in d7 ?

@herbdool
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stesi561 I can make some separate PRs.

In this commit bc15309 to this module it went from being [] to ['' => '']. So it seems like a mistake to me.

In regards to the children. I think the code assumes children arrays always have hashes, but an element with an #options array can contain items that don't start with a hash. For example, I saw something like this:

#options => [
  '0' => 'Red',
  '1 => 'Green',
  '2' => 'Blue,
];

That should be enough I think to recreate the bug.

Please sign in to comment.