Skip to content

固定ページ・ブログ記事 afterAddイベント追加#4312

Merged
ryuring merged 1 commit intobaserproject:5.2.xfrom
seto1:add-event
Feb 23, 2026
Merged

固定ページ・ブログ記事 afterAddイベント追加#4312
ryuring merged 1 commit intobaserproject:5.2.xfrom
seto1:add-event

Conversation

@seto1
Copy link
Collaborator

@seto1 seto1 commented Feb 9, 2026

Copilot AI review requested due to automatic review settings February 9, 2026 08:50
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

API 管理画面の「固定ページ追加」「ブログ記事追加」処理でも、追加完了後に afterAdd イベントが発火するようにして、管理画面(非API)とイベント挙動を揃える PR です。

Changes:

  • API の BlogPostsController の add() 成功時に afterAdd イベントを追加
  • API の PagesController の add() 成功時に afterAdd イベントを追加

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
plugins/bc-blog/src/Controller/Api/Admin/BlogPostsController.php ブログ記事追加 API の成功時に afterAdd イベントを発火
plugins/baser-core/src/Controller/Api/Admin/PagesController.php 固定ページ追加 API の成功時に afterAdd イベントを発火

$blogPost = $service->create($this->request->getData());
$message = __d('baser_core', '記事「{0}」を追加しました。', $blogPost->title);
$this->BcMessage->setSuccess($message, true, false);
// EVENT BlogPosts.afterAdd
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

コメント上は「BlogPosts.afterAdd」と記載されていますが、実際の呼び出しは dispatchLayerEvent('afterAdd', ...) になっています。dispatchLayerEvent() が内部で BlogPosts. を付与する仕様でない場合、コメントと実際に発火するイベント名がズレて誤解を招くので、(1) 実際に発火するイベント名にコメントを合わせる、または (2) プロジェクトの慣例に合わせて発火側のイベント名指定を修正する、のどちらかに統一すると良いです。あわせて、リスナー側が期待するペイロード(例: data キー)であることがわかる一言があると保守しやすいです。

Suggested change
// EVENT BlogPosts.afterAdd
// EVENT afterAdd (payload: ['data' => $blogPost])

Copilot uses AI. Check for mistakes.
Comment on lines +103 to +106
// EVENT Pages.afterAdd
$this->dispatchLayerEvent('afterAdd', [
'data' => $page,
]);
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

同様の afterAdd 発火コードが Pages / BlogPosts の両方に追加されており、今後イベント名やペイロード構造を変更したくなった場合に差分が生まれやすいです。API 管理系の共通基底(または trait / ヘルパーメソッド)に「追加完了イベント発火」を集約するか、少なくともイベント名(afterAdd)とペイロードキー(data)を定数化して、タイポや実装差異が入りにくい形に寄せるのを検討してください。

Copilot uses AI. Check for mistakes.
@ryuring
Copy link
Collaborator

ryuring commented Feb 23, 2026

@seto1 ありがとうございます。マージします。

@ryuring ryuring merged commit ee69f03 into baserproject:5.2.x Feb 23, 2026
0 of 3 checks passed
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.

3 participants