Skip to content

Instantly share code, notes, and snippets.

@cdracars
Created November 9, 2021 22:30
Show Gist options
  • Save cdracars/33399d76996317af6a6da4d00bdb7492 to your computer and use it in GitHub Desktop.
Save cdracars/33399d76996317af6a6da4d00bdb7492 to your computer and use it in GitHub Desktop.
Very basic python script to update form_state from Drupal 7 to Drupal 9.
#!/usr/bin/env python3
import re
filename = 'fsp_competitive_cross_reference.cut_n_paste.inc'
# Read in the file
with open(filename, 'r') as file:
filedata = file.read()
# print(filedata)
values = re.findall("\$form_state\['values'\].*\]", filedata)
temp = re.sub(r"(\$form_state\['values'\]\[)('.*')(\])", r'$form_state->getValue(\2)', filedata)
print(temp)
@worxco
Copy link

worxco commented Dec 2, 2021

damn thing pulled my astericks.... I should have probably used somthing that indicated this was code....
regex is a bit greedy - so on line 12 your closing .*\] would consume all characters until the LAST ] and not the first ] (if there was more than one....) that is why I used, (in the vim description) '[^']*'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment