Fix missing plugin parameters in scaffolding.

Add missing plugin parameter to scaffolded associations.
This improves link generation and correctness overall.

Fixes #3396
This commit is contained in:
mark_story 2012-11-27 21:57:12 -05:00
parent c727444880
commit 966c69cb98
5 changed files with 94 additions and 18 deletions

View file

@ -433,8 +433,14 @@ class Scaffold {
$associations[$type][$assocKey]['foreignKey'] = $associations[$type][$assocKey]['foreignKey'] =
$assocData['foreignKey']; $assocData['foreignKey'];
list($plugin, $model) = pluginSplit($assocData['className']);
if ($plugin) {
$plugin = Inflector::underscore($plugin);
}
$associations[$type][$assocKey]['plugin'] = $plugin;
$associations[$type][$assocKey]['controller'] = $associations[$type][$assocKey]['controller'] =
Inflector::pluralize(Inflector::underscore($assocData['className'])); Inflector::pluralize(Inflector::underscore($model));
if ($type == 'hasAndBelongsToMany') { if ($type == 'hasAndBelongsToMany') {
$associations[$type][$assocKey]['with'] = $assocData['with']; $associations[$type][$assocKey]['with'] = $assocData['with'];

View file

@ -217,6 +217,7 @@ class ScaffoldTest extends CakeTestCase {
$this->assertEquals('scaffoldMock', $result['singularVar']); $this->assertEquals('scaffoldMock', $result['singularVar']);
$this->assertEquals('scaffoldMock', $result['pluralVar']); $this->assertEquals('scaffoldMock', $result['pluralVar']);
$this->assertEquals(array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated'), $result['scaffoldFields']); $this->assertEquals(array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated'), $result['scaffoldFields']);
$this->assertArrayHasKey('plugin', $result['associations']['belongsTo']['User']);
} }
/** /**

View file

@ -40,8 +40,14 @@
foreach ($associations as $_type => $_data) { foreach ($associations as $_type => $_data) {
foreach ($_data as $_alias => $_details) { foreach ($_data as $_alias => $_details) {
if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) { 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(
echo "\t\t<li>" . $this->Html->link(__d('cake', 'New %s', Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add')) . "</li>\n"; __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']; $done[] = $_details['controller'];
} }
} }

View file

@ -82,8 +82,19 @@ endforeach;
foreach ($associations as $_type => $_data) { foreach ($associations as $_type => $_data) {
foreach ($_data as $_alias => $_details) { foreach ($_data as $_alias => $_details) {
if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) { 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>';
echo '<li>' . $this->Html->link(__d('cake', 'New %s', Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add')) . '</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']; $done[] = $_details['controller'];
} }
} }

View file

@ -28,7 +28,12 @@ foreach ($scaffoldFields as $_field) {
if ($_field === $_details['foreignKey']) { if ($_field === $_details['foreignKey']) {
$isKey = true; $isKey = true;
echo "\t\t<dt>" . Inflector::humanize($_alias) . "</dt>\n"; 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; break;
} }
} }
@ -45,17 +50,38 @@ foreach ($scaffoldFields as $_field) {
<h3><?php echo __d('cake', 'Actions'); ?></h3> <h3><?php echo __d('cake', 'Actions'); ?></h3>
<ul> <ul>
<?php <?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>";
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 $this->Html->link(__d('cake', 'Edit %s', $singularHumanName), array('action' => 'edit', ${$singularVar}[$modelClass][$primaryKey]));
echo "\t\t<li>" . $this->Html->link(__d('cake', 'List %s', $pluralHumanName), array('action' => 'index')) . " </li>\n"; echo " </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->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(); $done = array();
foreach ($associations as $_type => $_data) { foreach ($associations as $_type => $_data) {
foreach ($_data as $_alias => $_details) { foreach ($_data as $_alias => $_details) {
if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) { 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>";
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 $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']; $done[] = $_details['controller'];
} }
} }
@ -82,7 +108,13 @@ foreach ($associations['hasOne'] as $_alias => $_details): ?>
<?php endif; ?> <?php endif; ?>
<div class="actions"> <div class="actions">
<ul> <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> </ul>
</div> </div>
</div> </div>
@ -128,9 +160,26 @@ $otherSingularVar = Inflector::variable($_alias);
} }
echo "\t\t\t<td class=\"actions\">\n"; 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";
echo "\t\t\t\t" . $this->Html->link(__d('cake', 'Edit'), array('controller' => $_details['controller'], 'action' => 'edit', ${$otherSingularVar}[$_details['primaryKey']])). "\n"; echo $this->Html->link(
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"; __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\t</td>\n";
echo "\t\t</tr>\n"; echo "\t\t</tr>\n";
endforeach; endforeach;
@ -139,7 +188,10 @@ $otherSingularVar = Inflector::variable($_alias);
<?php endif; ?> <?php endif; ?>
<div class="actions"> <div class="actions">
<ul> <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> </ul>
</div> </div>
</div> </div>