BcBaserHelper::getTitle PHP Method

getTitle() public method

ページタイトルと直属のカテゴリ名が同じ場合は、ページ名を省略する version 3.0.10 より第2引数 $categoryTitleOn は、 $options にまとめられました。 後方互換のために第2引数に配列型以外を指定された場合は、 $categoryTitleOn として取り扱います。
public getTitle ( string $separator = '|', array $options = [] ) : string
$separator string 区切り文字
$options array `categoryTitleOn` カテゴリタイトルを表示するかどうか boolean で指定 (初期値 : null) `tag` (boolean) false でタグを削除するかどうか (初期値 : true) `allowableTags` tagが falseの場合、削除しないタグを指定できる。詳しくは、php strip_tags のドキュメントを参考してください。 (初期値 : '')
return string メタタグ用のタイトルを返す
    public function getTitle($separator = '|', $options = array())
    {
        if (!is_array($options)) {
            $categoryTitleOn = $options;
            unset($options);
            $options['categoryTitleOn'] = $categoryTitleOn;
        }
        $options = array_merge(array('categoryTitleOn' => null, 'tag' => true, 'allowableTags' => ''), $options);
        $title = array();
        if ($this->isHome()) {
            $homeTitle = $this->_View->get('homeTitle');
            if ($homeTitle) {
                if (!$options['tag']) {
                    $title[] = strip_tags($homeTitle, $options['allowableTags']);
                } else {
                    $title[] = $homeTitle;
                }
            }
        } else {
            $crumbs = $this->getCrumbs($options['categoryTitleOn']);
            if ($crumbs) {
                $crumbs = array_reverse($crumbs);
                foreach ($crumbs as $key => $crumb) {
                    if ($this->BcArray->first($crumbs, $key) && isset($crumbs[$key + 1])) {
                        if ($crumbs[$key + 1]['name'] == $crumb['name']) {
                            continue;
                        }
                    }
                    if (!$options['tag']) {
                        $title[] = strip_tags($crumb['name'], $options['allowableTags']);
                    } else {
                        $title[] = $crumb['name'];
                    }
                }
            }
        }
        // サイトタイトルを追加
        $siteName = '';
        if (!empty($this->request->params['Site']['title'])) {
            $siteName = $this->request->params['Site']['title'];
        } elseif (!empty($this->siteConfig['name'])) {
            $siteName = $this->siteConfig['name'];
        }
        if ($siteName) {
            if (!$options['tag']) {
                $title[] = strip_tags($siteName, $options['allowableTags']);
            } else {
                $title[] = $siteName;
            }
        }
        return implode($separator, $title);
    }