Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
dizzystuff authored Jul 24, 2022
2 parents 0b6a07f + 7aeb1fe commit a73d2fd
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


5 changes: 5 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
---
Name: fromholdio-listings
After:
- gridfieldextensions
---

SilverStripe\Core\Injector\Injector:
Psr\SimpleCache\CacheInterface.ListingsCache:
factory: SilverStripe\Core\Cache\CacheFactory
constructor:
namespace: "ListingsCache"

Fromholdio\Listings\Forms\GridFieldListedPagesAddNewButton:
showEmptyString: true
12 changes: 12 additions & 0 deletions src/Extensions/ListingsSiteTreeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
6 changes: 6 additions & 0 deletions src/Forms/GridFieldListedPagesAddNewButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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) {
Expand Down
56 changes: 53 additions & 3 deletions src/Forms/ListedPageGridFieldItemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}

Expand Down

0 comments on commit a73d2fd

Please sign in to comment.