如何在链接浏览器中为内容元素和新的rte_ckeditor定义自定义类,标题和目标?

时间:2017-04-24 20:02:32

标签: typo3 typo3-8.x

先决条件

[x]你可以在TYPO3 8.7 LTS上再现问题 - 是

[x]您是否[粗略搜索]看看您的错误或增强功能是否已经报告过? -YES

描述

如何在任何元素链接(通常是元素标题和图像)和Typo3 8 LTS中的rte_ckeditor中配置链接浏览器的默认链接目标,类和标题?我花了几个小时试图配置它,但没有成功,也没有文档。如下图所示,这些字段是空的。

enter image description here enter image description here

重现问题的步骤

  1. 创建可以链接标题或图像的任何元素。
  2. 单击以打开链接浏览器
  3. 对于任何类型的链接(页面,文件,文件夹,外部URL,电子邮件),选项都为空。
  4. 预期行为: 我想为每种类型的链接定义默认类,链接目标和标题,如果它们是空的。 例如外部URL,我想自动填充target =“_ blank”,类“external-link”,title =“链接到外部网站”,如果之前没有配置链接。基本上对于任何新链接,我只想让它自动填充我的自定义值而不是空值。

    这只适用于以前Typo3版本的rtehtmlarea,但不是我无法在Typo3 8 LTS和ckeditor上设置此选项系统。

    过去只为rtehtmlarea工作的PageTS是这样的:

    RTE {
        classesAnchor {
            externalLink {
                class = external-link
                type = url
                titleText = Opens external link in new window
                target = _blank
                image =
            }
            externalLinkInNewWindow {
                class = external-link-new-window
                type = url
                titleText = Opens external link in new window
                target = _blank
                image =
            }
            internalLink {
                class = internal-link
                type = page
                titleText =  Opens internal link in this window
                target = _top
                image =
            }
            internalLinkInNewWindow {
                class = internal-link-new-window
                type = page
                titleText = Opens internal link in new window
                target = _blank
                image =
            }
            folder {
                class = folder
                type = folder
                titleText =
                target =
                image =
            }
            download {
                class = download
                type = file
                titleText = Initiates file download
                target = _blank
                image =
            }
            mail {
                class = mail
                type = mail
                titleText = Email Address
                image =
            }
        }
    }
    

    我希望这适用于新的rte_ckeditor以及我可以使用链接浏览器链接的任何元素选项。

5 个答案:

答案 0 :(得分:3)

所以经过几天,几天和几天!在搜索,试验和错误方面,我终于找到了一种方法,可以根据rte_ckeditor之外或rtehtmlarea之外的类型启用链接的自动填充参数。它不完全是我想要的,但几乎就在那里!

将此添加到我的页面TSConfig解决了部分问题:

TCEMAIN.linkHandler {
    # I don't want to load the folder link handler so I reset it.
    folder >
    # Leaving page type empty on purpose.
    page {
    }
    file {
        addParams = onclick="jumpToUrl('?act=file&linkAttributes[target]=_blank&linkAttributes[title]=Opens or downloads file in new window&linkAttributes[class]=download&linkAttributes[params]=');return false;"
    }
    url {
        addParams = onclick="jumpToUrl('?act=url&linkAttributes[target]=_blank&linkAttributes[title]=Opens external link in new window&linkAttributes[class]=externalLink&linkAttributes[params]=');return false;"
    }
    mail {
        addParams = onclick="jumpToUrl('?act=mail&linkAttributes[title]=Opens email manager to send an email&linkAttributes[class]=mail&linkAttributes[params]=');return false;"
    }
}

我没有为page配置任何内容,因为如果它已填充并且我点击了文件,外部网址,电子邮件或任何其他自定义链接处理程序,则属性将从页链接处理程序,它违背了每个链接处理程序类型的预填充参数的用途。

唯一剩下的问题是,如果我点击External URL上的例子,目标将是"_blank",标题将是"Opens external link in new window",而课程将是"externalLink"。到现在为止还挺好。然后,如果您点击链接File或甚至链接内部Page,那么预先为外部网址加载的参数将会传递,我认为不应该这样做。由于我试图预先填充每个链接类型,为什么我要保留以前链接类型的属性?这可能仅仅是一个意见问题,但我想为每种链接类型选择强制预先填充的参数。也许我只是缺少一个小配置来实现这种行为。

答案 1 :(得分:2)

这是解决方案,

RTE.default {

     # This will provide only basic tool in the text RTE
     preset = default

     ## Bootstrap CSS
     contentCSS {
         20 = fileadmin/Resources/Public/Bootstrap/css/bootstrap.css
     }


     classesAnchor {
        url {
            class = externalLink
            type = url
            titleText = Opens external link in new window
            target = _blank
            image =
         }

        page {
            class = internalLink
            type = page
            titleText =  Opens internal link in this window
            target = _top
            image =
        }

        file {
            class = download
            type = file
            titleText = external file
            target = _blank
            image =
        }

        folder {
            class = folder
            type = folder
            titleText = folder file
            target = _blank
            image =
        }

        mail {
            class = mail
            type = mail
            titleText = Email Address
            image =
        }
    }

    buttons.link{
        page.properties.class.default = internalLink

        url.properties.class.default = externalLink

        folder.properties.class.default = folder

        file.properties.class.default = download

        mail.properties.class.default = mail

        properties.class.allowedClasses = internalLink,externalLink,folder,mail,download
    }
}

看看这个,我已经添加了默认链接标题以及它的目标。你可以看到我后端的输出:

enter image description here

答案 2 :(得分:2)

TYPO3 8.7.8(仅限)中存在错误 - 请参阅:https://forge.typo3.org/issues/82865

[编辑] classesAnchor的东西仅适用于版本8.7.5到8.7.7,并希望在8.7.9再次工作

但正确的答案(如Ghanshyam Bhava在评论中指出)可以切换到YAML配置。

https://typo3worx.eu/2017/02/configure-ckeditor-in-typo3/

# Load default processing options
imports:
    - { resource: "EXT:rte_ckeditor/Configuration/RTE/Default.yaml" }

classesAnchor:

  externalLink:
    class: 'external-link'
    type: 'url'

  downloadLink:
    class: 'download-link'
    type: 'file'

  mailLink:
    class: 'mail-link'
    type: 'mail'

buttons:
  link:
    properties:
      class:
        allowedClasses: 'external-link,download-link,mail-link'

RTE之外的其他字段的链接浏览器应该可以通过TCA-Overrides。

答案 3 :(得分:0)

我已经在TYPO3 9配置文件中用ckeditoryaml中测试了该解决方案,以加载我自己的默认值。除默认设置未按预期工作外,它工作正常。 titleText当前被相同类型的最后一个标题覆盖。例如对于“页面”类型,将加载标题“在新窗口中打开内部链接”,而不是“在此窗口中打开内部链接”。

buttons:
  link:
    relAttribute:
      enabled: true
    page:
      properties:
        class:
          default: internal-link
    url:
      properties:
        class:
          default: external-link-new-window
    folder:
      properties:
        class:
          default: folder
    file:
      properties:
        class:
          default: download
    mail:
      properties:
        class:
          default: mail
    properties:
      class:
        allowedClasses: 'internal-link,internal-link-new-window,download,external-link,external-link-new-window,mail'

#Classes config
classesAnchor:
  internalLink:
    class: 'internal-link'
    type: 'page'
    titleText: 'Opens internal link in this window'
  internalLinkNewWindow:
    class: 'internal-link-new-window'
    type: 'page'
    target: '_blank'
    titleText: 'Opens internal link in new window'
  download:
    class: 'download'
    type: 'file'
    target: '_blank'
    titleText: 'Download file'
  externalLink:
    class: 'external-link'
    type: 'url'
    titleText: 'Opens External link in this window'
  externalLinkNewWindow:
    class: 'external-link-new-window'
    type: 'url'
    target: '_blank'
    titleText: 'Opens External link in new window'
  linkMail:
    class: 'mail'
    type: 'mail'
    titleText: 'Email Address'

答案 4 :(得分:0)

要在yaml中配置默认类,您必须在.yaml文件中添加这样的默认类:

classesAnchor:
    page:
        class: 'link-page'
        type: 'page'
        target: '_top'
    file:
        class: 'link-file'
        type: 'file'
        target: '_blank'
        titleText: 'Download'
    url:
        class: 'link-external'
        type: 'url'
        target: '_blank'
    mail:
        class: 'link-mail'
        type: 'mail'
        titleText: 'Send email'


buttons:
    link:
        properties:
            class:
                allowedClasses: 'link-page, link-file, link-external, link-mail'
        page:
            properties:
                class:
                    default: 'link-page'
        file:
            properties:
                class:
                    default: 'link-file'
        url:
            properties:
                class:
                    default: 'link-external'
        mail:
            properties:
                class:
                    default: 'link-mail'