Skip to content

docs: プラグインフックポイント一覧ドキュメントを追加#1249

Merged
nanasess merged 3 commits intoEC-CUBE:masterfrom
nanasess:feature/add-plugin-hook-points-documentation
Jan 28, 2026
Merged

docs: プラグインフックポイント一覧ドキュメントを追加#1249
nanasess merged 3 commits intoEC-CUBE:masterfrom
nanasess:feature/add-plugin-hook-points-documentation

Conversation

@nanasess
Copy link
Contributor

@nanasess nanasess commented Jun 24, 2025

Summary

EC-CUBE2のプラグイン開発で利用可能なすべてのフックポイントの完全なリファレンスドキュメントを作成しました。

追加内容

  • docs/plugin-hook-points.md - フックポイント一覧の完全なドキュメント
  • docs/README.md - プラグイン開発セクションとリンクを追加

ドキュメントの特徴

  • 網羅性: 省略なしですべてのフックポイントを記載
  • 分類: スーパー、ローカル、特殊フックポイントに分類
  • 実用性: 具体的な使用例とコードサンプルを提供
  • 日本語: 完全日本語対応でわかりやすい説明

含まれる内容

  • スーパーフックポイント(6個): システム全体で実行されるフックポイント
  • ローカルフックポイント(約836個): 各ページクラス別のフックポイント
  • API関連フックポイント(13個): API操作用のフックポイント
  • 特殊フックポイント: 個別実装されたフックポイント
  • 実装例: 基本的・高度な使用例
  • 統計情報: フックポイントの種類と数

Test plan

  • ドキュメントの内容確認
  • リンクの動作確認
  • マークダウン形式の検証
  • 日本語表記の確認

🤖 Generated with Claude Code

Summary by CodeRabbit

ドキュメント

  • ドキュメント
    • プラグイン開発セクションを追加し、フックポイント一覧への参照を含める
    • プラグイン開発者向けの包括的なフックポイントリファレンスを新規作成
    • テーブル定義ドキュメントをデータベーススキーマ情報と更新手順で拡張

✏️ Tip: You can customize this high-level summary in your review settings.

EC-CUBE2のプラグイン開発で利用可能なすべてのフックポイントの完全なリファレンスを作成しました。

- docs/plugin-hook-points.md を新規追加
  - スーパーフックポイント(システム全体)
  - ローカルフックポイント(ページクラス別)
  - API関連フックポイント
  - 特殊なフックポイント
  - 実装例とコードサンプル
  - 統計情報
- docs/README.md にプラグイン開発セクションとリンクを追加

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Jun 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.39%. Comparing base (511d4a7) to head (a3a7788).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1249   +/-   ##
=======================================
  Coverage   54.39%   54.39%           
=======================================
  Files          83       83           
  Lines       10658    10658           
=======================================
  Hits         5797     5797           
  Misses       4861     4861           
Flag Coverage Δ
tests 54.39% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nanasess nanasess enabled auto-merge June 25, 2025 00:34
@nanasess
Copy link
Contributor Author

@coderabbitai レビューお願いします。特に使用例のコードについて検証してください

@coderabbitai
Copy link

coderabbitai bot commented Jan 28, 2026

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get the list of files changed in this PR
gh pr view 1249 --json files --jq '.files[].path'

Length of output: 41


🏁 Script executed:

#!/bin/bash
# Read the main documentation file
cat docs/plugin-hook-points.md

Length of output: 24593


🏁 Script executed:

#!/bin/bash
# Read the README changes
cat docs/README.md

Length of output: 863


🏁 Script executed:

#!/bin/bash
# Search for plugin hook implementation in the codebase to verify the documentation
rg -n "plugin->doAction" -A 2 -B 2 --type=php | head -100

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Check how super hooks are actually implemented in the codebase
rg -n "preProcess.*plugin" -A 3 -B 3 --type=php | head -80

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Find plugin helper class to understand the API
fd -e php -x grep -l "class.*SC_Helper_Plugin" {} \;

Length of output: 100


🏁 Script executed:

#!/bin/bash
# Read the plugin helper implementation to validate the examples
cat data/class/helper/SC_Helper_Plugin.php 2>/dev/null || find . -name "*Plugin*.php" -path "*/helper/*" -exec cat {} \; | head -200

Length of output: 11643


🏁 Script executed:

#!/bin/bash
# Check if SC_Plugin_Base class exists and examine its structure
fd -e php -x grep -l "class.*SC_Plugin_Base" {} \;

Length of output: 233


🏁 Script executed:

#!/bin/bash
# Read the SC_Plugin_Base class to validate the example code structure
find . -name "*Plugin_Base*.php" -exec cat {} \; | head -150

Length of output: 3219


🏁 Script executed:

#!/bin/bash
# Check how hook points are actually triggered in page classes
rg -n "doAction|LC_Page.*action_before|LC_Page.*action_after" --type=php -C 2 | head -150

Length of output: 9830


🏁 Script executed:

#!/bin/bash
# Verify the constants mentioned in the documentation
rg -n "HOOK_POINT_PREPROCESS|HOOK_POINT_PROCESS" --type=php

Length of output: 493


🏁 Script executed:

#!/bin/bash
# Check how page classes implement the action methods
rg -n "class LC_Page_Products_Detail" -A 50 --type=php | head -100

Length of output: 3922


🏁 Script executed:

#!/bin/bash
# Find examples of actual hook point usage in the codebase
rg -n "->doAction\(" --type=php -B 1 -A 1 | head -150

Length of output: 404


🏁 Script executed:

#!/bin/bash
# Check the outputfilterTransform hook implementation
rg -n "outputfilterTransform|prefilterTransform" --type=php -C 3

Length of output: 2413


🏁 Script executed:

#!/bin/bash
# Check the actual signature of action methods in page classes
rg -n "function action\(" --type=php -A 5 | head -100

Length of output: 6824


🏁 Script executed:

#!/bin/bash
# Find how actionExit and sendRedirect trigger hook points
rg -n "actionExit|sendRedirect" --type=php -C 4 | head -150

Length of output: 12746


🏁 Script executed:

#!/bin/bash
# Check SC_Response class for exit and redirect hook points
fd -e php -x grep -l "class.*SC_Response" {} \;

Length of output: 295


🏁 Script executed:

#!/bin/bash
# Read SC_Response to understand exit and redirect hooks
find . -name "*Response*.php" -path "*/class/*" ! -path "*/test*" -exec cat {} \; | head -200

Length of output: 6807


🏁 Script executed:

#!/bin/bash
# Verify the mode-specific hook points implementation in LC_Page
rg -n "action_\$.*mode|action_.*\\\$mode" --type=php -C 3

Length of output: 873


🏁 Script executed:

#!/bin/bash
# Check how dynamic hook points with mode are generated
cat data/class/pages/LC_Page.php | grep -A 20 "function action"

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Check the actual signature of prefilterTransform and outputfilterTransform in test fixtures
cat tests/class/fixtures/plugin/PrefilterTransformPlugin/PrefilterTransformPlugin.php

Length of output: 951


🏁 Script executed:

#!/bin/bash
# Look for real plugin examples in the codebase to verify correct signatures
rg -n "function (prefilterTransform|outputfilterTransform)" --type=php -A 5

Length of output: 784


🏁 Script executed:

#!/bin/bash
# Check what arguments are actually passed to these hooks
rg -n "doAction\('(prefilterTransform|outputfilterTransform)'" --type=php -C 2

Length of output: 783


🏁 Script executed:

#!/bin/bash
# Verify the method signatures in plugin examples work correctly with the actual calls
cat data/class/pages/LC_Page.php | grep -B 5 -A 10 "doAction.*action_before"

Length of output: 634


🏁 Script executed:

#!/bin/bash
# Check SC_View to understand what objSmarty could refer to
cat data/class/SC_View.php | head -100

Length of output: 5217


🏁 Script executed:

#!/bin/bash
# Look for any other plugin examples or documentation in the codebase
fd -t f -e md -e txt | xargs grep -l "plugin" | head -10

Length of output: 238


🏁 Script executed:

#!/bin/bash
# Check if there are any real world examples of outputfilterTransform implementation
rg -n "outputfilterTransform" --type=php -B 2 -A 8

Length of output: 615


🏁 Script executed:

#!/bin/bash
# Verify the API operations inherit pattern
cat data/class/api/operations/CartAdd.php | head -60

Length of output: 1625


🏁 Script executed:

#!/bin/bash
# Check how API operations are called and if they trigger hooks
cat data/class/api/SC_Api_Operation.php | grep -B 5 -A 15 "doAction"

Length of output: 1080


🏁 Script executed:

#!/bin/bash
# Check if API operations have hook points similar to LC_Page
rg -n "class API_" --type=php -A 30 | head -100

Length of output: 7037


🏁 Script executed:

#!/bin/bash
# Look for LC_Page_Api to understand API hook points
fd -e php | xargs grep -l "class LC_Page_Api"

Length of output: 160


🏁 Script executed:

#!/bin/bash
# Read LC_Page_Api to understand API page hooks
cat data/class/pages/api/LC_Page_Api.php | head -100

Length of output: 1603


🏁 Script executed:

#!/bin/bash
# Check if mode-based hooks are actually documented correctly by looking at Shopping_Confirm
rg -n "class LC_Page_Shopping_Confirm" --type=php -A 100 | grep -E "(function action|switch.*mode|case)" | head -30

Length of output: 86


@nanasess レビューが完了しました。ドキュメントの内容は非常に包括的で素晴らしいですが、コード例にいくつかの問題を発見しました。

重大な問題

1. テンプレートフックポイントのメソッドシグネチャが誤っています

高度な使用例の transformOutput メソッド:

public function transformOutput($output, $objSmarty)
{
    // テンプレート出力の変換
    return $output;
}

実際の実装は:

  • outputfilterTransform は3つの引数を受け取ります: &$source, $objPage, $filename
  • 第2引数は $objSmarty ではなく $objPage (LC_Pageオブジェクト)
  • 第1引数は参照渡し(&)である必要があります

正しいシグネチャ:

public function outputfilterTransform(&$source, $objPage, $filename)
{
    // テンプレート出力の変換
    // $source を直接変更する(return不要)
}

これは実際のテストフィクスチャ(tests/class/fixtures/plugin/PrefilterTransformPlugin/PrefilterTransformPlugin.php)でも確認できます。

2. API関連フックポイントのセクションに誤解を招く記述があります

ドキュメントの「API操作クラス」セクションにリストされている以下のクラスは、フックポイントではありません

  • AddrFromZip
  • CartAdd
  • CartGet
  • CartClear
    など

これらは API_* という名前の操作クラスで、doAction() メソッドは直接呼び出されます。プラグインのフックポイントとしては使用できません。

実際のAPIフックポイントは:

  • LC_Page_Api_action_before / LC_Page_Api_action_after
  • LC_Page_Api_Json_action_before / LC_Page_Api_Json_action_after
  • LC_Page_Api_Php_action_before / LC_Page_Api_Php_action_after
  • LC_Page_Api_Xml_action_before / LC_Page_Api_Xml_action_after

これらは他のページクラスと同様に LC_Page を継承しているため、標準的なローカルフックポイントが利用可能です。

修正提案

1. 高度な使用例を修正してください:

<?php
class AdvancedPlugin extends SC_Plugin_Base
{
    public function register($objPluginHelper, $priority)
    {
        // 複数のフックポイント登録
        $hookPoints = [
            'LC_Page_Admin_Order_Edit_action_before' => 'beforeOrderEdit',
            'LC_Page_Admin_Order_Edit_action_after' => 'afterOrderEdit',
            'LC_Page_Shopping_Confirm_action_confirm' => 'onOrderConfirm',
            'outputfilterTransform' => 'transformOutput'
        ];
        
        foreach ($hookPoints as $hookPoint => $method) {
            $objPluginHelper->addAction($hookPoint, [$this, $method], $priority);
        }
    }
    
    public function beforeOrderEdit($objPage)
    {
        // 受注編集前の処理
    }
    
    public function afterOrderEdit($objPage)
    {
        // 受注編集後の処理
    }
    
    public function onOrderConfirm($objPage)
    {
        // 注文確認時の処理
    }
    
    public function transformOutput(&$source, $objPage, $filename)
    {
        // テンプレート出力の変換
        // $sourceを直接変更します(return不要)
        if ($filename === 'shopping/confirm.tpl') {
            $source .= '<!-- カスタム追加コンテンツ -->';
        }
    }
}

2. API関連フックポイントのセクションを書き換えてください:

現在の「API操作クラス」セクションを削除し、以下に置き換えることを推奨:

## API関連フックポイント

### APIページクラス

APIリクエストを処理するページクラスには、他のページクラスと同様にフックポイントが利用可能です。

| クラス名 | 利用可能なフックポイント |
|---------|---------------------|
| `LC_Page_Api` | `LC_Page_Api_action_before`<br>`LC_Page_Api_action_after` |
| `LC_Page_Api_Json` | `LC_Page_Api_Json_action_before`<br>`LC_Page_Api_Json_action_after` |
| `LC_Page_Api_Php` | `LC_Page_Api_Php_action_before`<br>`LC_Page_Api_Php_action_after` |
| `LC_Page_Api_Xml` | `LC_Page_Api_Xml_action_before`<br>`LC_Page_Api_Xml_action_after` |

注意: `API_CartAdd``API_ItemSearch` などの操作クラスは、フックポイントを提供しません。これらは `SC_Api_Operation` によって直接呼び出されます。

その他の所見

以下は正確です:

  • スーパーフックポイントの説明と実装
  • ローカルフックポイント(action_before/action_after)の命名規則
  • モード固有フックポイントの動的生成
  • 基本的な使用例のコード
  • フックポイント登録の方法

統計情報の修正

「API関連クラス: 13個」という記述は、実際のAPIページクラスは4個のみであるため、修正が必要です。

上記の修正を行えば、このドキュメントはEC-CUBE2のプラグイン開発者にとって非常に価値のあるリファレンスになります。

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link

coderabbitai bot commented Jan 28, 2026

📝 Walkthrough

Walkthrough

プラグイン開発向けのドキュメントを追加・拡張しました。docs/README.mdにプラグイン開発セクションとテーブル定義更新手順を追記し、docs/plugin-hook-points.mdを新規作成してEC-CUBE2のフックポイント仕様を網羅的に記載しています。

Changes

コホート / ファイル(s) 変更概要
ドキュメント拡張
docs/README.md
プラグイン開発セクションを追加し、フックポイント参照を導線として追加。テーブル定義セクションにデータベーススキーマへのリンクとPostgreSQL/docker-compose前提、DSN指針、生成・差分コマンド等の更新手順を追記
新規ドキュメント作成
docs/plugin-hook-points.md
EC-CUBE2プラグイン用フックポイントの包括的リファレンスを新規作成。スーパー/グローバル、ページクラス単位、フロント/管理/API、動的フック、命名規則、登録例、応用例、統計などを列挙

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 ドキュメントの野原で跳ねるよ、
フックの道しるべをぴょんと置いて、
テーブルの地図もそっと描く、
開発の朝に光を渡し、
小さな脚で未来を耕すよ ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR タイトルは「docs: プラグインフックポイント一覧ドキュメントを追加」で、追加されたドキュメント(docs/plugin-hook-points.md と docs/README.md の更新)の主な変更内容を的確に要約しており、関連性が高く具体的です。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@docs/plugin-hook-points.md`:
- Around line 443-446: Update the statistics entry that currently reads
"API関連クラス: 13個" to the correct count "API関連クラス: 4個" and, if present, list or
validate the four API page classes LC_Page_Api, LC_Page_Api_Json,
LC_Page_Api_Php, and LC_Page_Api_Xml so the doc reflects the actual classes.
- Around line 318-333: Remove or replace the misleading "API操作クラス" table: delete
the table rows listing AddrFromZip, BrowseNodeLookup, CartAdd, CartClear,
CartCreate, CartGet, CartModify, Default, GetVersion, ItemLookup, ItemSearch
(and any similar API operation classes) and instead add a short note that these
API operation classes are not hook-providing and are "フックポイント対象外"; explicitly
state that API-related hooks are provided only on the LC_Page_Api* side to avoid
confusion.
- Around line 399-437: The example registers an output filter but defines
transformOutput($output, $objSmarty) and returns a value; replace that with the
correct outputfilter signature and behavior: in AdvancedPlugin change the hooked
method name to outputfilterTransform and implement it as
outputfilterTransform(&$source, $objPage, $filename) — edit $source by reference
(no return) — and update the $hookPoints entry ('outputfilterTransform' =>
'outputfilterTransform') so the registered hook matches the method name.

nanasess and others added 2 commits January 28, 2026 09:40
- outputfilterTransformのメソッドシグネチャを実装に合わせて修正
  (&$source, $objPage, $filename)
- API操作クラス(API_CartAdd等)はフックポイントではないため削除
- サンプルコードからSC_Plugin_Base継承を除去(EC-CUBE#551)
- 統計情報のAPIクラス数を修正(13→4)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@nanasess nanasess merged commit b788b2b into EC-CUBE:master Jan 28, 2026
127 checks passed
@nanasess nanasess deleted the feature/add-plugin-hook-points-documentation branch January 28, 2026 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments