Forum\Helper\BreadcrumbHelper::getBreadcrumbs PHP Method

getBreadcrumbs() public static method

getBreadcrumbs
public static getBreadcrumbs ( string $paths ) : Windwalker\Data\Data[]
$paths string
return Windwalker\Data\Data[]
    public static function getBreadcrumbs($paths)
    {
        if (!$paths) {
            return array();
        }
        $paths = explode('/', $paths);
        $record = new CategoryRecord();
        $breadcrumbs = array();
        foreach (range(1, count($paths)) as $i) {
            $item = new Data();
            $item->path = implode('/', $paths);
            $item->link = Router::html('forum:category', array('path' => $paths));
            $record->load(array('path' => $item->path));
            $item->title = $record->title;
            $breadcrumbs[] = $item;
            array_pop($paths);
        }
        $breadcrumbs[] = new Data(array('title' => 'Home', 'path' => '', 'link' => Router::html('forum:home')));
        $breadcrumbs = array_reverse($breadcrumbs);
        return $breadcrumbs;
    }

Usage Example

Example #1
0
 /**
  * prepareData
  *
  * @param \Windwalker\Data\Data $data
  *
  * @return  void
  */
 protected function prepareData($data)
 {
     $paths = $data->currentCategory->path;
     $data->breadcrumbs = BreadcrumbHelper::getBreadcrumbs($paths);
     if ($data->currentCategory->id != 1) {
         $this->setTitle($data->currentCategory->title);
     }
     // Prepare format
     foreach ($data->categories as $category) {
         $category->last_post->user_params = new Registry($category->last_post->user_params);
     }
     foreach ($data->topics as $topic) {
         $topic->last_user_params = new Registry($topic->last_user_params);
     }
     $user = User::get();
     $data->isWatch = Notification::getNotification('category', $data->currentCategory->id, $user->id)->notNull();
     if ($data->currentCategory->id != 1) {
         $desc = $data->currentCategory->description;
         $desc = Utf8String::substr(strip_tags($desc), 0, 150);
         HtmlHeader::addMetadata('description', $desc, true);
         HtmlHeader::addOpenGraph('og:title', HtmlHeader::getPageTitle(), true);
         HtmlHeader::addOpenGraph('og:description', $desc, true);
         HtmlHeader::addOpenGraph('og:image', $data->currentCategory->image, true);
     }
 }
All Usage Examples Of Forum\Helper\BreadcrumbHelper::getBreadcrumbs
BreadcrumbHelper