From 138e28a786371f39738cb55b94a58c2cb3543004 Mon Sep 17 00:00:00 2001 From: Tom Schulze Date: Wed, 14 Dec 2022 16:42:19 +0100 Subject: [PATCH] fix plugin registration, add default value --- CHANGELOG.md | 12 +++++++++--- README.md | 28 ++++++++++++++++++++++------ composer.json | 6 +++--- src/Nofollow.php | 10 +++++++--- src/resources/nofollow.js | 2 +- 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1fb3a5..6db9523 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ -# Redactor nofollow link plugin Changelog +# Release Notes for Redactor nofollow link Plugin + +## 2.1.0 - 2022-12-14 + +### Fixed + +- Preventing other Redactor plugins from registering. ## 2.0.0 - 2022-05-02 @@ -13,11 +19,11 @@ ## 1.0.1 - 2020-04-08 ### Fixed -- + - Fixed a bug when editing an existing link with the target="_blank" attribute causing the checkbox "nofollow" to always be selected. ## 1.0.0 - 2019-05-16 ### Added -- + - Initial release diff --git a/README.md b/README.md index f2dbce2..190eabc 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,14 @@ Plugin to add a checkbox to Redactor's link module to add the ```rel="nofollow"` ## Background -For a lot of sites it is important to set links to ```rel="nofollow"```. Redactor provides an option to set **all** links to *nofollow*. However, this is often not required and also not the usual practice in SEO. With this plugin it is possible to enable this attribute for every single link individual within the link's edit modal. +For a lot of sites it is important to set links to ```rel="nofollow"```. Redactor provides an option to set **all**links +to *nofollow*. However, this is often not required and also not the usual practice in SEO. With this plugin it is +possible to enable this attribute for every single link individual within the link's edit modal. ## Requirements - * Craft CMS >= 4.0.0 - * Craft Redactor Plugin >= 3.0.0 +* Craft CMS >= 4.0.0 +* Craft Redactor Plugin >= 3.0.0 ## Installation @@ -20,16 +22,28 @@ Open your terminal and go to your Craft project: ``` shell cd /path/to/project composer require codemonauts/craft-redactor-nofollow -./craft install/plugin nofollow +./craft plugin/install nofollow ``` +You can also install the plugin via the Plugin Store in the Craft Control Panel. + ## Configuration Add the new plugin to your Redactor config file: ```json { - "plugins": ["nofollow"] + "plugins": [ + "nofollow" + ] +} +``` + +You can configure whether the checkbox in the link dialog should be checked by default when adding a new link. Just add the following config to your Redactor config file: + +```json +{ + "linkDefaultNoFollow": true } ``` @@ -37,7 +51,9 @@ The ```nofollow``` will be stripped in all Redactor fields by the HTMLPurifier, ```json { - "Attr.AllowedRel": ["nofollow"] + "Attr.AllowedRel": [ + "nofollow" + ] } ``` diff --git a/composer.json b/composer.json index d064fac..8033a3d 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "codemonauts/craft-redactor-nofollow", "description": "Craft CMS plugin to extends the Redactor's link module with the nofollow relationship attribute.", - "version": "2.0.0", + "version": "2.1.0", "type": "craft-plugin", "keywords": [ "craft", @@ -24,8 +24,8 @@ "issues": "https://github.com/codemonauts/craft-redactor-nofollow/issues" }, "require": { - "craftcms/cms": "^4.0.0-alpha.1", - "craftcms/redactor": "^3.0.0-beta.1" + "craftcms/cms": "^4.0.0", + "craftcms/redactor": "^3.0.0" }, "autoload": { "psr-4": { diff --git a/src/Nofollow.php b/src/Nofollow.php index 7651acc..412ef17 100644 --- a/src/Nofollow.php +++ b/src/Nofollow.php @@ -4,6 +4,7 @@ use Craft; use craft\base\Plugin; +use craft\redactor\events\ModifyRedactorConfigEvent; use craft\redactor\events\RegisterPluginPathsEvent; use craft\redactor\Field; use yii\base\Event; @@ -17,13 +18,16 @@ public function init() { parent::init(); - if (Craft::$app->request->isCpRequest) { + if (Craft::$app->getRequest()->getIsCpRequest()) { // Register Plugin Path Event::on(Field::class, Field::EVENT_REGISTER_PLUGIN_PATHS, function (RegisterPluginPathsEvent $event) { - $event->paths[] = __DIR__ . '/resources/'; + $event->paths[] = Craft::getAlias('@codemonauts/nofollow/resources'); }); - Field::registerRedactorPlugin('nofollow'); + // Register config + Event::on(Field::class, Field::EVENT_DEFINE_REDACTOR_CONFIG, function (ModifyRedactorConfigEvent $event) { + $event->config['linkDefaultNoFollow'] = $event->config['linkDefaultNoFollow'] ?? false; + }); } } } diff --git a/src/resources/nofollow.js b/src/resources/nofollow.js index 367a7e0..c330b67 100644 --- a/src/resources/nofollow.js +++ b/src/resources/nofollow.js @@ -92,7 +92,7 @@ text: linkData.text, title: linkData.title, target: (this.opts.linkTarget || linkData.target), - nofollow: linkData.nofollow + nofollow: linkData.url === null ? this.opts.linkDefaultNoFollow : linkData.nofollow }; if (!this.opts.linkNewTab) $modal.find('.form-item-target').hide();