
Expressフォームのデザインカスタマイズ方法
カスタムコントローラー作成
protected $pkgAutoloaderRegistries = array(
'src/TestSite' => '\TestSite',
);


<?php
namespace TestSite\Express\Controller;
use Concrete\Core\Express\Controller\StandardController;
class FormController extends StandardController
{
}
public function on_start()
{
$this->app->make('Concrete\Core\Express\Controller\Manager')
->setStandardController('TestSite\Express\Controller\FormController');
}
コンテキストレジスタの実装

<?php
namespace TestSite\Express\Form\Context;
use Concrete\Core\Express\Form\Context\FrontendFormContext as CoreFrontendFormContext;
class FrontendFormContext extends CoreFrontendFormContext
{
}
<?php
namespace TestSite\Express\Controller;
use Concrete\Core\Express\Controller\StandardController;
use Concrete\Core\Express\Form\Context\FrontendFormContext as CoreFrontendFormContext;
use TestSite\Express\Form\Context\FrontendFormContext;
use Concrete\Core\Form\Context\Registry\ContextRegistry;
class FormController extends StandardController
{
public function getContextRegistry()
{
return new ContextRegistry([
CoreFrontendFormContext::class => new FrontendFormContext()
]);
}
}
コンテキストをカスタマイズ
<?php
namespace TestSite\Express\Form\Context;
use Concrete\Core\Express\Form\Context\FrontendFormContext as CoreFrontendFormContext;
use Concrete\Core\Filesystem\TemplateLocator;
class FrontendFormContext extends CoreFrontendFormContext
{
public function setLocation(TemplateLocator $locator)
{
$locator = parent::setLocation($locator);
$locator->prependLocation([DIRNAME_ELEMENTS .
DIRECTORY_SEPARATOR .
DIRNAME_EXPRESS .
DIRECTORY_SEPARATOR .
DIRNAME_EXPRESS_FORM_CONTROLS .
DIRECTORY_SEPARATOR .
DIRNAME_EXPRESS_FORM_CONTROLS // not a typo
, 'theme_test']);
return $locator;
}
}
カスタムコントロールテンプレート作成
<?php
use Concrete\Core\Page\Page;
defined('C5_EXECUTE') or die("Access Denied.");
/**
* @var Concrete\Core\Express\Form\Context\FrontendFormContext $context
* @var Concrete\Core\Entity\Express\Form $form
* @var Concrete\Core\Validation\CSRF\Token $token
*/
$page = Page::getCurrentPage();
if (!$page || $page->isError() || !$page->isEditMode()) {
$token->output('express_form');
}
?>
<input type="hidden" name="express_form_id" value="<?=$form->getID()?>">
<div class="ccm-dashboard-express-form">
<?php
foreach ($form->getFieldSets() as $fieldSet) { ?>
<fieldset>
<?php if ($fieldSet->getTitle()) { ?>
<legend><?= h($fieldSet->getTitle()) ?></legend>
<?php } ?>
<?php
foreach($fieldSet->getControls() as $setControl) {
$controlView = $setControl->getControlView($context);
if (is_object($controlView)) {
$renderer = $controlView->getControlRenderer();
print $renderer->render();
}
}
?>
</fieldset>
<?php } ?>
</div>
属性をカスタマイズ

<?php
namespace TestSite\Attribute\Context;
use Concrete\Core\Attribute\Context\FrontendFormContext as BaseFrontendFormContext;
class FrontendFormContext extends BaseFrontendFormContext
{
}
<?php
namespace TestSite\Express\Form\Context;
use Concrete\Core\Express\Form\Context\FrontendFormContext as CoreFrontendFormContext;
use Concrete\Core\Filesystem\TemplateLocator;
class FrontendFormContext extends CoreFrontendFormContext
{
// Set Attribute Context
public function getAttributeContext()
{
return new \TestSite\Attribute\Context\FrontendFormContext();
}
public function setLocation(TemplateLocator $locator)
{
$locator = parent::setLocation($locator);
$locator->prependLocation([DIRNAME_ELEMENTS .
DIRECTORY_SEPARATOR .
DIRNAME_EXPRESS .
DIRECTORY_SEPARATOR .
DIRNAME_EXPRESS_FORM_CONTROLS .
DIRECTORY_SEPARATOR .
DIRNAME_EXPRESS_FORM_CONTROLS // not a typo
, 'theme_test']);
return $locator;
}
}
属性コンテキストをカスタマイズ
public function __construct()
{
parent::__construct();
$this->preferTemplateIfAvailable('test', 'theme_test');
}
public function setLocation(TemplateLocator $locator)
{
$locator->setTemplate(['test', 'theme_test']);
return $locator;
}
属性フォームテンプレート作成
↓