本文整理汇总了PHP中GridField::getState方法的典型用法代码示例。如果您正苦于以下问题:PHP GridField::getState方法的具体用法?PHP GridField::getState怎么用?PHP GridField::getState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GridField
的用法示例。
在下文中一共展示了GridField::getState方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ListViewForm
public function ListViewForm()
{
$params = $this->request->requestVar('q');
$list = $this->getList($params, $parentID = $this->request->requestVar('ParentID'));
$gridFieldConfig = GridFieldConfig::create()->addComponents(new GridFieldSortableHeader(), new GridFieldDataColumns(), new GridFieldPaginator(self::config()->page_length));
if ($parentID) {
$gridFieldConfig->addComponent(GridFieldLevelup::create($parentID)->setLinkSpec('?ParentID=%d&view=list')->setAttributes(array('data-pjax' => 'ListViewForm,Breadcrumbs')));
}
$gridField = new GridField('Page', 'Pages', $list, $gridFieldConfig);
$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
// Don't allow navigating into children nodes on filtered lists
$fields = array('getTreeTitle' => _t('SiteTree.PAGETITLE', 'Page Title'), 'singular_name' => _t('SiteTree.PAGETYPE'), 'LastEdited' => _t('SiteTree.LASTUPDATED', 'Last Updated'));
$gridField->getConfig()->getComponentByType('GridFieldSortableHeader')->setFieldSorting(array('getTreeTitle' => 'Title'));
$gridField->getState()->ParentID = $parentID;
if (!$params) {
$fields = array_merge(array('listChildrenLink' => ''), $fields);
}
$columns->setDisplayFields($fields);
$columns->setFieldCasting(array('Created' => 'Datetime->Ago', 'LastEdited' => 'Datetime->FormatFromSettings', 'getTreeTitle' => 'HTMLText'));
$controller = $this;
$columns->setFieldFormatting(array('listChildrenLink' => function ($value, &$item) use($controller) {
$num = $item ? $item->numChildren() : null;
if ($num) {
return sprintf('<a class="cms-panel-link list-children-link" data-pjax-target="ListViewForm,Breadcrumbs" href="%s">%s</a>', Controller::join_links($controller->Link(), sprintf("?ParentID=%d&view=list", (int) $item->ID)), $num);
}
}, 'getTreeTitle' => function ($value, &$item) use($controller) {
return sprintf('<a class="action-detail" href="%s">%s</a>', Controller::join_links(singleton('CMSPageEditController')->Link('show'), (int) $item->ID), $item->TreeTitle);
}));
$listview = CMSForm::create($this, 'ListViewForm', new FieldList($gridField), new FieldList())->setHTMLID('Form_ListViewForm');
$listview->setAttribute('data-pjax-fragment', 'ListViewForm');
$listview->setResponseNegotiator($this->getResponseNegotiator());
$this->extend('updateListView', $listview);
$listview->disableSecurityToken();
return $listview;
}
示例2: testGetState
/**
* @covers GridField::getState
*/
public function testGetState()
{
$obj = new GridField('testfield', 'testfield');
$this->assertTrue($obj->getState() instanceof GridState_Data);
$this->assertTrue($obj->getState(false) instanceof GridState);
}
示例3: handleMoveToPage
/**
* Handles requests to move an item to the previous or next page.
*/
public function handleMoveToPage(GridField $grid, $request)
{
if (!($paginator = $grid->getConfig()->getComponentByType('GridFieldPaginator'))) {
$this->httpError(404, 'Paginator component not found');
}
$move = $request->postVar('move');
$field = $this->getSortField();
$list = $grid->getList();
$manip = $grid->getManipulatedList();
$existing = $manip->map('ID', $field)->toArray();
$values = $existing;
$order = array();
$id = isset($move['id']) ? (int) $move['id'] : null;
$to = isset($move['page']) ? $move['page'] : null;
if (!isset($values[$id])) {
$this->httpError(400, 'Invalid item ID');
}
$this->populateSortValues($list);
$page = (int) $grid->getState()->GridFieldPaginator->currentPage ?: 1;
$per = $paginator->getItemsPerPage();
if ($to == 'prev') {
$swap = $list->limit(1, ($page - 1) * $per - 1)->first();
$values[$swap->ID] = $swap->{$field};
$order[] = $id;
$order[] = $swap->ID;
foreach ($existing as $_id => $sort) {
if ($id != $_id) {
$order[] = $_id;
}
}
} elseif ($to == 'next') {
$swap = $list->limit(1, $page * $per)->first();
$values[$swap->ID] = $swap->{$field};
foreach ($existing as $_id => $sort) {
if ($id != $_id) {
$order[] = $_id;
}
}
$order[] = $swap->ID;
$order[] = $id;
} else {
$this->httpError(400, 'Invalid page target');
}
$this->reorderItems($list, $values, $order);
return $grid->FieldHolder();
}
开发者ID:helpfulrobot,项目名称:ajshort-silverstripe-gridfieldextensions,代码行数:49,代码来源:GridFieldOrderableRows.php