Redactor: 从下拉列表中删除“链接到条目”的选项或挂钩

创建于 2019-06-12  ·  3评论  ·  资料来源: craftcms/redactor

如果我们可以从下拉菜单中删除“链接到条目”选项,那就太好了。 “链接到类别”同上。

Ω 2019-06-12 at 12 49 47 PM

我什至不关心它是如何实现的(无论是字段选项、Redactor 配置还是需要模块挂钩)。 但是对用户可以链接到的内容有更多的控制会很好。

值得注意的是,这不是一个新的请求......

https://craftcms.stackexchange.com/questions/17567/how-to-remove-link-to-category-from-redactor

最有用的评论

甜蜜,这就像一个魅力!

use craft\redactor\events\RegisterLinkOptionsEvent;
use craft\redactor\Field as RedactorField;
use yii\base\Event;

// Remove "Link to..." Redactor links
Event::on(
    RedactorField::class,
    RedactorField::EVENT_REGISTER_LINK_OPTIONS,
    function(RegisterLinkOptionsEvent $event) {

        // Only apply to a specific Redactor config
        if ('Message.json' == $event->sender->redactorConfig) {

            // Remove Craft's injected links
            $event->linkOptions = [];

        }

    }
);

我使用$event->sender->redactorConfig来标识我想要定位的特定 Redactor 配置。

如果您只想删除_一个特定来源_,您可以手动选择它。 作为参考,以下是 Craft 配置这些额外链接的方式...

[
    0 => [
        'optionTitle' => 'Link to an entry'
        'elementType' => 'craft\\elements\\Entry'
        'refHandle' => 'entry'
        'sources' => [
            0 => 'section:19870dc1-a51e-4134-bd5c-de55b11ddf2c'
            1 => 'section:eca834a6-d8a1-4797-a552-e310f946eafb'
            2 => 'section:128d6e4e-d02f-4247-83eb-a3841ca7ade5'
            3 => 'section:c422ed50-9844-4531-854f-f8c505d92a05'
        ]
    ]
    1 => [
        'optionTitle' => 'Link to a category'
        'elementType' => 'craft\\elements\\Category'
        'refHandle' => 'category'
        'sources' => [
            0 => 'group:95e58ebd-aba6-48b8-adaf-ebae28ffbb7a'
            1 => 'group:9bd9e19d-e53a-46eb-af47-2ce9a12a0ade'
        ]
    ]
]

谢谢@andris-sevcenko! 🍺

所有3条评论

说到模块挂钩,您已经可以使用REGISTER_LINK_OPTIONS事件,只需从$event->linkOptions数组中删除一些选项即可。 (https://github.com/craftcms/redactor/blob/v2/src/Field.php#L563)

甜蜜,这就像一个魅力!

use craft\redactor\events\RegisterLinkOptionsEvent;
use craft\redactor\Field as RedactorField;
use yii\base\Event;

// Remove "Link to..." Redactor links
Event::on(
    RedactorField::class,
    RedactorField::EVENT_REGISTER_LINK_OPTIONS,
    function(RegisterLinkOptionsEvent $event) {

        // Only apply to a specific Redactor config
        if ('Message.json' == $event->sender->redactorConfig) {

            // Remove Craft's injected links
            $event->linkOptions = [];

        }

    }
);

我使用$event->sender->redactorConfig来标识我想要定位的特定 Redactor 配置。

如果您只想删除_一个特定来源_,您可以手动选择它。 作为参考,以下是 Craft 配置这些额外链接的方式...

[
    0 => [
        'optionTitle' => 'Link to an entry'
        'elementType' => 'craft\\elements\\Entry'
        'refHandle' => 'entry'
        'sources' => [
            0 => 'section:19870dc1-a51e-4134-bd5c-de55b11ddf2c'
            1 => 'section:eca834a6-d8a1-4797-a552-e310f946eafb'
            2 => 'section:128d6e4e-d02f-4247-83eb-a3841ca7ade5'
            3 => 'section:c422ed50-9844-4531-854f-f8c505d92a05'
        ]
    ]
    1 => [
        'optionTitle' => 'Link to a category'
        'elementType' => 'craft\\elements\\Category'
        'refHandle' => 'category'
        'sources' => [
            0 => 'group:95e58ebd-aba6-48b8-adaf-ebae28ffbb7a'
            1 => 'group:9bd9e19d-e53a-46eb-af47-2ce9a12a0ade'
        ]
    ]
]

谢谢@andris-sevcenko! 🍺

你好,

在链接到条目中,您知道如何根据用户的标记类别过滤部分条目吗? 我只想查看标记为该类别的所有条目。

非常感谢。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

stenvdb picture stenvdb  ·  16评论

lindseydiloreto picture lindseydiloreto  ·  10评论

jsunsawyer picture jsunsawyer  ·  15评论

lukeyouell picture lukeyouell  ·  26评论

cstudios-slovakia picture cstudios-slovakia  ·  6评论