toastnz/open-cms-preview 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

toastnz/open-cms-preview

最新稳定版本:6.0.0-beta1

Composer 安装命令:

composer require toastnz/open-cms-preview

包简介

Force SilverStripe to open the CMS preview panel on any page with a form

README 文档

README

This module allows you to open the CMS preview panel from any page in the CMS that has a form.

Installation

To install the module, use Composer:

composer require toastnz/open-cms-preview

Usage

To use the module, simply add the following form field to any form in the CMS:

use Toast\OpenCmsPreview\Fields\OpenCmsPreview;

public function getCMSFields()
{
    $fields = parent::getCMSFields();

    $fields->addFieldsToTab('Root.Main', [
        OpenCmsPreview::create($this->getPreviewLink());
    ]);

    return $fields;
}

public function getPreviewLink()
{
    // Return the link to the page you want to preview
}

Extending the controller

The module adds a new OpenCMSPreviewController to the window which you can extend to add custom functionality.

The refresh event is called when the Controller observes an ajax / fetch event with some basic and conditional checks to determine when the refresh should be called or prevented. You can use the on('beforeRefresh') event to add custom functionality before the refresh is called.

Additionally you can call event.preventRefresh(); to prevent the refresh from being called.

// Example usage
window.OpenCMSPreviewController.on('beforeRefresh', (event) => {
    // This event data also includes the ajax / fetch response
    console.log(event.data);

    // Prevent the refresh from being called if some condition is met
    if (event.data.someKey == 'someValue') {
        event.preventRefresh();
    }
});

You also have access to a few other events:

// When the refresh is complete
on('refresh', (iframeSrc) => {});

// Before the preview refresh script has run
on('beforeRefresh', (event) => {});

// After the preview has been added to the page
on('addPreview', (previewElement) => {});

// After the preview has been removed from the page
on('removePreview', () => {});

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2025-03-05