PagesController::admin_edit PHP Method

admin_edit() public method

[ADMIN] 固定ページ情報編集
public admin_edit ( integer $id ) : void
$id integer (page_id)
return void
    public function admin_edit($id)
    {
        if (!$id && empty($this->request->data)) {
            $this->setMessage('無効なIDです。', true);
            $this->redirect(['action' => 'index']);
        }
        if (empty($this->request->data)) {
            $this->request->data = $this->Page->read(null, $id);
        } else {
            $isChangedStatus = $this->Content->isChangedStatus($id, $this->request->data);
            if (empty($this->request->data['Page']['page_type'])) {
                $this->request->data['Page']['page_type'] = 1;
            }
            // EVENT Pages.beforeEdit
            $event = $this->dispatchEvent('beforeEdit', ['data' => $this->request->data]);
            if ($event !== false) {
                $this->request->data = $event->result === true ? $event->data['data'] : $event->result;
            }
            $this->Page->set($this->request->data);
            if ($data = $this->Page->save()) {
                // タイトル、URL、公開状態が更新された場合、全てビューキャッシュを削除する
                if ($isChangedStatus) {
                    clearViewCache();
                } else {
                    clearViewCache($this->request->data['Content']['url']);
                }
                // 完了メッセージ
                $this->setMessage('固定ページ「' . $this->request->data['Content']['name'] . '」を更新しました。', false, true);
                // EVENT Pages.afterEdit
                $this->dispatchEvent('afterEdit', ['data' => $data]);
                // 同固定ページへリダイレクト
                $this->redirect(['action' => 'edit', $id]);
            } else {
                $this->setMessage('入力エラーです。内容を修正してください。', true);
            }
        }
        // 公開リンク
        $publishLink = '';
        if ($this->request->data['Content']['url']) {
            $publishLink = $this->request->data['Content']['url'];
        }
        // エディタオプション
        $editorOptions = ['editorDisableDraft' => false];
        if (!empty($this->siteConfigs['editor_styles'])) {
            App::uses('CKEditorStyleParser', 'Vendor');
            $CKEditorStyleParser = new CKEditorStyleParser();
            $editorOptions = array_merge($editorOptions, ['editorStylesSet' => 'default', 'editorStyles' => ['default' => $CKEditorStyleParser->parse($this->siteConfigs['editor_styles'])]]);
        }
        // ページテンプレートリスト
        $pageTemplateList = $this->Page->getPageTemplateList($this->request->data['Content']['id'], $this->siteConfigs['theme']);
        $this->set(compact('editorOptions', 'pageTemplateList', 'publishLink'));
        if (!empty($this->request->data['Content']['title'])) {
            $this->pageTitle = '固定ページ情報編集:' . $this->request->data['Content']['title'];
        } else {
            $this->pageTitle = '固定ページ情報編集:' . Inflector::Classify($this->request->data['Content']['name']);
        }
        $this->help = 'pages_form';
        $this->render('form');
    }