Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$child_element - sometimes it's trying to treat a string as an array #2

Open
herbdool opened this issue Mar 31, 2023 · 3 comments · May be fixed by #7
Open

$child_element - sometimes it's trying to treat a string as an array #2

herbdool opened this issue Mar 31, 2023 · 3 comments · May be fixed by #7

Comments

@herbdool
Copy link

I need to investigate this further:

TypeError: Cannot access offset of type string on string in Drupal\webform_civicrm_migrate\EventSubscriber\WebformCivicrmMigrateSubscriber->migrateWebformElement() (line 414 of /app/httpdocs/modules/contrib/webform_civicrm_migrate/src/EventSubscriber/WebformCivicrmMigrateSubscriber.php).

This is where it happens:

        $child_element = $element[$key];
        $child_element['#form_key'] = $new_key;

In the source webform I guess there some cases where the "child element" is not really an element even if it doesn't have a hash. But I'm going to try to find out why.

@herbdool
Copy link
Author

herbdool commented Apr 3, 2023

I think the problem is that getChildren() only skips keys that are blank or start with a hash. But I found some cases which don't match that, such as #options children and #states children. So I tested with checking that the child is an array.

I can start submitting PRs if that helps.

@herbdool herbdool changed the title $child_element - some times its trying to treat a string as an array $child_element - sometimes it's trying to treat a string as an array Apr 3, 2023
herbdool added a commit to freeform/webform_civicrm_migrate that referenced this issue Apr 3, 2023
@stesi561
Copy link
Member

stesi561 commented Apr 4, 2023

I feel like the reason I had those empty strings in arrays was either copied from webform_civicrm or potentially I was comparing the result of exporting a migrated webform with generating one, or even opening and saving and ensuring hte config didn't change.

herbdool added a commit to freeform/webform_civicrm_migrate that referenced this issue Apr 4, 2023
@herbdool herbdool linked a pull request Apr 4, 2023 that will close this issue
@herbdool
Copy link
Author

herbdool commented Apr 4, 2023

@stesi561 you said:

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.

I guess I'm not entirely clear what the method does. If we skip over some elements I figured they would still be there since they're not being unset further down. I've been mostly focused on squashing fatal errors on the migration so I'd need to think about it more.

jmcclelland pushed a commit to progressivetech/webform_civicrm_migrate that referenced this issue May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants