Skip to content
This repository has been archived by the owner on Jun 26, 2018. It is now read-only.

Commit

Permalink
Workaround to address unexpected Pattern Lab Psuedo-Pattern Data Inhe…
Browse files Browse the repository at this point in the history
…ritance (#519)

* Reverting Pattern Lab psuedo-pattern rules to use original merge function vs array_replace_recursive -- temporary workaround to address unexpected behavior from drupal-pattern-lab/patternlab-php-core#12

* Adding composer patch library to automatically apply array_merge patch if/when upstream PL updates should occur

* Adding composer patch plugin to autoloader
  • Loading branch information
sghoweri authored and Jonathan Dallas committed Aug 7, 2017
1 parent fc01047 commit d342b1e
Show file tree
Hide file tree
Showing 16 changed files with 2,548 additions and 35 deletions.
8 changes: 7 additions & 1 deletion styleguide/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"pattern-lab/styleguidekit-assets-default": "^3.0.0",
"pattern-lab/styleguidekit-twig-default": "^3.0.0",
"phing/phing": "^2.14",
"pear/versionControl_git": "dev-master"
"pear/versionControl_git": "dev-master",
"cweagans/composer-patches": "^1.6"
},
"scripts": {
"post-install-cmd": [
Expand Down Expand Up @@ -81,6 +82,11 @@
"config": {
"overrideConfig": false
}
},
"patches": {
"pattern-lab/core": {
"temporarily revert array_replace_recursive function": "patches/PsuedoPatternRule.patch"
}
}
}
}
113 changes: 81 additions & 32 deletions styleguide/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions styleguide/patches/PsuedoPatternRule.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
diff --git a/src/PatternLab/PatternData/Rules/PseudoPatternRule.php b/src/PatternLab/PatternData/Rules/PseudoPatternRule.php
index 8575790c..8136c3c1 100755
--- a/src/PatternLab/PatternData/Rules/PseudoPatternRule.php
+++ b/src/PatternLab/PatternData/Rules/PseudoPatternRule.php
@@ -167,8 +167,19 @@ class PseudoPatternRule extends \PatternLab\PatternData\Rule {

}

+ /** Revert array_replace_recursive function to the original array_merge behavior (added to PL Core in July of 2016
+ * https://github.com/pattern-lab/patternlab-php-core/commit/613c7b6db41610ee858b0a6b80c9e0ffc7aab08f )
+ * NOTE: this should be treated as a temporary workaround to address the differences in behavior
+ * brought up in https://github.com/drupal-pattern-lab/patternlab-php-core/issues/12 until the ability
+ * to officially swap out or change core PL rule behavior is added
+ *
+ * 1. Changed occurrences of `array_replace_recursive` back to original `array_merge`
+ *
+ **/
+
+
// make sure the pattern data is an array before merging the data
- $patternStoreData["data"] = is_array($patternData) ? array_replace_recursive($patternDataBase, $patternData) : $patternDataBase;
+ $patternStoreData["data"] = is_array($patternData) ? array_merge($patternDataBase, $patternData) : $patternDataBase; /* [1] */

// if the pattern data store already exists make sure it is merged and overwrites this data
if (PatternData::checkOption($patternStoreKey)) {
@@ -177,7 +188,7 @@ class PseudoPatternRule extends \PatternLab\PatternData\Rule {
// don't overwrite nameClean
unset($patternStoreData['nameClean']);
}
- $patternStoreData = array_replace_recursive($existingData, $patternStoreData);
+ $patternStoreData = array_merge($existingData, $patternStoreData); /* [1] */
}
PatternData::setOption($patternStoreKey, $patternStoreData);
1 change: 1 addition & 0 deletions styleguide/vendor/composer/autoload_psr4.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
$baseDir = dirname($vendorDir);

return array(
'cweagans\\Composer\\' => array($vendorDir . '/cweagans/composer-patches/src'),
'Symfony\\Component\\Yaml\\' => array($vendorDir . '/symfony/yaml'),
'Symfony\\Component\\Process\\' => array($vendorDir . '/symfony/process'),
'Symfony\\Component\\Finder\\' => array($vendorDir . '/symfony/finder'),
Expand Down
4 changes: 4 additions & 0 deletions styleguide/vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class ComposerStaticInit8b1bb549747f81cdd4aa7e4da433b26e
);

public static $prefixDirsPsr4 = array (
'cweagans\\Composer\\' =>
array (
0 => __DIR__ . '/..' . '/cweagans/composer-patches/src',
),
'Symfony\\Component\\Yaml\\' =>
array (
0 => __DIR__ . '/..' . '/symfony/yaml',
Expand Down
11 changes: 11 additions & 0 deletions styleguide/vendor/cweagans/composer-patches/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This is the top-most .editorconfig file; do not search in parent directories.
root = true

# All files.
[*]
end_of_line = LF
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
1 change: 1 addition & 0 deletions styleguide/vendor/cweagans/composer-patches/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
Loading

0 comments on commit d342b1e

Please sign in to comment.