Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

コンテンツネームをWordPress風に取得する関数を追加 #230

Closed

Conversation

fuchigam1
Copy link
Collaborator

要望が出ていた機能を作成してみました。
WordPress の body_class() 風に文字列を取得できる仕組みです。
レビュー、可能であれば取込んでいただけるとうれしいです。
よろしくお願いします。

@n1215
Copy link
Contributor

n1215 commented Dec 20, 2014

機能としてはぜひ欲しいですね。

しかし、コアプラグインとはいえ、特定のプラグイン用のコードが本体を侵食する形になるので、プラグインとコアが密結合してしまうあまりよろしくない実装です。

$bodyClassはページごと(≒アクションごと)に多様性を持つパラメータですので、それぞれのコントローラのアクションに設定処理を記述して、ビュー変数にセットし、(わかりやすいインターフェースが必要であれば)ヘルパーによって値を取り出すという方式のほうが自然に思えます。(継承や何らかの規約等を利用して)ポリモーフィズムで実装できるほうがよりオブジェクト指向的でしょう。もしブログプラグイン特有の出力内容ならブログプラグインが責任を持つべきです。江頭さんが取り組んでいらっしゃるコンテンツ全体の管理機能との兼ね合いもあるので慎重に実装方法を決めたほうがいいと思います。
既存のBcBaserHelper::getContentsName()もHelperの領域に処理の実態があるのはどうかなという感じですね。

ついでに、各classの文字列をスペースで区切るというのはデータ構造の本質ではなくビューの領域なので、配列使ったほうが綺麗に書けます。

//前略
if($options['underscore']) {
    $separator = '_';
} else {
    $separator = '-';
}
$bodyClass = array();
if($this->isHome()) {
    $bodyClass[] = 'home';
    $bodyClass[] = 'page';
    $bodyClass[] = "page{$separator}home";
//中略
return implode(' ', $bodyClass);

@fuchigam1
Copy link
Collaborator Author

レビュー本当にありがとうございます。嬉しいです!
ご指摘ほんと勉強になります。
このリクエストはクローズしてコアの動向をうかがうことにします。
書き方のご指南までありがとうございます!

@fuchigam1 fuchigam1 closed this Dec 20, 2014
@fuchigam1 fuchigam1 deleted the custom-get_content_name branch December 21, 2014 12:14
@gondoh gondoh added this to the etc milestone Aug 13, 2019
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.

None yet

3 participants