本文整理汇总了PHP中GridField类的典型用法代码示例。如果您正苦于以下问题:PHP GridField类的具体用法?PHP GridField怎么用?PHP GridField使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GridField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateCMSFields
public function updateCMSFields(FieldList $fields)
{
// Payment Methods
$payment_table = GridField::create('PaymentMethods', _t("CheckoutAdmin.PaymentMethods", "Payment Methods"), $this->owner->PaymentMethods(), GridFieldConfig::create()->addComponents(new GridFieldToolbarHeader(), new GridFieldAddNewButton('toolbar-header-right'), new GridFieldSortableHeader(), new GridFieldDataColumns(), new GridFieldPaginator(20), new GridFieldEditButton(), new GridFieldDeleteAction(), new GridFieldDetailForm()));
// setup compressed payment options
$payment_fields = ToggleCompositeField::create('PaymentSettings', _t("CheckoutAdmin.Payments", "Payment Settings"), array(TextField::create('PaymentNumberPrefix', _t("CheckoutAdmin.OrderPrefix", "Add prefix to order numbers"), null, 9)->setAttribute("placeholder", _t("CheckoutAdmin.OrderPrefixPlaceholder", "EG 'abc'")), TextAreaField::create('PaymentSuccessContent', _t("CheckoutAdmin.PaymentSuccessContent", "Payment successfull content"))->setRows(4)->setColumns(30)->addExtraClass('stacked'), TextAreaField::create('PaymentFailerContent', _t("CheckoutAdmin.PaymentFailerContent", "Payment failer content"))->setRows(4)->setColumns(30)->addExtraClass('stacked'), $payment_table));
// Add html description of how to edit contries
$country_html = "<div class=\"field\">";
$country_html .= "<p>First select valid countries using the 2 character ";
$country_html .= "shortcode (see http://fasteri.com/list/2/short-names-of-countries-and-iso-3166-codes).</p>";
$country_html .= "<p>You can add multiple countries seperating them with";
$country_html .= "a comma or use a '*' for all countries.</p>";
$country_html .= "</div>";
$country_html_field = LiteralField::create("CountryDescription", $country_html);
// Deal with product features
$postage_field = new GridField('PostageAreas', '', $this->owner->PostageAreas(), GridFieldConfig::create()->addComponents(new GridFieldButtonRow('before'), new GridFieldToolbarHeader(), new GridFieldTitleHeader(), new GridFieldEditableColumns(), new GridFieldDeleteAction(), new GridFieldAddNewInlineButton('toolbar-header-left')));
// Add country dropdown to inline editing
$postage_field->getConfig()->getComponentByType('GridFieldEditableColumns')->setDisplayFields(array('Title' => array('title' => 'Title', 'field' => 'TextField'), 'Country' => array('title' => 'ISO 3166 codes', 'field' => 'TextField'), 'ZipCode' => array('title' => 'Zip/Post Codes', 'field' => 'TextField'), 'Calculation' => array('title' => 'Base unit', 'callback' => function ($record, $column, $grid) {
return DropdownField::create($column, "Based on", singleton('PostageArea')->dbObject('Calculation')->enumValues())->setValue("Weight");
}), 'Unit' => array('title' => 'Unit (equals or above)', 'field' => 'NumericField'), 'Cost' => array('title' => 'Cost', 'field' => 'NumericField'), 'Tax' => array('title' => 'Tax (percentage)', 'field' => 'NumericField')));
// Setup compressed postage options
$postage_fields = ToggleCompositeField::create('PostageFields', 'Postage Options', array($country_html_field, $postage_field));
// Setup compressed postage options
$discount_fields = ToggleCompositeField::create('DiscountFields', 'Discounts', array(GridField::create('Discounts', '', $this->owner->Discounts(), GridFieldConfig_RecordEditor::create())));
// Add config sets
$fields->addFieldToTab('Root.Checkout', $payment_fields);
$fields->addFieldToTab('Root.Checkout', $postage_fields);
$fields->addFieldToTab('Root.Checkout', $discount_fields);
}
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-checkout,代码行数:29,代码来源:CheckoutSiteConfigExtension.php
示例2: handleAction
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
{
if ($actionName == 'publishsummitevent') {
$summit_event = $gridField->getList()->byID($arguments['RecordID']);
$former_state = $summit_event->isPublished();
$msg = 'Summit Event Published!';
$code = 200;
try {
if ($former_state) {
$summit_event->unPublish();
} else {
$summit_event->publish();
}
$summit_event->write();
if ($former_state) {
$msg = 'Summit Event Unpublished!';
}
} catch (Exception $ex) {
//SS_Log::log($ex->getMessage(). SS_Log::ERR);
//throw new ValidationException($ex->getMessage(),0);
//return sprintf('<div>%s</div>', $ex->getMessage());
//Controller::curr()->getResponse()->setStatusCode($code, $ex->getMessage());
//Controller::curr()->getResponse()->setBody(sprintf('<div>%s</div>', $ex->getMessage()));
throw new ValidationException($ex->getMessage(), 0);
}
Controller::curr()->getResponse()->setStatusCode($code, $msg);
}
}
示例3: getClasses
/**
* Gets the classes that can be created using this button, defaulting to the model class and
* its subclasses.
*
* @param GridField $grid
* @return array a map of class name to title
*/
public function getClasses(GridField $grid)
{
$result = array();
if (is_null($this->classes)) {
$classes = array_values(ClassInfo::subclassesFor($grid->getModelClass()));
sort($classes);
} else {
$classes = $this->classes;
}
$kill_ancestors = array();
foreach ($classes as $class => $title) {
if (!is_string($class)) {
$class = $title;
$is_abstract = ($reflection = new ReflectionClass($class)) && $reflection->isAbstract();
if (!$is_abstract) {
$title = singleton($class)->i18n_singular_name();
}
} else {
$is_abstract = ($reflection = new ReflectionClass($class)) && $reflection->isAbstract();
}
if ($ancestor_to_hide = Config::inst()->get($class, 'hide_ancestor', Config::FIRST_SET)) {
$kill_ancestors[$ancestor_to_hide] = true;
}
if ($is_abstract || !singleton($class)->canCreate()) {
continue;
}
$result[$class] = $title;
}
if ($kill_ancestors) {
foreach ($kill_ancestors as $class => $bool) {
unset($result[$class]);
}
}
return $result;
}
示例4: getCMSFields
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->insertBefore(new DropdownField('MemberID', 'Member', Member::get()->map('ID', "FirstName")), 'AttendingWholeEvent');
$siteConfig = SiteConfig::current_site_config();
$current = $siteConfig->getCurrentEventID();
if ($this->ParentID < 1) {
$event = Event::get()->byID($current);
} else {
$event = Event::get()->byID($this->ParentID);
}
$fields->insertAfter(HiddenField::create('ParentID', 'Event', $event->ID), 'ExtraDetail');
$fields->removeByName('PublicFieldsRaw');
$fields->removeByName('Sort');
if ($this->PlayerGames()->Count() > 0) {
$gridField = new GridField('PlayerGames', 'Games', $this->PlayerGames(), $config = GridFieldConfig_RelationEditor::create());
$gridField->setModelClass('PlayerGame');
$config->addComponent(new GridFieldOrderableRows());
$config->removeComponentsByType('GridFieldPaginator');
$config->removeComponentsByType('GridFieldPageCount');
$config->addComponent(new GridFieldDeleteAction(false));
$config->addComponent($export = new GridFieldExportButton('before'));
$export->setExportColumns(singleton("PlayerGame")->getExportFields());
$fields->addFieldToTab('Root.PlayerGames', $gridField);
}
return $fields;
}
示例5: handleAction
public function handleAction(\GridField $gridField, $actionName, $arguments, $data)
{
if ($actionName != $this->urlSegment) {
return;
}
$record = $gridField->Form && $gridField->Form->Record ? $gridField->Form->Record : null;
if (!$record || !$record->SiteTreeID) {
throw new \ValidationException(_t('Link.NO_CURRENT_PAGE', 'No current page to draw from'), 0);
}
$root = \SiteTree::get()->filter('ParentID', $record->SiteTreeID);
if (!$root->exists()) {
throw new \ValidationException(_t('Link.NO_PAGES', 'No pages available'), 0);
}
$item = singleton($gridField->getModelClass());
if (!$item->canCreate()) {
throw new \ValidationException(_t('Link.CANNOT_CREATE', 'You cannot create a Link'), 0);
}
foreach ($root as $page) {
$link = $item->create();
$link->Type = 'SiteTree';
$link->SiteTreeID = $page->ID;
$link->write();
$gridField->getList()->add($link);
}
}
示例6: getManipulatedData
/**
*
* @param \GridField $gridField
* @param \SS_List $dataList
* @return \SS_List
*/
public function getManipulatedData(\GridField $gridField, \SS_List $dataList)
{
$state = $gridField->State->Milkyway_SS_GridFieldUtils_RangeSlider;
if (!isset($state->min) && !isset($state->value)) {
$settings = $this->scaffoldSliderSettingsForField(singleton($gridField->getModelClass())->obj($this->filterField), $dataList);
$this->working = [$gridField, $dataList];
if (isset($settings['start'])) {
if (is_array($settings['start'])) {
$state->min = $settings['start'][0];
$state->max = $settings['start'][1];
} else {
$state->value = $settings['start'];
}
} else {
return $dataList;
}
}
$dataListClone = clone $dataList;
$dbField = singleton($gridField->getModelClass())->obj($this->filterField);
if (isset($state->value)) {
$comparisonFilter = $this->comparisonFilter ? '' : ':' . $this->comparisonFilter;
$dataListClone = $dataListClone->filter($this->filterField . $comparisonFilter, $this->getValueForDB($dbField, $state->value));
} elseif (isset($state->min) && isset($state->max)) {
$dataListClone = $dataListClone->filter([$this->filterField . ':GreaterThan' => $this->getValueForDB($dbField, $state->min), $this->filterField . ':LessThan' => $this->getValueForDB($dbField, $state->max)]);
}
return $dataListClone;
}
示例7: getAllowedClasses
/**
* Gets the classes that can be created using this button, defaulting to the model class and
* its subclasses.
*
* @param \GridField $grid
* @return array a map of class name to title
*/
public function getAllowedClasses(\GridField $grid)
{
$result = array();
if ($this->useAllowedClasses) {
$classes = $this->useAllowedClasses;
$this->useAllowedClasses = null;
return $classes;
} else {
if (is_null($this->allowedClasses)) {
$classes = array_values(\ClassInfo::subclassesFor($grid->getModelClass()));
sort($classes);
} else {
$classes = $this->allowedClasses;
}
}
foreach ($classes as $class => $title) {
if (!is_string($class)) {
$class = $title;
$title = singleton($class)->i18n_singular_name();
}
if (!singleton($class)->canCreate()) {
continue;
}
$result[$class] = $title;
}
return $result;
}
开发者ID:helpfulrobot,项目名称:milkyway-multimedia-ss-gridfield-utils,代码行数:34,代码来源:AddNewInlineExtended_MultiClass.php
示例8: setupGridField
protected function setupGridField(GridField $gridfield, Config_ForClass $classConfig)
{
if (!$gridfield) {
return;
}
$config = $gridfield->getConfig();
$class = $gridfield->getModelClass();
// More item per page
$paginator = $config->getComponentByType('GridFieldPaginator');
$paginator->setItemsPerPage(50);
// Bulk manage
if ($classConfig->bulk_manage && class_exists('GridFieldBulkManager')) {
$already = $config->getComponentByType('GridFieldBulkManager');
if (!$already) {
$config->addComponent($bulkManager = new GridFieldBulkManager());
$bulkManager->removeBulkAction('unLink');
}
}
// Better export
if ($classConfig->export_csv) {
/* @var $export GridFieldExportButton */
$export = $config->getComponentByType('GridFieldExportButton');
$export->setExportColumns(ExcelImportExport::exportFieldsForClass($class));
} else {
$config->removeComponentsByType('GridFieldExportButton');
}
if ($classConfig->export_excel) {
if ($class == 'Group') {
$config->addComponent(new GridFieldButtonRow('after'));
}
$config->addComponent(new ExcelGridFieldExportButton('buttons-after-left'));
}
}
示例9: getCMSFields
public function getCMSFields()
{
$fields = singleton('DataObject')->getCMSFields();
$fields->addFieldsToTab('Root.Main', array(new ReadonlyField('SubmittedBy', 'Submitted By'), new ReadonlyField('IPAddress', 'IP Address'), new ReadonlyField('Created', 'Time Submitted'), new ReadonlyField('StatusMessages'), $field = new GridField('Values', 'Responses', $this->Values(), new GridFieldConfig_FlexiFormSubmissionValues())));
$field->addExtraClass('flexiform');
return $fields;
}
示例10: saveAllRecords
protected function saveAllRecords(\GridField $grid, $arguments, $data)
{
if (isset($data[$grid->Name])) {
$currValue = $grid->Value();
$grid->setValue($data[$grid->Name]);
$model = singleton($grid->List->dataClass());
foreach ($grid->getConfig()->getComponents() as $component) {
if ($component instanceof \GridField_SaveHandler) {
$component->handleSave($grid, $model);
}
}
if ($this->publish) {
// Only use the viewable list items, since bulk publishing can take a toll on the system
$list = ($paginator = $grid->getConfig()->getComponentByType('GridFieldPaginator')) ? $paginator->getManipulatedData($grid, $grid->List) : $grid->List;
$list->each(function ($item) {
if ($item->hasExtension('Versioned')) {
$item->writeToStage('Stage');
$item->publish('Stage', 'Live');
}
});
}
if ($model->exists()) {
$model->delete();
$model->destroy();
}
$grid->setValue($currValue);
if (\Controller::curr() && ($response = \Controller::curr()->Response)) {
if (!$this->completeMessage) {
$this->completeMessage = _t('GridField.DONE', 'Done.');
}
$response->addHeader('X-Status', rawurlencode($this->completeMessage));
}
}
}
示例11: updateCMSFields
function updateCMSFields(FieldList $fields)
{
$fields->addFieldToTab('Root.SkitterSlides', $grid = new GridField('MaxSkitterSlides', 'Skitter slides', $this->owner->MaxSkitterSlides(), GridFieldConfig_RelationEditor::create(10)));
if (class_exists("GridFieldSortableRows")) {
$grid->getConfig()->addComponent(new GridFieldSortableRows('SortOrder'));
}
}
示例12: updateCMSFields
public function updateCMSFields(FieldList $fields)
{
if ($this->owner->ID) {
// Relation handler for Blocks
$SConfig = GridFieldConfig_RelationEditor::create(25);
$SConfig->addComponent(new GridFieldOrderableRows('SortOrder'));
$SConfig->addComponent(new GridFieldDeleteAction());
// If the copy button module is installed, add copy as option
if (class_exists('GridFieldCopyButton')) {
$SConfig->addComponent(new GridFieldCopyButton(), 'GridFieldDeleteAction');
}
$gridField = new GridField("Blocks", "Content blocks", $this->owner->Blocks(), $SConfig);
$classes = array_values(ClassInfo::subclassesFor($gridField->getModelClass()));
if (count($classes) > 1 && class_exists('GridFieldAddNewMultiClass')) {
$SConfig->removeComponentsByType('GridFieldAddNewButton');
$SConfig->addComponent(new GridFieldAddNewMultiClass());
}
if (self::$create_block_tab) {
$fields->addFieldToTab("Root.Blocks", $gridField);
} else {
// Downsize the content field
$fields->removeByName('Content');
$fields->addFieldToTab('Root.Main', HTMLEditorField::create('Content')->setRows(self::$contentarea_rows), 'Metadata');
$fields->addFieldToTab("Root.Main", $gridField, 'Metadata');
}
}
return $fields;
}
示例13: handleAction
/**
* Handles the add action for the given DataObject.
*
* @param $gridField GridField
* @param $actionName string
* @param $arguments mixed
* @param $data array
*
* @return null|SS_HTTPResponse
*
* @throws UnexpectedValueException
*/
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
{
if ($actionName == 'add') {
$dbField = $this->getDataObjectField();
$objClass = $gridField->getModelClass();
/**
* @var DataObject $obj
*/
$obj = new $objClass();
if ($obj->hasField($dbField)) {
$obj->setCastedField($dbField, $data['gridfieldaddbydbfield'][$obj->ClassName][$dbField]);
if ($obj->canCreate()) {
$id = $gridField->getList()->add($obj);
if (!$id) {
$gridField->setError(_t('GridFieldAddByDBField.AddFail', 'Unable to save {class} to the database.', 'Unable to add the DataObject.', array('class' => get_class($obj))), 'error');
}
} else {
return Security::permissionFailure(Controller::curr(), _t('GridFieldAddByDBField.PermissionFail', 'You don\'t have permission to create a {class}.', 'Unable to add the DataObject.', array('class' => get_class($obj))));
}
} else {
throw new UnexpectedValueException(sprintf('Invalid field (%s) on %s.', $dbField, $obj->ClassName));
}
}
return null;
}
示例14: getColumnContent
/**
* @param GridField $gridField
* @param DataObject $record
* @param string $columnName
*
* @return string - the HTML for the column
*/
public function getColumnContent($gridField, $record, $columnName)
{
// No permission checks, handled through GridFieldDetailForm,
// which can make the form readonly if no edit permissions are available.
$data = new ArrayData(array('Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'edit')));
return $data->renderWith('GridFieldEditButton');
}
示例15: getClasses
/**
* Gets the classes that can be created using this button, defaulting to the model class and
* its subclasses.
*
* @param GridField $grid
* @return array a map of class name to title
*/
public function getClasses(GridField $grid)
{
$result = array();
if (is_null($this->classes)) {
$classes = array_values(ClassInfo::subclassesFor($grid->getModelClass()));
sort($classes);
} else {
$classes = $this->classes;
}
foreach ($classes as $class => $title) {
if (!is_string($class)) {
$class = $title;
if (($reflection = new ReflectionClass($class)) && $reflection->isAbstract()) {
continue;
}
$title = singleton($class)->i18n_singular_name();
} else {
if (($reflection = new ReflectionClass($class)) && $reflection->isAbstract()) {
continue;
}
}
if (!singleton($class)->canCreate()) {
continue;
}
$result[$class] = $title;
}
return $result;
}
开发者ID:DrMartinGonzo,项目名称:silverstripe-gridfieldextensions,代码行数:35,代码来源:GridFieldAddNewMultiClass.php