Skip to content

Commit

Permalink
Adds --design option to create:Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
daftspunk committed Feb 29, 2024
1 parent 1e23041 commit 5610592
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 4 deletions.
29 changes: 26 additions & 3 deletions src/Scaffold/Console/CreateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class CreateController extends GeneratorCommandBase
{namespace : App or Plugin Namespace. <info>(eg: Acme.Blog)</info>}
{name : The name of the controller. Eg: Posts}
{--model= : Define which model name to use, otherwise the singular controller name is used.}
{--design= : Specify a design (basic, sidebar, survey, popup, custom)}
{--no-form : Do not implement a form for this controller}
{--no-list : Do not implement a list for this controller}
{--o|overwrite : Overwrite existing files with generated ones}';
Expand All @@ -34,6 +35,8 @@ class CreateController extends GeneratorCommandBase
*/
public function makeStubs()
{
$design = $this->defineDesignMode();

$this->makeStub('controller/controller.stub', 'controllers/{{studly_name}}.php');

if (!$this->option('no-list')) {
Expand All @@ -44,9 +47,16 @@ public function makeStubs()

if (!$this->option('no-form')) {
$this->makeStub('controller/config_form.stub', 'controllers/{{lower_name}}/config_form.yaml');
$this->makeStub('controller/update.stub', 'controllers/{{lower_name}}/update.php');
$this->makeStub('controller/preview.stub', 'controllers/{{lower_name}}/preview.php');
$this->makeStub('controller/create.stub', 'controllers/{{lower_name}}/create.php');
if (in_array($design, ['basic', 'sidebar', 'survey'])) {
$this->makeStub('controller/update_design.stub', 'controllers/{{lower_name}}/update.php');
$this->makeStub('controller/preview_design.stub', 'controllers/{{lower_name}}/preview.php');
$this->makeStub('controller/create_design.stub', 'controllers/{{lower_name}}/create.php');
}
elseif ($design !== 'popup') {
$this->makeStub('controller/update.stub', 'controllers/{{lower_name}}/update.php');
$this->makeStub('controller/preview.stub', 'controllers/{{lower_name}}/preview.php');
$this->makeStub('controller/create.stub', 'controllers/{{lower_name}}/create.php');
}
}
}

Expand All @@ -59,6 +69,7 @@ protected function prepareVars(): array
'name' => $this->argument('name'),
'namespace' => $this->argument('namespace'),
'model' => $this->defineModelName(),
'design' => $this->defineDesignMode(),
'form' => !$this->option('no-form'),
'list' => !$this->option('no-list'),
];
Expand All @@ -78,4 +89,16 @@ protected function defineModelName(): string
return $model;

}

/**
* defineDesignMode
*/
protected function defineDesignMode(): string
{
if ($design = $this->option('design')) {
return trim(strtolower($design));
}

return '';
}
}
11 changes: 10 additions & 1 deletion src/Scaffold/Console/controller/_list_toolbar.stub
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<div data-control="toolbar loader-container">
{% if design == 'popup' %}
<button
type="button"
data-control="popup"
data-handler="onLoadPopupForm"
class="btn btn-primary">
<?= __("New :name", ['name' => '{{title_singular_name}}']) ?>
</button>
{% else %}
<a
href="<?= Backend::url('{{namespace_path}}/{{lower_name}}/create') ?>"
class="btn btn-primary">
<i class="icon-plus"></i>
<?= __("New :name", ['name' => '{{title_singular_name}}']) ?>
</a>

{% endif %}

<div class="toolbar-divider"></div>

Expand Down
6 changes: 6 additions & 0 deletions src/Scaffold/Console/controller/config_form.stub
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ modelClass: {{namespace_php}}\Models\{{studly_model}}
# Default redirect location
defaultRedirect: {{namespace_path}}/{{lower_name}}

{% if design %}
# Form Design
design:
displayMode: {{design}}

{% endif %}
# Create page
create:
title: backend::lang.form.create_title
Expand Down
5 changes: 5 additions & 0 deletions src/Scaffold/Console/controller/config_list.stub
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ modelClass: {{namespace_php}}\Models\{{studly_model}}
# List Title
title: Manage {{title_plural_name}}

{% if design == 'popup' %}
# Link each record to popup form design
recordOnClick: popup
{% else %}
# Link URL for each record
recordUrl: {{namespace_path}}/{{lower_name}}/update/:id
{% endif %}

# Message to display if the list is empty
noRecordsMessage: backend::lang.list.no_records
Expand Down
8 changes: 8 additions & 0 deletions src/Scaffold/Console/controller/create_design.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php Block::put('breadcrumb') ?>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="<?= Backend::url('{{namespace_path}}/{{lower_name}}') ?>">{{title_name}}</a></li>
<li class="breadcrumb-item active" aria-current="page"><?= e($this->pageTitle) ?></li>
</ol>
<?php Block::endPut() ?>

<?= $this->formRenderDesign() ?>
8 changes: 8 additions & 0 deletions src/Scaffold/Console/controller/preview_design.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php Block::put('breadcrumb') ?>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="<?= Backend::url('{{namespace_path}}/{{lower_name}}') ?>">{{title_name}}</a></li>
<li class="breadcrumb-item active" aria-current="page"><?= e($this->pageTitle) ?></li>
</ol>
<?php Block::endPut() ?>

<?= $this->formRenderDesign() ?>
8 changes: 8 additions & 0 deletions src/Scaffold/Console/controller/update_design.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php Block::put('breadcrumb') ?>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="<?= Backend::url('{{namespace_path}}/{{lower_name}}') ?>">{{title_name}}</a></li>
<li class="breadcrumb-item active" aria-current="page"><?= e($this->pageTitle) ?></li>
</ol>
<?php Block::endPut() ?>

<?= $this->formRenderDesign() ?>

0 comments on commit 5610592

Please sign in to comment.