/**
  * Contructor
  * @param type $controller
  * @param type $name
  */
 function __construct($controller, $name)
 {
     //Administering calendars
     if (CalendarConfig::subpackage_enabled('calendars')) {
         //Configuration for calendar grid field
         $gridCalendarConfig = GridFieldConfig_RecordEditor::create();
         $gridCalendarConfig->removeComponentsByType('GridFieldDataColumns');
         $gridCalendarConfig->addComponent($dataColumns = new GridFieldDataColumns(), 'GridFieldEditButton');
         $c = singleton('Calendar');
         $summaryFields = $c->summaryFields();
         //$summaryFields = array(
         //	'Title' => 'Title',
         //	//'SubscriptionOptIn' => 'Opt In',
         //	//'Shaded' => 'Shaded'
         //);
         $s = CalendarConfig::subpackage_settings('calendars');
         //show shading info in the gridfield
         if ($s['shading']) {
             $summaryFields['Shaded'] = 'Shaded';
         }
         $dataColumns->setDisplayFields($summaryFields);
         //settings for the case that colors are enabled
         if ($s['colors']) {
             $dataColumns->setFieldFormatting(array("Title" => '<div style=\\"height:20px;width:20px;display:inline-block;vertical-align:middle;margin-right:6px;background:$Color\\"></div> $Title'));
         }
         $GridFieldCalendars = new GridField('Calendars', '', PublicCalendar::get(), $gridCalendarConfig);
         $fields = new FieldList($GridFieldCalendars);
         $actions = new FieldList();
         $this->addExtraClass('CalendarsForm');
         parent::__construct($controller, $name, $fields, $actions);
     }
 }
 function getGridFieldSiteTreeField($name, $title = null, SS_List $dataList = null)
 {
     $gf = GridField::create($name, $title, $dataList, $config = GridFieldConfig::create());
     $config->addComponents(new GridFieldSortableHeader(), $columns = new GridFieldDataColumns(), new GridFieldPaginator(15));
     $fields = array('getTreeTitle' => _t('SiteTree.PAGETITLE', 'Page Title'), 'singular_name' => _t('SiteTree.PAGETYPE'), 'LastEdited' => _t('SiteTree.LASTUPDATED', 'Last Updated'));
     $columns->setDisplayFields($fields);
     $columns->setFieldCasting(array('Created' => 'Datetime->Ago', 'LastEdited' => 'Datetime->Ago', 'getTreeTitle' => 'HTMLText'));
     $config->getComponentByType('GridFieldSortableHeader')->setFieldSorting(array('getTreeTitle' => 'Title'));
     $controller = $this;
     $columns->setFieldFormatting(array('getTreeTitle' => function ($value, &$item) use($controller) {
         return '<a class="action-detail" href="' . singleton('CMSPageEditController')->Link('show') . '/' . $item->ID . '">' . $item->TreeTitle . '</a>';
     }));
     return $gf;
 }
 /**
  *
  * @param int $itemsPerPage - How many items per page should show up
  */
 public function __construct($itemsPerPage = null, $currentStage = 'Latest')
 {
     $this->addComponent(new PublishableGridFieldStage($currentStage));
     $this->addComponent(new GridFieldButtonRow('before'));
     $this->addComponent(new GridFieldAddNewButton('buttons-before-left'));
     $this->addComponent(new GridFieldToolbarHeader());
     $this->addComponent($sort = new GridFieldSortableHeader());
     $this->addComponent($filter = new GridFieldFilterHeader());
     $this->addComponent($columns = new GridFieldDataColumns());
     $this->addComponent(new PublishableGridFieldDeleteAction());
     $this->addComponent(new PublishableGridFieldPublishAction());
     $this->addComponent(new PublishableGridFieldEditButton());
     $this->addComponent(new GridFieldPageCount('toolbar-header-right'));
     $this->addComponent($pagination = new GridFieldPaginator($itemsPerPage));
     $this->addComponent(new PublishableGridFieldDetailForm());
     $sort->setThrowExceptionOnBadDataType(false);
     $filter->setThrowExceptionOnBadDataType(false);
     $pagination->setThrowExceptionOnBadDataType(false);
     $columns->setFieldFormatting(array('Title' => function ($value, &$item) {
         $badge = array();
         if ($item->ExistsOnLive && $item->IsModifiedOnStage) {
             $badge['class'] = 'modified';
             $badge['title'] = _t('PublishableGridFieldStatusColumns.ModifiedStage', 'Modified');
         } elseif ($item->IsAddedToStage) {
             $badge['class'] = 'addedtodraft';
             $badge['title'] = _t('PublishableGridFieldStatusColumns.Stage', 'Draft');
         }
         $return = $item->Title;
         if (isset($badge['class']) && isset($badge['title'])) {
             $return .= sprintf("<span class=\"badge %s\">%s</span>", 'status-' . Convert::raw2xml($badge['class']), Convert::raw2xml($badge['title']));
         }
         return $return;
     }));
 }