Silverstripe Version: 4.4
I’d like to change the fields used when viewing a page in a list.
By default they are Page Name Page type
and Last Updated
I’ve tried both $summary_fields
and $extra_summary_fields
in my Page class.
I’ve done dev/build?flush=all
with no change.
Found this here: https://docs.silverstripe.org/en/4/developer_guides/forms/field_types/gridfield/
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\CMS\Model\SiteTree;
class Page extends SiteTree
{
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Pages',
$grid = new GridField('Pages', 'All pages', SiteTree::get())
);
// GridField configuration
$config = $grid->getConfig();
//
// Modification of existing components can be done by fetching that component.
// Consult the API documentation for each component to determine the configuration
// you can do.
//
$dataColumns = $config->getComponentByType(GridFieldDataColumns::class);
$dataColumns->setDisplayFields([
'Title' => 'Title',
'Link'=> 'URL',
'LastEdited' => 'Changed'
]);
return $fields;
}
}
Interesting.
A bit more info I should have added. I’m not trying to do it for all pages. I have a holder page (NewsListPage
) and a view page (NewsPage
).
I’d like to change the columns for those NewsPage
pages only. The only $allowed_children
Pages under NewsListPage
are the NewsPage
types.
I’ve used getCMSFields
in both types to set their editing forms.
I’ve put some debugging in both page classes getCMSFields
functions and doesn’t seem to get hit. I also added some debugging to SiteTree::getCMSFields and still nothing.
This is the view I’m trying to change:
Digging in the code these fields are hard coded in the CMSMain::ListViewForm
Controller.