silverstripe-blog/code/widgets/BlogCategoriesWidget.php

68 lines
1.1 KiB
PHP
Raw Normal View History

2013-08-04 18:38:26 +02:00
<?php
2015-05-09 16:33:12 +02:00
if(!class_exists("Widget")) {
return;
}
2013-08-04 18:38:26 +02:00
2015-05-09 16:33:12 +02:00
/**
* @method Blog Blog()
*/
class BlogCategoriesWidget extends Widget {
/**
* @var string
*/
private static $title = 'Categories';
2013-08-04 18:38:26 +02:00
2015-05-09 16:33:12 +02:00
/**
* @var string
*/
private static $cmsTitle = 'Blog Categories';
2013-08-04 18:38:26 +02:00
2015-05-09 16:33:12 +02:00
/**
* @var string
*/
private static $description = 'Displays a list of blog categories.';
2013-08-04 18:38:26 +02:00
2015-05-09 16:33:12 +02:00
/**
* @var array
*/
private static $db = array();
2013-08-04 18:38:26 +02:00
2015-05-09 16:33:12 +02:00
/**
* @var array
*/
private static $has_one = array(
'Blog' => 'Blog',
);
2013-10-10 00:09:28 +02:00
2015-05-09 16:33:12 +02:00
/**
* {@inheritdoc}
*/
public function getCMSFields() {
$this->beforeUpdateCMSFields(function ($fields) {
$fields->push(
DropdownField::create('BlogID', _t('BlogCategoriesWidget.Blog', 'Blog'), Blog::get()->map())
);
});
return parent::getCMSFields();
}
2013-08-04 18:38:26 +02:00
2015-05-09 16:33:12 +02:00
/**
* @return array
*/
public function getCategories() {
$blog = $this->Blog();
if($blog) {
return $blog->Categories();
2013-08-04 18:38:26 +02:00
}
2013-10-10 00:09:28 +02:00
2015-05-09 16:33:12 +02:00
return array();
2013-08-04 18:38:26 +02:00
}
2015-05-09 16:33:12 +02:00
}
2013-08-04 18:38:26 +02:00
2015-05-09 16:33:12 +02:00
class BlogCategoriesWidget_Controller extends Widget_Controller {
2013-08-04 18:38:26 +02:00
2013-10-10 00:09:28 +02:00
}