diu/neos-anchorlink

扩展Neos CKE5链接编辑器的自定义锚点链接选项

0.1.0 2020-02-07 12:29 UTC

README

通过服务器端可解析的锚点链接扩展Neos CKE5链接编辑器

anchorlink

安装

  1. 安装包:composer require diu/neos-anchorlink

  2. 使用以下配置启用额外的链接选项

"Neos.NodeTypes.BaseMixins:TextMixin": # Or other nodetype
  properties:
    text:
      ui:
        inline:
          editorOptions:
            linking:
              anchorLink: true
  1. 对于您希望能够链接到的所有内容节点类型,继承自DIU.Neos.AnchorLink:AnchorMixin,例如:
Neos.Neos:Content: # Or other nodetype
  superTypes:
    DIU.Neos.AnchorLink:AnchorMixin: true
  1. 调整这些节点的渲染以在它们之前插入锚点,例如,包含了一个Fusion处理器来帮助完成此操作
prototype(Neos.Neos:Content).@process.anchor = DIU.Neos.AnchorLink:AnchorLinkAugmentor

注意:这将向相应的输出添加一个id属性。为了可靠地工作,相应的原型应渲染单个根元素。否则,将渲染一个额外的包装div元素。此外,渲染的内容不得已包含id属性,因为它将与此处augmentor的属性合并。

配置

可以配置用于链接的内容节点节点类型。还可以通过Settings.yaml使用不同的属性来设置锚点值和标签。

以下是默认值

DIU:
  Neos:
    AnchorLink:
      # Only nodes of this type will appear in the "Choose link anchor" selector
      contentNodeType: "DIU.Neos.AnchorLink:AnchorMixin"
      # Eel Expression that returns the anchor (without leading "#") for a given node
      anchor: ${node.properties.anchor || node.name}
      # Eel Expression that returns the label to be rendered in the anchor selector in the Backend
      label: ${node.label}
      # Eel Expression that returns a group for the anchor selector (empty string == no grouping)
      group: ${I18n.translate(node.nodeType.label)}
      # Eel Expression that returns an icon for the anchor selector (empty string = no icon)
      icon: ${node.nodeType.fullConfiguration.ui.icon}

可以通过Settings.yaml禁用搜索框或调整其阈值,默认设置如下:

Neos:
  Neos:
    Ui:
      frontendConfiguration:
        "Diu.Neos.AnchorLink":
          displaySearchBox: true
          threshold: 0

低级自定义

最后,可以创建一个完全定制的锚点节点解析器。

创建一个实现AnchorLinkResolverInterface的类,它将接受当前内容节点、链接和搜索词,并返回一个用于链接锚点选择器的选项数组,并在Objects.yaml中进行配置,如下所示:

'DIU\Neos\AnchorLink\Controller\AnchorLinkController':
  properties:
    resolver:
      object: Your\Custom\AnchorLinkResolver

开发

如果您需要调整此包中的任何内容,请相应地进行调整,然后按照以下方式重新构建代码:

cd Resources/Private/AnchorLink
yarn && yarn build

然后提交更改的文件,包括Plugin.js