-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sample single page to manage config value
Fixed #4
- Loading branch information
Showing
6 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Concrete\Package\V9PackageBoilerplate\Controller\SinglePage\Dashboard\System; | ||
|
||
use Concrete\Core\Page\Controller\DashboardPageController; | ||
use Concrete\Core\Url\Resolver\Manager\ResolverManagerInterface; | ||
|
||
class Boilerplate extends DashboardPageController | ||
{ | ||
public function view() | ||
{ | ||
/** @var ResolverManagerInterface $resolver */ | ||
$resolver = $this->app->make(ResolverManagerInterface::class); | ||
|
||
return $this->buildRedirect($resolver->resolve(['/dashboard/system/boilerplate/config'])); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
controllers/single_page/dashboard/system/boilerplate/config.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Concrete\Package\V9PackageBoilerplate\Controller\SinglePage\Dashboard\System\Boilerplate; | ||
|
||
use Concrete\Core\Config\Repository\Liaison; | ||
use Concrete\Core\Package\PackageService; | ||
use Concrete\Core\Page\Controller\DashboardPageController; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
|
||
class Config extends DashboardPageController | ||
{ | ||
public function view() | ||
{ | ||
$config = $this->getConfig(); | ||
if ($config) { | ||
$example_value = $config->get('app.example'); | ||
$this->set('example_value', $example_value); | ||
} | ||
} | ||
|
||
public function submit(): ?RedirectResponse | ||
{ | ||
if (!$this->token->validate('update_config')) { | ||
$this->error->add($this->token->getErrorMessage()); | ||
} | ||
|
||
$example_value = trim($this->post('example_key')); | ||
if (empty($example_value)) { | ||
$this->error->add(t('The key is required.')); | ||
} | ||
|
||
if (!$this->error->has()) { | ||
$config = $this->getConfig(); | ||
if ($config) { | ||
$config->save('app.example', $example_value); | ||
$this->flash('success', t('The settings has been successfully updated.')); | ||
} | ||
|
||
return $this->buildRedirect([$this->getPageObject()]); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
protected function getConfig(): ?Liaison | ||
{ | ||
/** @var PackageService $packageService */ | ||
$packageService = $this->app->make(PackageService::class); | ||
$package = $packageService->getClass('v9_package_boilerplate'); | ||
if ($package) { | ||
return $package->getFileConfig(); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
defined('C5_EXECUTE') or die('Access Denied.'); | ||
|
||
/** @var \Concrete\Core\Page\View\PageView $view */ | ||
/** @var \Concrete\Core\Form\Service\Form $form */ | ||
/** @var \Concrete\Core\Validation\CSRF\Token $token */ | ||
|
||
$example_value = $example_value ?? null; | ||
?> | ||
<form action="<?= $view->action('submit') ?>" method="post"> | ||
<?php $token->output('update_config'); ?> | ||
|
||
<div class="form-group"> | ||
<?= $form->label('example_key', t('Example Config Value')) ?> | ||
<?= $form->text('example_key', $example_value) ?> | ||
<p class="help-block"><?= t('This is an example config value and not used in anywhere.') ?></p> | ||
</div> | ||
|
||
<div class="ccm-dashboard-form-actions-wrapper"> | ||
<div class="ccm-dashboard-form-actions"> | ||
<button type="submit" class="btn btn-primary float-end"> | ||
<?php echo t('Save') ?> | ||
</button> | ||
</div> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
defined('C5_EXECUTE') or die('Access Denied.'); |