fromholdio/silverstripe-cms-fields-scaffolder
Composer 安装命令:
composer require fromholdio/silverstripe-cms-fields-scaffolder
包简介
关键字:
README 文档
README
A SilverStripe module for scaffolding CMS field tab structures and placement via YAML configuration. This module simplifies the process of organizing CMS fields into custom tab structures across different contexts (CMS edit forms, Settings forms, custom forms).
Features
- Section-based configuration: Define different tab structures for different contexts (cms, settings, or custom sections)
- Declarative tab structure: Define your entire tab hierarchy in YAML
- Automatic tab creation: TabSets and Tabs are created automatically based on configuration
- Field label integration: Tab titles automatically use your DataObject's
field_labelsconfiguration - Content field relocation: Move the default Content field to a custom tab location
- Root.Main tab relocation: Move fields from the default Root.Main tab to a custom location
- Empty tab cleanup: Automatically remove empty tabs and tabsets
- Field removal: Remove unwanted fields by name
Installation
composer require fromholdio/silverstripe-cms-fields-scaffolder
Requirements
- SilverStripe ^4.1 || ^5.0 || ^6.0
Usage
Basic Setup
- Apply the extension to your DataObject:
Page: extensions: - Fromholdio\CMSFieldsScaffolder\CMSFieldsScaffolder
- Configure your tab structure:
Page: scaffolder: cms: tabs: MainTabSet: - MainTab - DetailsTab ContentTabSet: - ContentMainTab - ContentBlocksTab field_labels: MainTabSet: Main MainTab: Main DetailsTab: Details ContentTabSet: Content ContentMainTab: Main ContentBlocksTab: Blocks
- Integrate into your getCMSFields() method:
public function getCMSFields() { $this->beforeUpdateCMSFields(function (FieldList $fields) { return $this->runCMSFieldsScaffolderBeforeUpdate($fields); }); $this->afterUpdateCMSFields(function (FieldList $fields) { return $this->runCMSFieldsScaffolderAfterUpdate($fields, 'cms', false); }); $fields = parent::getCMSFields(); // Your custom field additions here $fields = $this->clearCMSFieldsScaffolderEmptyTabs($fields, 'cms'); $fields = $this->removeCMSFieldsScaffolderFields($fields, 'cms'); return $fields; }
Section Keys
The module supports section-based configuration, allowing you to define different tab structures for different contexts. Common section keys include:
cms- For the main CMS edit form (getCMSFields)settings- For the Settings tab (getSettingsFields)- Custom keys - For any other form context you define
Each section can have its own independent configuration.
Configuration Options
Each section supports the following configuration options:
tabs
Defines the tab structure. Can be a simple array of tab names, or a nested structure for TabSets:
Page: scaffolder: cms: tabs: # Simple TabSet with child Tabs MainTabSet: - MainTab - DetailsTab # Another TabSet ContentTabSet: - ContentMainTab
do_clear_empty_tabs
Boolean. When true, automatically removes empty tabs and tabsets after all fields have been added. Default: true
Page: scaffolder: cms: do_clear_empty_tabs: true
content_field_tab_path
Specifies where to move the default Content field. Set to false to remove it entirely, or provide a tab path:
Page: scaffolder: cms: content_field_tab_path: 'Root.ContentTabSet.ContentMainTab' # Or to remove it: # content_field_tab_path: false
root_main_tab_path
Specifies where to move fields from the default Root.Main tab:
Page: scaffolder: cms: root_main_tab_path: 'Root.MainTabSet.MainTab'
fields_to_remove
Array of field names to remove from the form:
Page: scaffolder: cms: fields_to_remove: - UnwantedField - AnotherField
Complete Example
Here's a complete example showing multiple sections:
Page: extensions: - Fromholdio\CMSFieldsScaffolder\CMSFieldsScaffolder scaffolder: cms: do_clear_empty_tabs: true content_field_tab_path: 'Root.ContentTabSet.ContentMainTab' root_main_tab_path: 'Root.MainTabSet.MainTab' tabs: MainTabSet: - MainTab - DetailsTab ContentTabSet: - ContentMainTab - ContentBlocksTab SEOTabSet: - SEOMainTab settings: do_clear_empty_tabs: true root_main_tab_path: 'Root.MainTabSet.MainTab' tabs: MainTabSet: - MainTab AccessTabSet: - AccessMainTab field_labels: MainTabSet: Main MainTab: Main DetailsTab: Details ContentTabSet: Content ContentMainTab: Main ContentBlocksTab: Blocks SEOTabSet: SEO SEOMainTab: SEO AccessTabSet: Access AccessMainTab: Main
Integration Patterns
For getCMSFields()
public function getCMSFields() { $this->beforeUpdateCMSFields(function (FieldList $fields) { return $this->runCMSFieldsScaffolderBeforeUpdate($fields); // Or with explicit section: $this->runCMSFieldsScaffolderBeforeUpdate($fields, 'cms'); }); $this->afterUpdateCMSFields(function (FieldList $fields) { return $this->runCMSFieldsScaffolderAfterUpdate($fields, 'cms', false); }); $fields = parent::getCMSFields(); // Add your custom fields here $fields = $this->clearCMSFieldsScaffolderEmptyTabs($fields, 'cms'); $fields = $this->removeCMSFieldsScaffolderFields($fields, 'cms'); return $fields; }
For getSettingsFields()
public function getSettingsFields() { $this->beforeExtending('updateSettingsFields', function (FieldList $fields) { return $this->runCMSFieldsScaffolderBeforeUpdate($fields, 'settings'); }); $this->afterExtending('updateSettingsFields', function (FieldList $fields) { return $this->runCMSFieldsScaffolderAfterUpdate($fields, 'settings', false); }); $fields = parent::getSettingsFields(); // Add your custom fields here $fields = $this->clearCMSFieldsScaffolderEmptyTabs($fields, 'settings'); $fields = $this->removeCMSFieldsScaffolderFields($fields, 'settings'); return $fields; }
API Methods
runCMSFieldsScaffolderBeforeUpdate(FieldList $fields, string $key = 'cms'): FieldList
Runs before extensions update fields. Creates tabs and relocates the Content field.
runCMSFieldsScaffolderAfterUpdate(FieldList $fields, string $key = 'cms', bool $doClearTabs = true): FieldList
Runs after extensions update fields. Relocates Root.Main tab fields and optionally clears empty tabs.
clearCMSFieldsScaffolderEmptyTabs(FieldList $fields, string $key = 'cms'): FieldList
Removes empty tabs and tabsets based on the section's do_clear_empty_tabs setting.
removeCMSFieldsScaffolderFields(FieldList $fields, string $key = 'cms'): FieldList
Removes fields specified in the section's fields_to_remove configuration.
getCMSFieldsScaffolderSetting(string $name, string $key = 'cms')
Retrieves a specific configuration setting for a section.
applyCMSFieldsScaffolderTabs(FieldList $fields, string $key = 'cms'): FieldList
Creates the tab structure defined in the section's tabs configuration.
applyCMSFieldsScaffolderContentFieldTabPath(FieldList $fields, string $key = 'cms'): FieldList
Relocates or removes the Content field based on the section's content_field_tab_path configuration.
applyCMSFieldsScaffolderRootMainTabPath(FieldList $fields, string $key = 'cms'): FieldList
Relocates fields from Root.Main (or Root.Settings) to the path specified in root_main_tab_path.
Version History & Breaking Changes
Version 2.x (Current - With Section Keys)
The current version uses section-based configuration where each context (cms, settings, etc.) has its own configuration block.
Configuration structure:
Page: scaffolder: cms: # Section key tabs: ... do_clear_empty_tabs: true settings: # Another section key tabs: ...
Method signatures:
runCMSFieldsScaffolderBeforeUpdate(FieldList $fields, string $key = 'cms'): FieldList runCMSFieldsScaffolderAfterUpdate(FieldList $fields, string $key = 'cms', bool $doClearTabs = true): FieldList clearCMSFieldsScaffolderEmptyTabs(FieldList $fields, string $key = 'cms'): FieldList removeCMSFieldsScaffolderFields(FieldList $fields, string $key = 'cms'): FieldList getCMSFieldsScaffolderSetting(string $name, string $key = 'cms')
Default section configurations:
private static $scaffolder = [ 'cms' => [ 'tabs' => null, 'do_clear_empty_tabs' => true, 'content_field_tab_path' => 'Root.ContentTabSet.ContentMainTab', 'root_main_tab_path' => 'Root.MainTabSet.MainTab', 'fields_to_remove' => null, ], 'settings' => [ 'tabs' => null, 'do_clear_empty_tabs' => true, 'content_field_tab_path' => 'Root.ContentTabSet.ContentMainTab', 'root_main_tab_path' => 'Root.MainTabSet.MainTab', 'fields_to_remove' => null, ], ];
Version 1.x (Legacy - Without Section Keys)
The legacy version used a flat configuration structure without section keys.
Configuration structure:
Page: scaffolder: tabs: ... # Direct configuration, no section key do_clear_empty_tabs: true
Method signatures:
runCMSFieldsScaffolderBeforeUpdate(FieldList $fields): FieldList runCMSFieldsScaffolderAfterUpdate(FieldList $fields): FieldList clearCMSFieldsScaffolderEmptyTabs(FieldList $fields): FieldList removeCMSFieldsScaffolderFields(FieldList $fields): FieldList getCMSFieldsScaffolderSetting(string $key)
Default configuration:
private static $scaffolder = [ 'tabs' => null, 'do_clear_empty_tabs' => true, 'content_field_tab_path' => 'Root.ContentTabSet.ContentMainTab', 'root_main_tab_path' => 'Root.MainTabSet.MainTab', 'fields_to_remove' => null ];
Migrating from 1.x to 2.x
If you're upgrading from version 1.x, you'll need to:
- Update your YAML configuration to nest settings under section keys:
# Old (1.x) Page: scaffolder: tabs: MainTabSet: - MainTab # New (2.x) Page: scaffolder: cms: # Add section key tabs: MainTabSet: - MainTab
- Update method calls to include the section parameter:
// Old (1.x) $this->runCMSFieldsScaffolderBeforeUpdate($fields); $this->runCMSFieldsScaffolderAfterUpdate($fields); $this->clearCMSFieldsScaffolderEmptyTabs($fields); // New (2.x) $this->runCMSFieldsScaffolderBeforeUpdate($fields, 'cms'); $this->runCMSFieldsScaffolderAfterUpdate($fields, 'cms', false); $this->clearCMSFieldsScaffolderEmptyTabs($fields, 'cms');
Note: The section parameter defaults to 'cms', so you can omit it for CMS forms if desired.
License
BSD-3-Clause
Maintainer
Luke Fromhold - https://fromhold.io
fromholdio/silverstripe-cms-fields-scaffolder 适用场景与选型建议
fromholdio/silverstripe-cms-fields-scaffolder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 451 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「silverstripe」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fromholdio/silverstripe-cms-fields-scaffolder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fromholdio/silverstripe-cms-fields-scaffolder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fromholdio/silverstripe-cms-fields-scaffolder 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Analytics chooser extensions for site settings.
CitaNZ's SilverStripe picture object and field for SilverStripe 4
bootstrap select field module implementing http://silviomoreto.github.io/bootstrap-select/
Allows you to defined CMS form structure via config.yml
A module for adding a podcast or multiple podcasts to your SilverStripe site. With support for audio, video or other files.
统计信息
- 总下载量: 451
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2023-04-17