Source of file GridBuilder.php
Size: 3,217 Bytes - Last Modified: 2021-12-24T06:49:04+00:00
/var/www/docs.ssmods.com/process/src/code/Helpers/GridBuilder.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 | <?php class GridBuilder { private $gridConfig; public function getGridConfig() { return $this->gridConfig; } public function setGridConfig($gridConfig) { $this->gridConfig = $gridConfig; return $this; } // Make constructor private to for creation via on of the static create* methods private function __construct() { } /** * Create a grid builder with a default GridFieldConfig * @return \self */ public static function create() { $result = new self(); $result->gridConfig = GridFieldConfig::create(); return $result; } /** * Create a grid builder with a default GridFieldConfig_RelationEditor * * <p> * Allows to search for existing records to add to the relationship, detach * listed records from the relationship (rather than removing them from the * database), and automatically add newly created records to it. * </p> * * @return \self */ public static function createRelation() { $result = new self(); $result->gridConfig = GridFieldConfig_RelationEditor::create() ->addComponent(new GridFieldAddExistingSearchButton()) ->removeComponentsByType('GridFieldAddExistingAutocompleter'); return $result; } /** * Create a grid builder with a default GridFieldConfig_RelationEditor * * <p> * Allows drag and drop sorting of grid rows * </p> * * <p> * Allows to search for existing records to add to the relationship, detach * listed records from the relationship (rather than removing them from the * database), and automatically add newly created records to it. * </p> * * @return \self */ public static function createRelationSortableGrid($sortField = "Sort") { $result = self::createRelation(); $result->gridConfig ->addComponent(GridFieldOrderableRows::create($sortField)); return $result; } /** * Enables bulk uploaded of files and images * @param string $fileRelationName The relation name in the model to attach uploaded files to * @param string $folderName Folder path to upload files to * @return \GridBuilder */ public function addBulkUploader($fileRelationName = null, $folderName = null) { $gridFieldBulkUpload = Injector::inst()->create("GridFieldBulkUpload", $fileRelationName); if ($folderName) { $gridFieldBulkUpload->setUfSetup("setFolderName", $folderName); } $this->gridConfig->addComponent($gridFieldBulkUpload); return $this; } /** * <p> * Returns a new GridField instance preconfigured with options chosen from the GridConfigBuilder. * </p> * * @param string $name * @param string $title * @param SS_List $dataList * @return GridField */ public function getGrid($name, $title = null, SS_List $dataList = null) { return GridField::create($name, $title, $dataList, $this->gridConfig); } } |