教文館の社内ナレッジベースです。

EC-CUBE3でページ管理から画面作成時にURLからuser_dataを無くす方法。当たり前です。この場合userって 「Lockon」さんから見たユーザーですね。ショップにあると紛らわしいので削除。

 

削除手順

まず、FrontControllerProviderにあるuser_dataを定義しているルーティングの箇所をコメントアウトします。

src/Eccube/ControllerProvider/FrontControllerProvider.php.php

// user定義
// $c->match('/'.$app['config']['user_data_route'].'/{route}', '\Eccube\Controller\UserDataController::index')->assert('route', '([0-9a-zA-Z_\-]+\/?)+(?<!\/)')->bind('user_data');

ページ作成時にuser_dataの定義がなくても動作するように、PageControllerとPageLayoutRepositoryを修正します。

src/Eccube/Controller/Admin/Content/PageController.php

・120行目
// ファイル生成・更新
$templatePath = $app['eccube.repository.page_layout']->getWriteTemplatePath($editable);
↓
$templatePath = $app['eccube.repository.page_layout']->getWriteTemplatePath(false);


・156行目
$templatePath = $app['eccube.repository.page_layout']->getWriteTemplatePath($editable);
↓
$templatePath = $app['eccube.repository.page_layout']->getWriteTemplatePath(false);


・187行目
$templatePath = $app['eccube.repository.page_layout']->getWriteTemplatePath(true);
↓
$templatePath = $app['eccube.repository.page_layout']->getWriteTemplatePath(false);

というようにそれぞれ$app[‘eccube.repository.page_layout’]->getWriteTemplatePath(false);と変更します。

src/Eccube/Repository/PageLayoutRepository.php

public function getReadTemplateFile($fileName, $isUser = false)
{
if ($isUser) {
$readPaths = array(
$this->app['config']['user_data_realdir'],
);
} else {
$readPaths = array(
$this->app['config']['template_realdir'],
$this->app['config']['template_default_realdir'],
);
}
・
・
・

と記述されている箇所を

public function getReadTemplateFile($fileName, $isUser = false)
{
if ($isUser) {
$readPaths = array(
$this->app['config']['template_realdir'],
$this->app['config']['user_data_realdir'],
);
} else {
$readPaths = array(
$this->app['config']['template_realdir'],
$this->app['config']['template_default_realdir'],
);
}
・
・
・

と$this->app[‘config’][‘template_realdir’],を263行目に追加します。

また、管理画面でのURL表記を変更するため、page_edit.twigも修正します。

app/template/admin/Content/page_edit.twig

・59行目
{{ url('top') }}{{ app.config.user_data_route }}/{{ form_widget(form.url) }}
↓
{{ url('homepage') }}{{ form_widget(form.url) }}

こちらはuser_dataを表示上からなくしているだけです。

ここまで対応すればほぼ完了なのですが、FrontControllerProviderからuser_dataへルーティング定義を削除してしまったため、新たに定義してあげる必要があります。どこに定義するのかというと、index.phpで定義してあげます。

html/index.php

// インストールされてなければインストーラにリダイレクト
if (isset($app['config']['eccube_install']) && $app['config']['eccube_install']) {
$app->initialize();
$app->initializePlugin();
if ($app['config']['http_cache']['enabled']) {
$app['http_cache']->run();
} else {
$app->run();
}
} else {
・
・
・

と記載されている箇所を

/

/ インストールされてなければインストーラにリダイレクト
if (isset($app['config']['eccube_install']) && $app['config']['eccube_install']) {
$app->initialize();
$app->initializePlugin();

// ページレイアウトのカスタマイズに伴う修正
$front = $app['controllers_factory'];
// 強制SSL
if ($app['config']['force_ssl'] == \Eccube\Common\Constant::ENABLED) {
$front->requireHttps();
}

$front->match('/{route}', '\Eccube\Controller\UserDataController::index')->assert('route', '([0-9a-zA-Z_\-]+\/?)+(?<!\/)')->bind('user_data');
$app->mount('', $front);

if ($app['config']['http_cache']['enabled']) {
$app['http_cache']->run();
} else {
$app->run();
}
} else {
・
・
・

 

というように新たにuser_data用のルーティング定義を行います。

以上の作業を行うことで、ページ管理から新たなページを作成した場合、URLにはuser_dataはなくなります。

(コアコードカスタマイズ指針より)

画面の作成、URLについて

新規ページを作成する際、静的ページの場合は、ページ管理機能を利用し、作成します。

ロジックが必要な場合は、新規ページの追加を参考に、

Controllerの作成
twigテンプレートの作成
ルーティング定義の追加

を行います。

既存ページのURLの変更や、無効化を行う場合は、利用しないページの無効化を参考に、既存のルーティングに対して設定を行います。
Formの拡張