diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ce355a..c754e68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [1.0.4] + +Added methods to get plural and singular names of ListedRoot child common class. + ## [1.0.0] Initial project release diff --git a/README.md b/README.md index 5b8a38b..486aa43 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,11 @@ More thorough docs to come. In the meantime please submit questions as issues. ## To Do * Documentation and usage examples + +## When using ListedPagesAdmin (ModelAdmin subclass) to manage pages + +Add `doPlaceCMSFieldsUnderListedPagesAdminRootTabSet():bool` to your ListedPage class, and when displayed inside a ListedPagesAdmin the page fields' TabSets and Tabs will be displayed on the left side (like regularly viewed pages) rather than the top right. + +Further add `doAddSettingsFieldsAsListedPagesAdminTab():bool` to ListedPage class, and the page's settings fields will be displayed per regularly viewed pages as a Settings tab on the top right. This may/may not work for your specific class, where the same field name exists in your pages' getCMSFields and getSettingsFields. You'll need to manage that. + + diff --git a/_config/config.yml b/_config/config.yml index 1fd449a..483d40c 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -1,5 +1,7 @@ --- Name: fromholdio-listings +After: + - gridfieldextensions --- SilverStripe\Core\Injector\Injector: @@ -7,3 +9,6 @@ SilverStripe\Core\Injector\Injector: factory: SilverStripe\Core\Cache\CacheFactory constructor: namespace: "ListingsCache" + +Fromholdio\Listings\Forms\GridFieldListedPagesAddNewButton: + showEmptyString: true diff --git a/src/Extensions/ListingsSiteTreeExtension.php b/src/Extensions/ListingsSiteTreeExtension.php index 642323b..4d64ed6 100644 --- a/src/Extensions/ListingsSiteTreeExtension.php +++ b/src/Extensions/ListingsSiteTreeExtension.php @@ -73,4 +73,16 @@ public function getListedPagesCommonClass() return $class; } + + public function getListedPagesCommonSingularName() + { + $class = $this->getOwner()->getListedPagesCommonClass(); + return $class::singleton()->i18n_singular_name(); + } + + public function getListedPagesCommonPluralName() + { + $class = $this->getOwner()->getListedPagesCommonClass(); + return $class::singleton()->i18n_plural_name(); + } } diff --git a/src/Forms/GridFieldListedPagesAddNewButton.php b/src/Forms/GridFieldListedPagesAddNewButton.php index 43f9feb..d335b8f 100644 --- a/src/Forms/GridFieldListedPagesAddNewButton.php +++ b/src/Forms/GridFieldListedPagesAddNewButton.php @@ -31,6 +31,8 @@ */ class GridFieldListedPagesAddNewButton extends GridFieldAddNewButton implements GridField_ActionProvider { + private static $showEmptyString = false; + /** * Determine the list of classnames and titles allowed for a given parent object * @@ -72,6 +74,10 @@ public function getHTMLFragments($gridField) ->setFieldHolderTemplate(__CLASS__ . '_holder') ->addExtraClass('gridfield-dropdown gridfield-listedpages no-change-track'); + if (Config::inst()->get(__CLASS__, 'showEmptyString')) { + $pageTypes->setEmptyString(_t(__CLASS__ . '.SELECTTYPETOCREATE', '(Select type to create)')); + } + $state->pageType = $parent->defaultChild(); if (!$this->buttonName) { diff --git a/src/Forms/ListedPageGridFieldItemRequest.php b/src/Forms/ListedPageGridFieldItemRequest.php index db8df84..12b2f32 100644 --- a/src/Forms/ListedPageGridFieldItemRequest.php +++ b/src/Forms/ListedPageGridFieldItemRequest.php @@ -2,6 +2,9 @@ namespace Fromholdio\Listings\Forms; +use SilverStripe\Forms\FieldList; +use SilverStripe\Forms\TabSet; +use SilverStripe\Security\Permission; use SilverStripe\Versioned\VersionedGridFieldItemRequest; class ListedPageGridFieldItemRequest extends VersionedGridFieldItemRequest @@ -12,11 +15,58 @@ class ListedPageGridFieldItemRequest extends VersionedGridFieldItemRequest public function ItemEditForm() { - if (!empty($this->getRecord()) && !$this->getRecord()->ParentID) { - if ($this->getDefaultParentID() !== null) { - $this->getRecord()->ParentID = $this->getDefaultParentID(); + $record = $this->getRecord(); + $fields = $this->component->getFields(); + + $doPlaceCMSFieldsUnderRootTabSet = empty($fields) && !empty($record) + && $record->hasMethod('doPlaceCMSFieldsUnderListedPagesAdminRootTabSet') + && $record->doPlaceCMSFieldsUnderListedPagesAdminRootTabSet(); + + if ($doPlaceCMSFieldsUnderRootTabSet) + { + $singularName = empty($record) ? 'Page' : $record->i18n_singular_name(); + $cmsTabSet = TabSet::create('PageTabSet', $singularName); + + $fields = FieldList::create( + TabSet::create('Root', + $cmsTabSet = TabSet::create('CMSFieldsTabSet', $singularName), + $settingsTabSet = TabSet::create( + 'SettingsTabSet', _t(self::class . '.SETTINGSTABSET', 'Settings') + ) + ) + ); + + $cmsFields = $this->record->getCMSFields(); + $rootTabSet = $cmsFields->fieldByName('Root'); + foreach ($rootTabSet->Tabs() as $tab) { + $cmsTabSet->push($tab); + } + + if ( + !empty($record) + && $record->hasMethod('getSettingsFields') + && $record->hasMethod('doAddSettingsFieldsAsListedPagesAdminTab') + && $record->doAddSettingsFieldsAsListedPagesAdminTab() + ) { + $settingsFields = $record->getSettingsFields(); + $settingsRootTabSet = $settingsFields->fieldByName('Root'); + foreach ($settingsRootTabSet->Tabs() as $tab) { + $settingsTabSet->push($tab); + } + } + else { + $fields->removeByName('SettingsTabSet'); + } + + $this->component->setFields($fields); + } + + if (!empty($record) && empty($record->getField('ParentID'))) { + if (!empty($this->getDefaultParentID())) { + $record->setField('ParentID', $this->getDefaultParentID()); } } + return parent::ItemEditForm(); }