定制 christopherbolt/silverstripe-contentmodules 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

christopherbolt/silverstripe-contentmodules

Composer 安装命令:

composer require christopherbolt/silverstripe-contentmodules

包简介

A framework for flexible content modules.

README 文档

README

A framework for adding modular content to a page. All kinds of different content types can be added and re-ordered on a page. This is similar to the WidgetArea module but focused on content. Content Modules will be published and unpublished when the page is published/unpublished, ie. changes to content modules will only be published when the page is published which makes this module fully compatible with Workflow. CMS editors can change the content type of a module in a similar why to how you can change the the type of a page in the CMS.

Requirements

SS 4.x see 1.0 branch for SS 3.x

Creating Modules

No content modules are included, you must create your own.

You must create at least one ContentModule type.

Here is how you might code a basic text content module:

mysite/code/modules/TextModule.php:

<?php

use ChristopherBolt\ContentModules\ContentModule;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;

class TextModule extends ContentModule {
		
	private static $db = array(
		'Title' => 'Varchar',
		'Content' => 'HTMLText'
	);
	
	function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldsToTab('Root.Main', array(
			TextField::create('Title', 'Title'),
			HTMLEditorField::create('Content', 'Content')
		));		
		return $fields;
	}
}

themes/mytheme/templates/modules/TextModule.ss:

<section class="module $ClassName">
	<h2>$Title</h2>
	$Content
</section>

Adding modules to your page

Add the ModularPageExtension extension to your page:

use ChristopherBolt\ContentModules\ModularPageExtension;

class Page extends SiteTree {
	private static $extensions = array(
        ModularPageExtension::class
	);

You can now create and add modules to the page in the CMS.

To display the modules in your page template just use:

$Modules

Multiple module areas on one page

By default the ModularPageExtension adds a ContentModuleArea named "Modules". You can add additional ContentModuleArea areas:

use ChristopherBolt\ContentModules\ContentModuleArea;
use ChristopherBolt\ContentModules\ModularPageExtension;

class TwoColumnPage extends Page {
	private static $has_one = array(
        "RightColumn" => ContentModuleArea::class
	);
    private static $owns = array(
        "RightColumn"
    );
	private static $extensions = array(
        ModularPageExtension::class
	);
	function getCMSFields() {
		$fields = parent::getCMSFields();
		
		$fields->addFieldsToTab('Root.RightColumn', $this->getModularCMSFields('RightColumn', 'Right Column'));
				
		return $fields;
	}
}

And you can display your "RightColumn" content modules in your page template with $RightColumn

Customise how modules are stacked in your template

By default modules are simply stacked one after the other, but you might want to stack them in a list:

themes/mytheme/templates/ContentModuleArea.ss:

<ul>
<% loop $Modules %>
<li>$forLoop</li>
<% end_loop %>
</ul>

If you wanted to stack different ContentModuleAreas on your page in different ways then you may prefer to add the loop to your page template:

<% with $RightColumn %>
<ul>
<% loop $Modules %>
<li>$forLoop</li>
<% end_loop %>
</ul>
<% end_with %>

Controlling which module types are allowed on a page

You can restrict what types of content modules can be added to a page, or if you have multiple module areas on your page you can set restrictions for each area.

If you only have the default "Modules" module area or if you have multiple module areas and want to set the same restrictions for all of them:

	private static $allowed_modules = array(
        TextModule::class,
        ImageModule::class,
        StaffProfileModule::class
	);

If you have multiple module areas you can set restrictions for each one like this:

	private static $allowed_modules = array(
		'Modules' = array(
			TextModule::class,
			StaffProfileModule::class
		),
		'RightColumn' = array(
			ImageModule::class,
			RightTextModule::class,
			LinksModule::class
		),
	);

Installation

composer require christopherbolt/silverstripe-contentmodules ^2

christopherbolt/silverstripe-contentmodules 适用场景与选型建议

christopherbolt/silverstripe-contentmodules 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 194 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 04 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 christopherbolt/silverstripe-contentmodules 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 christopherbolt/silverstripe-contentmodules 我们能提供哪些服务?
定制开发 / 二次开发

基于 christopherbolt/silverstripe-contentmodules 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 194
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2016-04-19