Skip to content

Commit

Permalink
Merge pull request #239 from FriendsOfCake/action-links
Browse files Browse the repository at this point in the history
Fix action links generation.
  • Loading branch information
josegonzalez authored Apr 4, 2018
2 parents b3b37e7 + f1a8535 commit 771f3a4
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/Template/Element/actions.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,22 @@ foreach ($actions as $name => $config) {

$url = $config['url'];
if (!empty($singularVar)) {
$setPrimaryKey = false;
$modifiedUrl = [];
$setPrimaryKey = true;
foreach ($url as $key => $value) {
if (is_array($value)) {
if (!is_string($value)) {
continue;
}

list($k, $v) = str_replace(':primaryKey:', $singularVar->{$primaryKey}, [$key, $value]);
if ($key != $k) {
$setPrimaryKey = true;
if (strpos($value, ':primaryKey:') !== false) {
$url[$key] = str_replace(
':primaryKey:',
$singularVar->{$primaryKey},
$value
);
$setPrimaryKey = false;
}
if ($value != $v) {
$setPrimaryKey = true;
}
$modifiedUrl[$k] = $v;
}
$url = $modifiedUrl;
if (!$setPrimaryKey) {
if ($setPrimaryKey) {
$url[] = $singularVar->{$primaryKey};
}
}
Expand Down

0 comments on commit 771f3a4

Please sign in to comment.