123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- /**
- * Main Linkage object setup.
- *
- * Sets up the main Linkage object and create editable fields in the CMS.
- *
- * @author S.Dwayne Pivac, OMI Ltd.
- *
- */
- class Linkage extends DataObject
- {
- private static $db = array(
- 'Title' => 'Text',
- 'URL' => 'Text',
- 'External' => 'Boolean',
- 'Sorder' => 'Varchar',
- );
- private static $summary_fields = array('HTMLDescription');
- static $singular_name = 'Link';
- static $plural_name = 'Links';
- public static $default_sort = 'Sorder ASC';
- function fieldLabels($includerelations = true)
- {
- $labels = parent::fieldLabels($includerelations);
- $labels['HTMLDescription'] = 'Links';
- return $labels;
- }
- private static $casting = array('HTMLDescription' => 'HTMLText');
- function HTMLDescription()
- {
- return $this->getHTMLDescription();
- }
- public function getHTMLDescription()
- {
- $ShowExt = 'self';
- if ($this->External) {
- $ShowExt = 'blank';
- }
- $data = new ArrayData(array(
- 'ID' => $this->ID,
- 'Title' => $this->Title,
- 'URL' => $this->URL,
- 'ShowExt' => $ShowExt,
- ));
- $output = HTMLText::create();
- $output->setValue($data->renderWith('Links'));
- return $output;
- }
- public function getCMSfields(){
- $f=FieldList::create(TabSet::create('Root'));
- $f->addFieldToTab('Root.Main', TextField::create('Title', 'Link/button name'));
- $f->addFieldToTab('Root.Main', TextField::create('URL', 'URL/Link'));
- $f->addFieldToTab('Root.Main', CheckboxField::create('External', 'External linkage?')->setDescription('Open in a new window?'));
- $f->addFieldToTab('Root.Main', TextField::create('Sorder', 'Sort Order')->setDescription('Links are sorted by this field using alphanumeric sorting. You can use numbers or letters.'));
- return $f;
- }
- }
- /**
- * Create Linkage menu.
- *
- * Create the Linkage link on the 'Left' hand side of the ModelAdmin.
- *
- * @author S.Dwayne Pivac, OMI Ltd.
- *
- */
- class LinkageAdmin extends ModelAdmin
- {
- private static $menu_title = 'Linkage';
- private static $url_segment = 'linkage';
- private static $managed_models = array('Linkage');
- private static $menu_icon = 'linkage/img/linkage.gif';
- private static $page_length = 50;
- private static $menu_priority = 110;#2Do: can this be configurable?
- private static $url_priority = 30;
- public function init()
- {
- parent::init();
- Requirements::css('linkage/css/linkage.css');
- }
- public function getEditForm($id=null, $fields=null)
- {
- $gridFieldTitle = 'Your Linkage';
- $listField=GridField::create(
- $this->sanitiseClassName($this->modelClass), $gridFieldTitle, $this->getList(),
- $fieldConfig=GridFieldConfig_RecordViewer::create($this->stat('page_length'))
- ->removeComponentsByType('GridFieldPageCount')
- ->removeComponentsByType('GridFieldPaginator')
- ->removeComponentsByType('GridFieldSortableHeader')
- ->removeComponentsByType('GridFieldViewButton')
- ->removeComponentsByType('GridFieldToolbarHeader')
- ->addComponent(new GridFieldEditLinkage())
- ->addComponent(new GridFieldAddNewButton())
- );
- return CMSForm::create(
- $this,
- 'EditForm',
- new FieldList($listField),
- new FieldList()
- )->setHTMLID('Form_EditForm')->addExtraClass('cms-edit-form cms-panel-padded center');
- }
- }
- /**
- * Linkage Edit Buttons.
- *
- * Custom Edit Buttons to avoid the default behaviour of linking via the GridField.
- *
- * @author S.Dwayne Pivac, OMI Ltd.
- *
- */
- class GridFieldEditLinkage implements GridField_ColumnProvider
- {
- public function augmentColumns($gridField, &$columns) {
- if(!in_array('Actions', $columns)) {
- $columns[] = 'Actions';
- }
- }
- public function getColumnAttributes($gridField, $record, $columnName) {
- return array('class' => 'col-buttons');
- }
- public function getColumnMetadata($gridField, $columnName) {
- if($columnName == 'Actions') {
- return array('title' => '');
- }
- }
- public function getColumnsHandled($gridField) {
- return array('Actions');
- }
- public function getColumnContent($gridField, $record, $columnName) {
- $data = new ArrayData(array(
- 'Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'edit')
- ));
- return $data->renderWith('LinkageEditButton');
- }
- }
- #~/linkage/code/Linkage.php
|