Skip to content

Commit

Permalink
Fix missing plugin parameters in scaffolding.
Browse files Browse the repository at this point in the history
Add missing plugin parameter to scaffolded associations.
This improves link generation and correctness overall.

Fixes #3396
  • Loading branch information
markstory committed Nov 28, 2012
1 parent c727444 commit 966c69c
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 18 deletions.
8 changes: 7 additions & 1 deletion lib/Cake/Controller/Scaffold.php
Expand Up @@ -433,8 +433,14 @@ protected function _associations() {
$associations[$type][$assocKey]['foreignKey'] =
$assocData['foreignKey'];

list($plugin, $model) = pluginSplit($assocData['className']);
if ($plugin) {
$plugin = Inflector::underscore($plugin);
}
$associations[$type][$assocKey]['plugin'] = $plugin;

$associations[$type][$assocKey]['controller'] =
Inflector::pluralize(Inflector::underscore($assocData['className']));
Inflector::pluralize(Inflector::underscore($model));

if ($type == 'hasAndBelongsToMany') {
$associations[$type][$assocKey]['with'] = $assocData['with'];
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Test/Case/Controller/ScaffoldTest.php
Expand Up @@ -217,6 +217,7 @@ public function testScaffoldVariableSetting() {
$this->assertEquals('scaffoldMock', $result['singularVar']);
$this->assertEquals('scaffoldMock', $result['pluralVar']);
$this->assertEquals(array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated'), $result['scaffoldFields']);
$this->assertArrayHasKey('plugin', $result['associations']['belongsTo']['User']);
}

/**
Expand Down
12 changes: 9 additions & 3 deletions lib/Cake/View/Scaffolds/form.ctp
Expand Up @@ -40,12 +40,18 @@
foreach ($associations as $_type => $_data) {
foreach ($_data as $_alias => $_details) {
if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) {
echo "\t\t<li>" . $this->Html->link(__d('cake', 'List %s', Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' => 'index')) . "</li>\n";
echo "\t\t<li>" . $this->Html->link(__d('cake', 'New %s', Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add')) . "</li>\n";
echo "\t\t<li>" . $this->Html->link(
__d('cake', 'List %s', Inflector::humanize($_details['controller'])),
array('plugin' => $_details['plugin'], 'controller' => $_details['controller'], 'action' => 'index')
) . "</li>\n";
echo "\t\t<li>" . $this->Html->link(
__d('cake', 'New %s', Inflector::humanize(Inflector::underscore($_alias))),
array('plugin' => $_details['plugin'], 'controller' => $_details['controller'], 'action' => 'add')
) . "</li>\n";
$done[] = $_details['controller'];
}
}
}
?>
</ul>
</div>
</div>
15 changes: 13 additions & 2 deletions lib/Cake/View/Scaffolds/index.ctp
Expand Up @@ -82,8 +82,19 @@ endforeach;
foreach ($associations as $_type => $_data) {
foreach ($_data as $_alias => $_details) {
if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) {
echo '<li>' . $this->Html->link(__d('cake', 'List %s', Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' => 'index')) . '</li>';
echo '<li>' . $this->Html->link(__d('cake', 'New %s', Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add')) . '</li>';
echo '<li>';
echo $this->Html->link(
__d('cake', 'List %s', Inflector::humanize($_details['controller'])),
array('plugin' => $_details['plugin'], 'controller' => $_details['controller'], 'action' => 'index')
);
echo '</li>';

echo '<li>';
echo $this->Html->link(
__d('cake', 'New %s', Inflector::humanize(Inflector::underscore($_alias))),
array('plugin' => $_details['plugin'], 'controller' => $_details['controller'], 'action' => 'add')
);
echo '</li>';
$done[] = $_details['controller'];
}
}
Expand Down
76 changes: 64 additions & 12 deletions lib/Cake/View/Scaffolds/view.ctp
Expand Up @@ -28,7 +28,12 @@ foreach ($scaffoldFields as $_field) {
if ($_field === $_details['foreignKey']) {
$isKey = true;
echo "\t\t<dt>" . Inflector::humanize($_alias) . "</dt>\n";
echo "\t\t<dd>\n\t\t\t" . $this->Html->link(${$singularVar}[$_alias][$_details['displayField']], array('controller' => $_details['controller'], 'action' => 'view', ${$singularVar}[$_alias][$_details['primaryKey']])) . "\n\t\t&nbsp;</dd>\n";
echo "\t\t<dd>\n\t\t\t";
echo $this->Html->link(
${$singularVar}[$_alias][$_details['displayField']],
array('plugin' => $_details['plugin'], 'controller' => $_details['controller'], 'action' => 'view', ${$singularVar}[$_alias][$_details['primaryKey']])
);
echo "\n\t\t&nbsp;</dd>\n";
break;
}
}
Expand All @@ -45,17 +50,38 @@ foreach ($scaffoldFields as $_field) {
<h3><?php echo __d('cake', 'Actions'); ?></h3>
<ul>
<?php
echo "\t\t<li>" . $this->Html->link(__d('cake', 'Edit %s', $singularHumanName), array('action' => 'edit', ${$singularVar}[$modelClass][$primaryKey])) . " </li>\n";
echo "\t\t<li>" . $this->Form->postLink(__d('cake', 'Delete %s', $singularHumanName), array('action' => 'delete', ${$singularVar}[$modelClass][$primaryKey]), null, __d('cake', 'Are you sure you want to delete').' #' . ${$singularVar}[$modelClass][$primaryKey] . '?') . " </li>\n";
echo "\t\t<li>" . $this->Html->link(__d('cake', 'List %s', $pluralHumanName), array('action' => 'index')) . " </li>\n";
echo "\t\t<li>" . $this->Html->link(__d('cake', 'New %s', $singularHumanName), array('action' => 'add')) . " </li>\n";
echo "\t\t<li>";
echo $this->Html->link(__d('cake', 'Edit %s', $singularHumanName), array('action' => 'edit', ${$singularVar}[$modelClass][$primaryKey]));
echo " </li>\n";

echo "\t\t<li>";
echo $this->Form->postLink(__d('cake', 'Delete %s', $singularHumanName), array('action' => 'delete', ${$singularVar}[$modelClass][$primaryKey]), null, __d('cake', 'Are you sure you want to delete').' #' . ${$singularVar}[$modelClass][$primaryKey] . '?');
echo " </li>\n";

echo "\t\t<li>";
echo $this->Html->link(__d('cake', 'List %s', $pluralHumanName), array('action' => 'index'));
echo " </li>\n";

echo "\t\t<li>";
echo $this->Html->link(__d('cake', 'New %s', $singularHumanName), array('action' => 'add'));
echo " </li>\n";

$done = array();
foreach ($associations as $_type => $_data) {
foreach ($_data as $_alias => $_details) {
if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) {
echo "\t\t<li>" . $this->Html->link(__d('cake', 'List %s', Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' => 'index')) . "</li>\n";
echo "\t\t<li>" . $this->Html->link(__d('cake', 'New %s', Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add')) . "</li>\n";
echo "\t\t<li>";
echo $this->Html->link(
__d('cake', 'List %s', Inflector::humanize($_details['controller'])),
array('plugin' => $_details['plugin'], 'controller' => $_details['controller'], 'action' => 'index')
);
echo "</li>\n";
echo "\t\t<li>";
echo $this->Html->link(
__d('cake', 'New %s', Inflector::humanize(Inflector::underscore($_alias))),
array('plugin' => $_details['plugin'], 'controller' => $_details['controller'], 'action' => 'add')
);
echo "</li>\n";
$done[] = $_details['controller'];
}
}
Expand All @@ -82,7 +108,13 @@ foreach ($associations['hasOne'] as $_alias => $_details): ?>
<?php endif; ?>
<div class="actions">
<ul>
<li><?php echo $this->Html->link(__d('cake', 'Edit %s', Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'edit', ${$singularVar}[$_alias][$_details['primaryKey']]))."</li>\n"; ?>
<li><?php
echo $this->Html->link(
__d('cake', 'Edit %s', Inflector::humanize(Inflector::underscore($_alias))),
array('plugin' => $_details['plugin'], 'controller' => $_details['controller'], 'action' => 'edit', ${$singularVar}[$_alias][$_details['primaryKey']])
);
echo "</li>\n";
?>
</ul>
</div>
</div>
Expand Down Expand Up @@ -128,9 +160,26 @@ $otherSingularVar = Inflector::variable($_alias);
}

echo "\t\t\t<td class=\"actions\">\n";
echo "\t\t\t\t" . $this->Html->link(__d('cake', 'View'), array('controller' => $_details['controller'], 'action' => 'view', ${$otherSingularVar}[$_details['primaryKey']])). "\n";
echo "\t\t\t\t" . $this->Html->link(__d('cake', 'Edit'), array('controller' => $_details['controller'], 'action' => 'edit', ${$otherSingularVar}[$_details['primaryKey']])). "\n";
echo "\t\t\t\t" . $this->Form->postLink(__d('cake', 'Delete'), array('controller' => $_details['controller'], 'action' => 'delete', ${$otherSingularVar}[$_details['primaryKey']]), null, __d('cake', 'Are you sure you want to delete', true).' #' . ${$otherSingularVar}[$_details['primaryKey']] . '?'). "\n";
echo "\t\t\t\t";
echo $this->Html->link(
__d('cake', 'View'),
array('plugin' => $_details['plugin'], 'controller' => $_details['controller'], 'action' => 'view', ${$otherSingularVar}[$_details['primaryKey']])
);
echo "\n";
echo "\t\t\t\t";
echo $this->Html->link(
__d('cake', 'Edit'),
array('plugin' => $_details['plugin'], 'controller' => $_details['controller'], 'action' => 'edit', ${$otherSingularVar}[$_details['primaryKey']])
);
echo "\n";
echo "\t\t\t\t";
echo $this->Form->postLink(
__d('cake', 'Delete'),
array('plugin' => $_details['plugin'], 'controller' => $_details['controller'], 'action' => 'delete', ${$otherSingularVar}[$_details['primaryKey']]),
null,
__d('cake', 'Are you sure you want to delete', true) .' #' . ${$otherSingularVar}[$_details['primaryKey']] . '?'
);
echo "\n";
echo "\t\t\t</td>\n";
echo "\t\t</tr>\n";
endforeach;
Expand All @@ -139,7 +188,10 @@ $otherSingularVar = Inflector::variable($_alias);
<?php endif; ?>
<div class="actions">
<ul>
<li><?php echo $this->Html->link(__d('cake', "New %s", Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add')); ?> </li>
<li><?php echo $this->Html->link(
__d('cake', "New %s", Inflector::humanize(Inflector::underscore($_alias))),
array('plugin' => $_details['plugin'], 'controller' => $_details['controller'], 'action' => 'add')
); ?> </li>
</ul>
</div>
</div>
Expand Down

0 comments on commit 966c69c

Please sign in to comment.