定制 alengo/sulu-preview-block-focus-bundle 二次开发

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

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

alengo/sulu-preview-block-focus-bundle

最新稳定版本:3.0.0

Composer 安装命令:

composer require alengo/sulu-preview-block-focus-bundle

包简介

Sulu CMS admin enhancement: clicking a block in the preview iframe scrolls to and expands the corresponding block in the admin form.

README 文档

README

Sulu CMS bundle that enables click-to-edit in the preview iframe: hovering a block shows a focus button, clicking it scrolls to and expands the corresponding block in the admin form.

Features

  • Hover overlay with focus button on blocks in the preview iframe
  • Clicking the button scrolls to the block in the admin form and expands it
  • Supports nested blocks (sends parent IDs first, child last)
  • Twig function sulu_user_loggedin_and_preview to conditionally include the preview script

Requirements

  • PHP 8.2+
  • Sulu CMS 3.0+
  • Symfony 7.0+

Installation

composer require alengo/sulu-preview-block-focus-bundle

Register the bundle in config/bundles.php:

Alengo\SuluPreviewBlockFocusBundle\PreviewBlockFocusBundle::class => ['all' => true],

Admin JS

1. Add to assets/admin/package.json under dependencies:

"sulu-preview-block-focus-bundle": "file:../../vendor/alengo/sulu-preview-block-focus-bundle/assets/admin"

2. Install the dependency:

cd assets/admin && npm install

3. Import in assets/admin/app.js:

import 'sulu-preview-block-focus-bundle';

4. Rebuild the admin:

cd assets/admin && npm run build

Website JS (Webpack Encore)

Add an entry in webpack.config.js:

.addEntry('suluPreviewBlockFocus', './vendor/alengo/sulu-preview-block-focus-bundle/assets/website/index.js')

Include the script conditionally in your Twig layout (only in Sulu preview context):

{% if sulu_user_loggedin_and_preview(app.request) %}
    {{ encore_entry_script_tags('suluPreviewBlockFocus', null, 'baseConfig', attributes={
        'defer': false,
        'async': true
    }) }}
{% endif %}

Block markup

Add data-block-id conditionally — only when rendering in the Sulu preview context:

<div{{ (sulu_user_loggedin_and_preview(app.request) ? ' data-block-id="' ~ content._id|default ~ '"')|raw }}>

This ensures data-block-id is only rendered inside the preview iframe and never exposed on the public website.

How it works

Website side (assets/website/index.js): Runs inside the Sulu preview iframe. On block hover, a focus button appears. On click, it posts a sulu-preview-block-click message with the block UUID to the parent window.

Admin side (assets/admin/index.js): Listens for sulu-preview-block-click messages. Uses React fiber introspection to find the matching block in the admin form, collapses other open blocks, expands the target block, and scrolls to it.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固