Skip to content

Commit

Permalink
Merge pull request #142 from LubosRemplik/master
Browse files Browse the repository at this point in the history
Related elements
  • Loading branch information
josegonzalez authored Aug 30, 2016
2 parents b3a7652 + dc0a434 commit 922780c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
15 changes: 6 additions & 9 deletions src/Template/Element/view/related/has_many.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ foreach ($relations as $alias => $details):
?>
<div class="related">
<h3><?= __d('crud', 'Related {0}', [Inflector::humanize($details['controller'])]); ?></h3>
<div class="actions-wrapper">
<?= $this->CrudView->createRelationLink($alias, $details, array('class' => 'btn btn-default'));?>
</div>
<?php
if (${$viewVar}->{$details['entities']}):
?>
Expand Down Expand Up @@ -50,9 +53,9 @@ foreach ($relations as $alias => $details):
}
?>
<td class="actions">
<?= $this->Html->link(__d('crud', 'View'), array('plugin' => $details['plugin'], 'controller' => $details['controller'], 'action' => 'view', ${$otherSingularVar}[$details['primaryKey']])); ?>
<?= $this->Html->link(__d('crud', 'Edit'), array('plugin' => $details['plugin'], 'controller' => $details['controller'], 'action' => 'edit', ${$otherSingularVar}[$details['primaryKey']])); ?>
<?= $this->Html->link(__d('crud', 'Delete'), array('plugin' => $details['plugin'], 'controller' => $details['controller'], 'action' => 'delete', ${$otherSingularVar}[$details['primaryKey']])); ?>
<?= $this->Html->link(__d('crud', 'View'), array('plugin' => $details['plugin'], 'controller' => $details['controller'], 'action' => 'view', ${$otherSingularVar}[$details['primaryKey']]), array('class' => 'btn btn-default')); ?>
<?= $this->Html->link(__d('crud', 'Edit'), array('plugin' => $details['plugin'], 'controller' => $details['controller'], 'action' => 'edit', ${$otherSingularVar}[$details['primaryKey']]), array('class' => 'btn btn-default')); ?>
<?= $this->Html->link(__d('crud', 'Delete'), array('plugin' => $details['plugin'], 'controller' => $details['controller'], 'action' => 'delete', ${$otherSingularVar}[$details['primaryKey']]), array('class' => 'btn btn-default')); ?>
</td>
</tr>
<?php
Expand All @@ -63,12 +66,6 @@ foreach ($relations as $alias => $details):
<?php
endif;
?>

<div class="actions">
<ul>
<li><?= $this->CrudView->createRelationLink($alias, $details);?></li>
</ul>
</div>
</div>
<?php
endforeach;
19 changes: 8 additions & 11 deletions src/Template/Element/view/related/has_one.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ foreach ($associations['oneToOne'] as $alias => $details):
<div class="related">
<h3><?= __d('crud', 'Related {0}', [Inflector::humanize($details['controller'])]); ?></h3>

<div class="actions-wrapper">
<?= $this->Html->link(
__d('crud', 'View {0}', [Inflector::humanize(Inflector::underscore($alias))]),
array('plugin' => $details['plugin'], 'controller' => $details['controller'], 'action' => 'view', ${$viewVar}[$alias][$details['primaryKey']]),
array('class' => 'btn btn-default')
); ?>
</div>

<?php
if (!empty(${$viewVar}->{$alias})) :
?>
Expand All @@ -29,17 +37,6 @@ foreach ($associations['oneToOne'] as $alias => $details):
<?php
endif;
?>

<div class="actions">
<ul>
<li><?= $this->Html->link(
__d('crud', 'View {0}', [Inflector::humanize(Inflector::underscore($alias))]),
array('plugin' => $details['plugin'], 'controller' => $details['controller'], 'action' => 'view', ${$viewVar}[$alias][$details['primaryKey']])
);
?>
</li>
</ul>
</div>
</div>
<?php
endforeach;
4 changes: 3 additions & 1 deletion src/View/CrudView.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ public function exists($name)
/**
* Constructs a ViewBlock from an array of configured data
*
* @return void
* @param array $data ViewBlock data
*
* @return string
*/
protected function _createViewblock($data)
{
Expand Down
8 changes: 5 additions & 3 deletions src/View/Helper/CrudViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function introspect($field, $value, array $options = [])
$value = $this->formatString($field, $value);

if ($field === $this->getViewVar('displayField')) {
return $this->formatdisplayField($value, $options);
return $this->formatDisplayField($value, $options);
}

return $value;
Expand Down Expand Up @@ -317,9 +317,10 @@ public function redirectUrl()
*
* @param string $alias Model alias.
* @param array $relation Relation information.
* @param array $options Options array to be passed to the link function
* @return string
*/
public function createRelationLink($alias, $relation)
public function createRelationLink($alias, $relation, $options = [])
{
return $this->Html->link(
__d('crud', 'Add {0}', [Inflector::singularize(Inflector::humanize(Inflector::underscore($alias)))]),
Expand All @@ -331,7 +332,8 @@ public function createRelationLink($alias, $relation)
$relation['foreignKey'] => $this->getViewVar('primaryKeyValue'),
'_redirect_url' => $this->request->here
]
]
],
$options
);
}

Expand Down

0 comments on commit 922780c

Please sign in to comment.