micschk/silverstripe-excludechildren

此包已被废弃,不再维护。作者建议使用 由核心功能替代,请参阅 excludechildren README 包。
此包的最新版本(2.0)没有提供许可证信息。

从 SiteTree 中隐藏页面的扩展

安装次数: 22,361

依赖: 2

建议者: 0

安全: 0

星标: 20

关注者: 5

分支: 10

开放问题: 0

类型:silverstripe-module

2.0 2018-04-24 04:48 UTC

This package is auto-updated.

Last update: 2019-11-26 07:02:37 UTC


README

感谢每一位安装了此扩展以隐藏 SiteTree 中的页面(自 2012 年以来有近 16.5K 次Composer 安装)。由于比较功能已添加到 SilverStripe 框架(Hierarchy),我将不再更新此模块以支持 SS4。

我已标记 2.0 版本,表示与 SS3.5 及以上版本的兼容性。这应会提示用户迁移到以下所述的核心功能。我将保持此存储库不变,所以如果您遇到任何问题,请提出工单,我将尽力解决。

如果需要,1.1 版本应继续在 SS3 的任何版本上使用,但建议您从 SS3.5 开始卸载此模块并更新配置,如下所示。

配置 SS3.5+ 中的隐藏页面

$hide_from_cms_tree 在 CMS 中隐藏,不在前端隐藏

通常在 CMS 中隐藏页面类型

SilverStripe\ORM\Hierarchy\Hierarchy:
  hide_from_cms_tree:
    - 'PageClassToHide'

仅在“容器”页面类型的子页面中隐藏页面类型

HiddenPageHolderClass:
  hide_from_cms_tree:
    - 'PageClassToHide'

$hide_from_hierarchy 在 CMS 和前端都隐藏

通常在 CMS 和前端中隐藏页面类型

SilverStripe\ORM\Hierarchy\Hierarchy:
  hide_from_hierarchy:
    - 'PageClassToHide'

仅在“容器”页面类型的子页面中在 CMS 和前端中隐藏页面类型

HiddenPageHolderClass:
  hide_from_hierarchy:
    - 'PageClassToHide'

管理 SS3.5+ 中的“隐藏”页面

使用持有者页面上的网格字段(参见:silverstripe-gridfieldsitetreebuttons)或使用 ModelAdmin 或类似工具来管理隐藏页面。

当然,还有非常鼓舞人心的 Lumberjack 模块(但您可能已经看到了它被推广)... (/sarcasm)

获取前端中的“隐藏”页面

如果使用 $hide_from_hierarchy,隐藏页面将不会包含在 $Children 循环中。相反,可以使用类似以下方法进行查询:

	public function HiddenChildren(){
		return SiteTree::get()->filter('ParentID', $this->ID)->sort('Sort');
	}

或者,分页显示

	public function PaginatedChildren(){
		$children = SiteTree::get()->filter('ParentID', $this->ID);
		$ctrlr = Controller::curr();
		$children = new PaginatedList($children, $ctrlr->request);
		$children->setPageLength(10);
		return $children;
	}

遗留:在 SS<3.5> 中使用 excludechildren 模块

要求

  • SilverStripe 3.0 或更高版本(<3.5)

截图

从 sitetree 中隐藏 SiteTree 项(以及,通过一些额外的代码/模块,使用 GridField 管理它们):

安装

composer require micschk/silverstripe-excludechildren dev-master

使用方法

在 config.yml 中(最佳选择)

---
Only:
  classexists: 'ExcludeChildren'
---
SubPageHolder:
  extensions:
	- 'ExcludeChildren'
  excluded_children:
	- 'SubPage'
	- 'AnotherPageType'
  # optionally exclude from theme $Children as well (set to true if desired, default only from CMS)
  # eg. to exclude pre-existing child pages with 'show in menus' = true
  force_exclusion_beyond_cms: false

或者在您的 Page 类中(PHP)

	class SubPageHolder extends Page {
		...
		static $extensions = array("ExcludeChildren");
		static $excluded_children = array('SubPage', 'AnotherPageType_Extending_Page');
		...

或者通过外部的 _config.php 文件

		Object::add_extension("SubPageHolder", "ExcludeChildren");
		Config::inst()->update("SubPageHolder", "excluded_children", array("BlogEntry"));

###然后,添加一个 GridField 来创建/编辑子页面(参见下方的 Gridfieldpages 模块以获取现成解决方案/示例)

	$gridFieldConfig = GridFieldConfig::create()->addComponents(
		new GridFieldToolbarHeader(),
		new GridFieldAddNewSiteTreeItemButton('toolbar-header-right'), // GridfieldSitetreebuttons module
		new GridFieldSortableHeader(),
		new GridFieldFilterHeader(),
		$dataColumns = new GridFieldDataColumns(),
		new GridFieldPaginator(20),
		new GridFieldEditSiteTreeItemButton(), // GridfieldSitetreebuttons module
		new GridFieldOrderableRows() // Gridfieldextensions module, default 'Sort' is equal to page sort field...
	);
	$dataColumns->setDisplayFields(array(
		'Title' => 'Title',
		'URLSegment'=> 'URL',
		//'getStatus' => 'Status', // Implement getStatus() on child page class, see gridfieldpages module for an example
		'LastEdited' => 'Changed',
	));
	// use gridfield as normal
	$gridField = new GridField(
		"SubPages", # Can be any name, field doesn't have to exist on model...
		"SubPages of this page", 
        SiteTree::get()->filter('ParentID', $this->ID),
		$gridFieldConfig);
    $fields->addFieldToTab("Root.SubPages", $gridField);

在模板中循环遍历 $Children

此模块默认情况下仅隐藏子页面从 CMS 站点树中。因此,您可以在主题中像往常一样使用 $Children。当从 CMS 编辑器创建页面链接时,子页面也将可用。

当从前端也排除页面(force_exclusion_beyond_cms)时,您可以在您的 Holder 中添加一个备选获取器

	public function SortedChildren(){
		return SiteTree::get()->filter('ParentID', $this->ID)->sort('Sort');
	}

或者,分页显示

	public function PaginatedChildren(){
		$children = SiteTree::get()->filter('ParentID', $this->ID);
		$ctrlr = Controller::curr();
		$children = new PaginatedList($children, $ctrlr->request);
		$children->setPageLength(10);
		return $children;
	}

如果您的页面没有显示在 $Children 中,以下是一些需要检查的事项

  • force_exclusion_beyond_cms 是否设置为 false(或使用自定义获取器)?
  • 您的子页面是否设置为显示在菜单中(显示在菜单中)?

自定义您的子页面

如果您需要通过不仅仅是类名来自定义隐藏的子页面,您可以实现 getExcludedChildren,它需要返回一个 DataList,包含在 SiteTree 中要显示的子页面。

专业提示

将 GridfieldSitetreebuttons 添加到您的 gridfieldconfig 中,以在常规编辑表单中编辑页面

或者使用/继承预先配置的 GridfieldPages 模块,该模块包含排除子页面、站点树按钮、排序和发布状态