Skip to content

Commit

Permalink
Add support for nested array to BakeHelper::stringifyList()
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Dec 2, 2017
1 parent fa9639d commit b334b48
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/View/Helper/BakeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,19 @@ public function stringifyList(array $list, array $options = [])
$v = "'$v'";
}
if (!is_numeric($k)) {
$v = "'$k' => $v";
$nestedOptions = $options;
if ($nestedOptions['indent']) {
$nestedOptions['indent'] += 1;
}
if (is_array($v)) {
$v = sprintf(
"'%s' => [%s]",
$k,
$this->stringifyList($v, $nestedOptions)
);
} else {
$v = "'$k' => $v";
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase/Shell/Task/ModelTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,8 @@ public function testGetBehaviors()
$behaviors = $this->Task->getBehaviors($model);

$behaviors['Translate'] = [
'defaultLocale' => "'fr_FR'"
'defaultLocale' => "'fr_FR'",
'implementedFinders' => ['translations' => "'findTranslations'"],
];

$result = $this->Task->bakeTable($model, ['behaviors' => $behaviors]);
Expand Down
5 changes: 4 additions & 1 deletion tests/comparisons/Model/testGetBehaviors.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public function initialize(array $config)
'Users' => ['post_count']
]);
$this->addBehavior('Translate', [
'defaultLocale' => 'fr_FR'
'defaultLocale' => 'fr_FR',
'implementedFinders' => [
'translations' => 'findTranslations'
]
]);
}

Expand Down

0 comments on commit b334b48

Please sign in to comment.