Skip to content

Commit

Permalink
Merge pull request #209 from FriendsOfCake/form-buttons
Browse files Browse the repository at this point in the history
Form buttons
  • Loading branch information
ADmad authored Sep 3, 2017
2 parents 7a53156 + d380085 commit 3e522e3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
34 changes: 21 additions & 13 deletions src/Listener/Traits/FormTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,41 @@ protected function _getFormSubmitExtraButtons()
return [];
}

$defaults = [
[
if ($buttons === null || $buttons === true) {
$buttons = $this->_getDefaultExtraButtons();
}

return $buttons;
}

/**
* Get default extra buttons
*
* @return array
*/
protected function _getDefaultExtraButtons()
{
return [
'save_and_continue' => [
'title' => __d('crud', 'Save & continue editing'),
'options' => ['class' => 'btn btn-success btn-save-continue', 'name' => '_edit', 'value' => true],
'options' => ['class' => 'btn btn-success btn-save-continue', 'name' => '_edit', 'value' => '1'],
'type' => 'button',
'_label' => 'save_and_continue',
],
[
'save_and_create' => [
'title' => __d('crud', 'Save & create new'),
'options' => ['class' => 'btn btn-success', 'name' => '_add', 'value' => true],
'options' => ['class' => 'btn btn-success', 'name' => '_add', 'value' => '1'],
'type' => 'button',
'_label' => 'save_and_create',
],
[
'back' => [
'title' => __d('crud', 'Back'),
'url' => ['action' => 'index'],
'options' => ['class' => 'btn btn-default', 'role' => 'button', 'value' => true],
'options' => ['class' => 'btn btn-default', 'role' => 'button'],
'type' => 'link',
'_label' => 'back',
],
];

if ($buttons === null || $buttons === true) {
$buttons = $defaults;
}

return $buttons;
}

/**
Expand Down
20 changes: 11 additions & 9 deletions src/Template/Element/form/buttons.ctp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<div class="col pull-right">
<?= $this->Form->button(
$formSubmitButtonText,
['class' => 'btn btn-primary', 'name' => '_save', 'value' => '1']
) ?>
<?php
echo $this->Form->button($formSubmitButtonText, ['class' => 'btn btn-primary', 'name' => '_save']);

if (!empty($formSubmitExtraButtons)) {
foreach ($formSubmitExtraButtons as $button) {
if ($button['type'] === 'button') {
echo $this->Form->button($button['title'], $button['options']);
} elseif ($button['type'] === 'link') {
echo $this->Html->link($button['title'], $button['url'], $button['options']);
}
if (!empty($formSubmitExtraButtons)) {
foreach ($formSubmitExtraButtons as $button) {
if ($button['type'] === 'button') {
echo $this->Form->button($button['title'], $button['options']);
} elseif ($button['type'] === 'link') {
echo $this->Html->link($button['title'], $button['url'], $button['options']);
}
}
}
?>
</div>

0 comments on commit 3e522e3

Please sign in to comment.