mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
68 lines
1.1 KiB
PHP
68 lines
1.1 KiB
PHP
<?php
|
|
|
|
if(!class_exists("Widget")) {
|
|
return;
|
|
}
|
|
|
|
/**
|
|
* @method Blog Blog()
|
|
*/
|
|
class BlogCategoriesWidget extends Widget {
|
|
/**
|
|
* @var string
|
|
*/
|
|
private static $title = 'Categories';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
private static $cmsTitle = 'Blog Categories';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
private static $description = 'Displays a list of blog categories.';
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
private static $db = array();
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
private static $has_one = array(
|
|
'Blog' => 'Blog',
|
|
);
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function getCMSFields() {
|
|
$this->beforeUpdateCMSFields(function ($fields) {
|
|
$fields->push(
|
|
DropdownField::create('BlogID', _t('BlogCategoriesWidget.Blog', 'Blog'), Blog::get()->map())
|
|
);
|
|
});
|
|
|
|
return parent::getCMSFields();
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getCategories() {
|
|
$blog = $this->Blog();
|
|
|
|
if($blog) {
|
|
return $blog->Categories();
|
|
}
|
|
|
|
return array();
|
|
}
|
|
}
|
|
|
|
class BlogCategoriesWidget_Controller extends Widget_Controller {
|
|
|
|
}
|