mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Merge branch 'master' into patch-1
This commit is contained in:
commit
1dcffe6815
@ -19,6 +19,8 @@ class GridFieldAddNewMultiClass implements GridField_HTMLProvider, GridField_URL
|
||||
private $title;
|
||||
|
||||
private $classes;
|
||||
|
||||
private $defaultClass;
|
||||
|
||||
/**
|
||||
* @var String
|
||||
@ -112,11 +114,23 @@ class GridFieldAddNewMultiClass implements GridField_HTMLProvider, GridField_URL
|
||||
* @param array $classes a set of class names, optionally mapped to titles
|
||||
* @return GridFieldAddNewMultiClass $this
|
||||
*/
|
||||
public function setClasses(array $classes) {
|
||||
public function setClasses(array $classes, $default = null) {
|
||||
$this->classes = $classes;
|
||||
if($default) $this->defaultClass = $default;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default class that is selected automatically.
|
||||
*
|
||||
* @param string $default the class name to use as default
|
||||
* @return GridFieldAddNewMultiClass $this
|
||||
*/
|
||||
public function setDefaultClass($default) {
|
||||
$this->defaultClass = $default;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles adding a new instance of a selected class.
|
||||
*
|
||||
@ -157,7 +171,7 @@ class GridFieldAddNewMultiClass implements GridField_HTMLProvider, GridField_URL
|
||||
|
||||
GridFieldExtensions::include_requirements();
|
||||
|
||||
$field = new DropdownField(sprintf('%s[ClassName]', __CLASS__), '', $classes);
|
||||
$field = new DropdownField(sprintf('%s[ClassName]', __CLASS__), '', $classes, $this->defaultClass);
|
||||
if (Config::inst()->get('GridFieldAddNewMultiClass', 'showEmptyString')) {
|
||||
$field->setEmptyString(_t('GridFieldExtensions.SELECTTYPETOCREATE', '(Select type to create)'));
|
||||
}
|
||||
|
68
code/GridFieldExternalLink.php
Normal file
68
code/GridFieldExternalLink.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Displays a link to an external source referenced 'external link'
|
||||
*/
|
||||
class GridFieldExternalLink extends GridFieldDataColumns {
|
||||
|
||||
/**
|
||||
* Add a column for the actions
|
||||
*
|
||||
* @param type $gridField
|
||||
* @param array $columns
|
||||
*/
|
||||
public function augmentColumns($gridField, &$columns) {
|
||||
if(!in_array('Actions', $columns)) $columns[] = 'Actions';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return any special attributes that will be used for FormField::create_tag()
|
||||
*
|
||||
* @param GridField $gridField
|
||||
* @param DataObject $record
|
||||
* @param string $columnName
|
||||
* @return array
|
||||
*/
|
||||
public function getColumnAttributes($gridField, $record, $columnName) {
|
||||
return array('class' => 'col-buttons');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the title
|
||||
*
|
||||
* @param GridField $gridField
|
||||
* @param string $columnName
|
||||
* @return array
|
||||
*/
|
||||
public function getColumnMetadata($gridField, $columnName) {
|
||||
if($columnName == 'Actions') {
|
||||
return array('title' => '');
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Which columns are handled by this component
|
||||
*
|
||||
* @param type $gridField
|
||||
* @return type
|
||||
*/
|
||||
public function getColumnsHandled($gridField) {
|
||||
return array('Actions');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GridField $gridField
|
||||
* @param DataObject $record
|
||||
* @param string $columnName
|
||||
*
|
||||
* @return string - the HTML for the column
|
||||
*/
|
||||
public function getColumnContent($gridField, $record, $columnName) {
|
||||
$data = new ArrayData(array(
|
||||
'Link' => $record->hasMethod('getExternalLink') ? $record->getExternalLink() : $record->ExternalLink,
|
||||
'Text' => $record->hasMethod('getExternalLinkText') ? $record->getExternalLinkText() : 'External Link'
|
||||
));
|
||||
|
||||
return $data->renderWith('GridFieldExternalLink');
|
||||
}
|
||||
}
|
@ -199,6 +199,10 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
|
||||
/**
|
||||
* Handles requests to reorder a set of IDs in a specific order.
|
||||
*
|
||||
* @param GridField $grid
|
||||
* @param SS_HTTPRequest $request
|
||||
* @return SS_HTTPResponse
|
||||
*/
|
||||
public function handleReorder($grid, $request) {
|
||||
$list = $grid->getList();
|
||||
@ -234,6 +238,12 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
$this->httpError(404);
|
||||
}
|
||||
|
||||
// Save any un-comitted changes to the gridfield
|
||||
if(($form = $grid->getForm()) && ($record = $form->getRecord()) ) {
|
||||
$form->loadDataFrom($request->requestVars(), true);
|
||||
$grid->saveInto($record);
|
||||
}
|
||||
|
||||
// Populate each object we are sorting with a sort value.
|
||||
$this->populateSortValues($items);
|
||||
|
||||
|
1
templates/GridFieldExternalLink.ss
Normal file
1
templates/GridFieldExternalLink.ss
Normal file
@ -0,0 +1 @@
|
||||
<a href="$Link" target="_blank" title="$Text">$Text</a>
|
Loading…
Reference in New Issue
Block a user