Example #1
0
 /**
  * @param string $sortField - Field to sort the blocks on. If this is set, it will also make the
  * 	blocks sortable in the CMS (requires SortableGridField module!)
  * @param array $allowedBlocks - a set of allowed class names, optionally mapped to titles
  * @param int $itemsPerPage - How many items per page should show up
  */
 public function __construct($sortField = null, $allowedBlocks = null, $itemsPerPage = null)
 {
     parent::__construct($itemsPerPage);
     // setup a bulk manager for block management
     $bulkManager = new GridFieldBulkManager();
     // remove the default actions
     $toRemove = array('bulkedit', 'bulkEdit', 'delete', 'unlink', 'unLink');
     $validActions = array_keys($bulkManager->getConfig('actions'));
     foreach ($toRemove as $key) {
         if (in_array($key, $validActions)) {
             $bulkManager->removeBulkAction($key);
         }
     }
     // add the actions in desired order
     $bulkManager->addBulkAction('publish', _t('PageBlock.PUBLISH', 'Publish'))->addBulkAction('unpublish', _t('PageBlock.UNPUBLISH', 'Unpublish'))->addBulkAction('bulkedit', _t('PageBlock.EDIT', 'Edit'), 'GridFieldBulkActionEditHandler', array('icon' => 'pencil'))->addBulkAction('versionedunlink', _t('PageBlock.UNLINK', 'Unlink'), 'GridFieldBulkActionVersionedUnlinkHandler', array('icon' => 'chain--minus'))->addBulkAction('versioneddelete', _t('PageBlock.DELETE', 'Delete'), 'GridFieldBulkActionVersionedDeleteHandler', array('isDestructive' => true, 'icon' => 'decline'));
     if ($sortField && class_exists('GridFieldOrderableRows')) {
         $this->addComponent(new GridFieldOrderableRows($sortField));
     }
     // remove the delete action, since unlinking is not required
     $this->removeComponent($this->getComponentByType('GridFieldDeleteAction'));
     // remove the search field since it doesn't make sense (cannot add existing, unless "stealing" from another page)
     $this->removeComponentsByType('GridFieldAddExistingAutocompleter');
     $this->addComponent(new GridFieldAddExistingSearchButton('buttons-before-right'));
     $this->addComponent(new GridFieldAddNewMultiClass(), 'GridFieldToolbarHeader');
     $this->addComponent($bulkManager);
     $this->getComponentByType('GridFieldDataColumns')->setDisplayFields(array('Title' => _t('Block.TITLE', 'Title'), 'i18n_singular_name' => _t('Block.TYPE', 'Type'), 'PublishedStatus' => _t('Block.STATUS', 'Status')));
     $this->setAllowedBlocks($allowedBlocks);
 }