Skip to content

Commit

Permalink
Add --sidebar option to create:controller (#1208)
Browse files Browse the repository at this point in the history
Co-authored-by: Luke Towers <[email protected]>
  • Loading branch information
mjauvin and LukeTowers authored Sep 24, 2024
1 parent dd7f500 commit 33087e8
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 3 deletions.
11 changes: 8 additions & 3 deletions modules/backend/console/CreateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CreateController extends BaseScaffoldCommand
{controller : The name of the controller to generate. <info>(eg: Posts)</info>}
{--force : Overwrite existing files with generated files.}
{--model= : Defines the model name to use. If not provided, the singular name of the controller is used.}
{--sidebar : Create stubs for form-with-sidebar layout}
{--uninspiring : Disable inspirational quotes}
';

Expand All @@ -47,10 +48,7 @@ class CreateController extends BaseScaffoldCommand
'scaffold/controller/_list_toolbar.stub' => 'controllers/{{lower_name}}/_list_toolbar.php',
'scaffold/controller/config_form.stub' => 'controllers/{{lower_name}}/config_form.yaml',
'scaffold/controller/config_list.stub' => 'controllers/{{lower_name}}/config_list.yaml',
'scaffold/controller/create.stub' => 'controllers/{{lower_name}}/create.php',
'scaffold/controller/index.stub' => 'controllers/{{lower_name}}/index.php',
'scaffold/controller/preview.stub' => 'controllers/{{lower_name}}/preview.php',
'scaffold/controller/update.stub' => 'controllers/{{lower_name}}/update.php',
'scaffold/controller/controller.stub' => 'controllers/{{studly_name}}.php',
];

Expand All @@ -69,6 +67,13 @@ protected function prepareVars(): array
$model = Str::singular($vars['name']);
}
$vars['model'] = $model;
$vars['sidebar'] = $this->option('sidebar');

$layout = $this->option('sidebar') ? 'sidebar' : 'standard';

$this->stubs["scaffold/controller/{$layout}/create.stub"] = 'controllers/{{lower_name}}/create.php';
$this->stubs["scaffold/controller/{$layout}/update.stub"] = 'controllers/{{lower_name}}/update.php';
$this->stubs["scaffold/controller/{$layout}/preview.stub"] = 'controllers/{{lower_name}}/preview.php';

return $vars;
}
Expand Down
4 changes: 4 additions & 0 deletions modules/backend/console/scaffold/controller/controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ class {{ studly_name }} extends Controller
parent::__construct();

BackendMenu::setContext('{{ plugin_code }}', '{{ lower_plugin }}', '{{ lower_name }}');
{% if sidebar %}

$this->bodyClass = 'compact-container';
{% endif -%}
}
}
64 changes: 64 additions & 0 deletions modules/backend/console/scaffold/controller/sidebar/create.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('{{ controller_url }}') ?>"><?= e(trans('{{ model_lang_key }}.label_plural')) ?></a></li>
<li><?= e(trans($this->pageTitle)) ?></li>
</ul>
<?php Block::endPut() ?>

<?php if (!$this->fatalError): ?>

<?php Block::put('form-contents') ?>
<div class="layout">

<div class="layout-row">
<?= $this->formRenderOutsideFields() ?>
<?= $this->formRenderPrimaryTabs() ?>
</div>

<div class="form-buttons">
<div class="loading-indicator-container">
<button
type="button"
data-request="onSave"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="<?= e(trans('backend::lang.form.creating_name', ['name' => trans('{{ model_lang_key }}.label')])); ?>"
class="btn btn-primary">
<?= e(trans('backend::lang.form.create')); ?>
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="<?= e(trans('backend::lang.form.creating_name', ['name' => trans('{{ model_lang_key }}.label')])); ?>"
class="btn btn-default">
<?= e(trans('backend::lang.form.create_and_close')); ?>
</button>
<span class="btn-text">
or <a href="<?= Backend::url('{{ controller_url }}') ?>"><?= e(trans('backend::lang.form.cancel')); ?></a>
</span>
</div>
</div>

</div>
<?php Block::endPut() ?>

<?php Block::put('form-sidebar') ?>
<div class="hide-tabs"><?= $this->formRenderSecondaryTabs() ?></div>
<?php Block::endPut() ?>

<?php Block::put('body') ?>
<?= Form::open(['class'=>'layout stretch']) ?>
<?= $this->makeLayout('form-with-sidebar') ?>
<?= Form::close() ?>
<?php Block::endPut() ?>

<?php else: ?>
<div class="control-breadcrumb">
<?= Block::placeholder('breadcrumb') ?>
</div>
<div class="padded-container">
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
<p><a href="<?= Backend::url('{{ controller_url }}') ?>" class="btn btn-default"><?= e(trans('backend::lang.form.return_to_list')); ?></a></p>
</div>
<?php endif ?>
39 changes: 39 additions & 0 deletions modules/backend/console/scaffold/controller/sidebar/preview.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('{{ controller_url }}') ?>"><?= e(trans('{{ model_lang_key }}.label_plural')) ?></a></li>
<li><?= e(trans($this->pageTitle)) ?></li>
</ul>
<?php Block::endPut() ?>

<?php if (!$this->fatalError): ?>

<?php Block::put('form-contents') ?>
<div class="layout">

<div class="layout-row">
<?= $this->formRenderOutsideFields() ?>
<?= $this->formRenderPrimaryTabs() ?>
</div>

</div>
<?php Block::endPut() ?>

<?php Block::put('form-sidebar') ?>
<div class="hide-tabs"><?= $this->formRenderSecondaryTabs() ?></div>
<?php Block::endPut() ?>

<?php Block::put('body') ?>
<?= Form::open(['class'=>'layout stretch']) ?>
<?= $this->makeLayout('form-with-sidebar') ?>
<?= Form::close() ?>
<?php Block::endPut() ?>

<?php else: ?>
<div class="control-breadcrumb">
<?= Block::placeholder('breadcrumb') ?>
</div>
<div class="padded-container">
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
<p><a href="<?= Backend::url('{{ controller_url }}') ?>" class="btn btn-default"><?= e(trans('backend::lang.form.return_to_list')); ?></a></p>
</div>
<?php endif ?>
72 changes: 72 additions & 0 deletions modules/backend/console/scaffold/controller/sidebar/update.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('{{ controller_url }}') ?>"><?= e(trans('{{ model_lang_key }}.label_plural')) ?></a></li>
<li><?= e(trans($this->pageTitle)) ?></li>
</ul>
<?php Block::endPut() ?>

<?php if (!$this->fatalError): ?>

<?php Block::put('form-contents') ?>
<div class="layout">

<div class="layout-row">
<?= $this->formRenderOutsideFields() ?>
<?= $this->formRenderPrimaryTabs() ?>
</div>

<div class="form-buttons">
<div class="loading-indicator-container">
<button
type="button"
data-request="onSave"
data-request-data="redirect:0"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="<?= e(trans('backend::lang.form.saving_name', ['name' => trans('{{ model_lang_key }}.label')])); ?>"
class="btn btn-primary">
<?= e(trans('backend::lang.form.save')); ?>
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="<?= e(trans('backend::lang.form.saving_name', ['name' => trans('{{ model_lang_key }}.label')])); ?>"
class="btn btn-default">
<?= e(trans('backend::lang.form.save_and_close')); ?>
</button>
<button
type="button"
class="wn-icon-trash-o btn-icon danger pull-right"
data-request="onDelete"
data-load-indicator="<?= e(trans('backend::lang.form.deleting_name', ['name' => trans('{{ model_lang_key }}.label')])); ?>"
data-request-confirm="<?= e(trans('backend::lang.form.confirm_delete')); ?>">
</button>
<span class="btn-text">
or <a href="<?= Backend::url('{{ controller_url }}') ?>"><?= e(trans('backend::lang.form.cancel')); ?></a>
</span>
</div>
</div>

</div>
<?php Block::endPut() ?>

<?php Block::put('form-sidebar') ?>
<div class="hide-tabs"><?= $this->formRenderSecondaryTabs() ?></div>
<?php Block::endPut() ?>

<?php Block::put('body') ?>
<?= Form::open(['class'=>'layout stretch']) ?>
<?= $this->makeLayout('form-with-sidebar') ?>
<?= Form::close() ?>
<?php Block::endPut() ?>

<?php else: ?>
<div class="control-breadcrumb">
<?= Block::placeholder('breadcrumb') ?>
</div>
<div class="padded-container">
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
<p><a href="<?= Backend::url('{{ controller_url }}') ?>" class="btn btn-default"><?= e(trans('backend::lang.form.return_to_list')); ?></a></p>
</div>
<?php endif ?>

0 comments on commit 33087e8

Please sign in to comment.