From 6517ffc6e6c29fdd355e352350d412d2a9a7b85c Mon Sep 17 00:00:00 2001 From: "Robert J. Lang" Date: Sun, 28 Mar 2021 17:26:22 -0700 Subject: [PATCH] =?UTF-8?q?Issue=2043:=20initialization=20from=20array()?= =?UTF-8?q?=20leads=20to=20=E2=80=9Cdynamic=20value=E2=80=A6=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes the issue where initializing a variable_get() from an empty array leads to a “dynamic value…” in .install and config file. --- conversions/call.inc | 6 +++++- conversions/end.inc | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/conversions/call.inc b/conversions/call.inc index e4262bf..9d83587 100644 --- a/conversions/call.inc +++ b/conversions/call.inc @@ -65,7 +65,11 @@ function coder_upgrade_upgrade_call_variable_get_alter(&$node, &$reader) { // DO } elseif ($item->printParameter(1)) { $value = str_replace("'", '', $item->printParameter(1)); - if (preg_match('@[\.\s\$\[\]\#\>\(]@', $value)) { + // Catch initialization with empty array. + if ($value == 'array()') { + $value = array(); + } + elseif (preg_match('@[\.\s\$\[\]\#\>\(]@', $value)) { $value = 'dynamic value in file ' . $path . ' line ' . $node->line; } } diff --git a/conversions/end.inc b/conversions/end.inc index f30a389..4e6ce5b 100644 --- a/conversions/end.inc +++ b/conversions/end.inc @@ -281,6 +281,10 @@ function coder_upgrade_create_update_install($module_name, &$reader, &$nodes, $c $line_matches = array(); foreach ($config_data as $key => $line) { + if ($line == array()) { + // Catch initialization with empty array. + continue; + } if (preg_match('/(dynamic variable in file )(.*)/', $line, $matches) || preg_match('/(dynamic value in file )(.*)/', $line, $matches)) { $line_matches[] = $matches[2]; } @@ -359,7 +363,13 @@ function coder_upgrade_create_update_1000($module_name, &$reader, &$nodes, $conf $body->insertLast($body_content); foreach ($config_data as $key => $line) { - $string = " \$config->set('$key', update_variable_get('$key', '$line'));"; + // Catch initialization with empty array. + if ($line == array()) { + $string = " \$config->set('$key', update_variable_get('$key', array()));"; + } + else { + $string = " \$config->set('$key', update_variable_get('$key', '$line'));"; + } $body_content = $editor->textToStatements($string)->getElement(0); $body->insertLast($body_content); }