3

Is there a way to remove the 2 Craft specific menu items from Redactor's Link menu without losing access to the "Insert link" menu item?

Removing the Link button in the redactor configs is too draconian as I don't want to lose access to the basic Insert and Unlink functions previously in that menu.

I've dug into the src, and the only hook/event I can find related to the redactor settings allows addition of menu items to the Links menu, but not removal of the Craft added "Link to an Entry" and "Link to a Category".

Rich text field with link menu exposed with menu items crossed out.

1

I don't think there's an easy way to do this natively in Craft.

Maybe you could pull it off with combination of https://github.com/lindseydiloreto/craft-cpcss and/or https://github.com/lindseydiloreto/craft-cpcjs and manipulate the DOM directly.

Or maybe by going from the Redactor site and listening to their click event.

1

Turns out, this is very easy to do in Craft 3!

https://github.com/craftcms/redactor/issues/146#issuecomment-501862773

Using a custom module, you can implement code similar to this...

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 = [];

        }

    }
);
-2

In craft->app->fieldtypes->RichTextFieldType.php there is a function called _getLinkOptions. In there if you just return an empty array, there will only be the option to link to a URL.

  • 2
    Please do NOT do this. Any updates you make to the craft/app folder could be removed when you run Craft updates. Brad's answer about using a plugin is the best solution. – Jamie Wade Jan 26 '17 at 16:03
  • Sometimes people need a solution. If you have control of updates and keep track of what you've changed it's really not a big deal. Can people be trusted to use their own discretion? – Dexterity Jan 27 '17 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.