Answers.Body: <p>At the moment, your are overriding <code>$event-&gt;linkOptions</code> which contains an array with all options to an empty array with <code>$event-&gt;linkOptions = []</code>.</p>
  <p>First, add the below to your module and refresh any page on your site so you see what you are working with:</p>
  <pre class="lang-php prettyprint-override"><code>Event::on(
    RedactorField::class,
    RedactorField::EVENT_REGISTER_LINK_OPTIONS,
    function(RegisterLinkOptionsEvent $event) {
  
      Craft::dd($event-&gt;linkOptions);
    }
  );
  </code></pre>
  <p>In the array you saw above, you want to remove the object containing a <code>'elementType' =&gt; 'craft\\elements\\Category'</code>.</p>
  <p>You can do this by searching <code>$event-&gt;linkOptions</code> for <code>craft\\elements\\Category</code>, remove it but still returning the rest of the options.</p>
  <p>Here's one way of doing so:</p>
  <pre class="lang-php prettyprint-override"><code>Event::on(
      \craft\redactor\Field::class,
      \craft\redactor\Field::EVENT_REGISTER_LINK_OPTIONS,
      function(\craft\Redactor\events\RegisterLinkOptionsEvent $event) {
          $defaultOptions = $event-&gt;linkOptions;
  
          // Search for category element
          $categoryLink = \craft\helpers\ArrayHelper::where($defaultOptions, 'elementType', 'craft\\elements\\Category');
  
          // If present, remove the option and return the rest
          $event-&gt;linkOptions = \craft\helpers\ArrayHelper::without($defaultOptions, key($categoryLink));
      }
  );
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-15T16:28:06.883Z
Answers.Text: That works, and learned a bit more about setting op a Module, thanks!
Answers.UserDisplayName: noregt
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-15T12:24:53.170Z
Answers.LastActivityDate: 2021-03-15T12:24:53.170Z
Answers.UserDisplayName: Oli
Body: <p>This is a follow up from <a href="https://craftcms.stackexchange.com/questions/17567/how-to-remove-link-to-category-from-redactor">How to remove Link To Category from Redactor</a>.</p>
  <p>I've been able to setup the module and remove all links with this:</p>
  <pre><code>Event::on(
    RedactorField::class,
    RedactorField::EVENT_REGISTER_LINK_OPTIONS,
    function(RegisterLinkOptionsEvent $event) {
  
            $event-&gt;linkOptions = [];
    }
  );
  </code></pre>
  <p>Which removes all Craft links, but how do I remove the categories links only?</p>
  
Tags: <plugin-development><redactor><modules>
Title: How to remove category link from redactor links but leave assets and entry link
ThreadText: # How to remove category link from redactor links but leave assets and entry link
  
  (Asked by: username_0 on 2021-03-15)
  
  This is a follow up from [How to remove Link To Category from Redactor](https://craftcms.stackexchange.com/questions/17567/how-to-remove-link-to-category-from-redactor).
  
  I've been able to setup the module and remove all links with this:
  
  ```
  Event::on(
    RedactorField::class,
    RedactorField::EVENT_REGISTER_LINK_OPTIONS,
    function(RegisterLinkOptionsEvent $event) {
  
            $event->linkOptions = [];
    }
  );
  
  ```
  
  Which removes all Craft links, but how do I remove the categories links only?
  
  **Tags:** plugin-development, redactor, modules
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-03-15. Score: 2 | Accepted answer
  
  At the moment, your are overriding `$event->linkOptions` which contains an array with all options to an empty array with `$event->linkOptions = []`.
  
  First, add the below to your module and refresh any page on your site so you see what you are working with:
  
  ```php
  Event::on(
    RedactorField::class,
    RedactorField::EVENT_REGISTER_LINK_OPTIONS,
    function(RegisterLinkOptionsEvent $event) {
  
      Craft::dd($event->linkOptions);
    }
  );
  
  ```
  
  In the array you saw above, you want to remove the object containing a `'elementType' => 'craft\\elements\\Category'`.
  
  You can do this by searching `$event->linkOptions` for `craft\\elements\\Category`, remove it but still returning the rest of the options.
  
  Here's one way of doing so:
  
  ```php
  Event::on(
      \craft\redactor\Field::class,
      \craft\redactor\Field::EVENT_REGISTER_LINK_OPTIONS,
      function(\craft\Redactor\events\RegisterLinkOptionsEvent $event) {
          $defaultOptions = $event->linkOptions;
  
          // Search for category element
          $categoryLink = \craft\helpers\ArrayHelper::where($defaultOptions, 'elementType', 'craft\\elements\\Category');
  
          // If present, remove the option and return the rest
          $event->linkOptions = \craft\helpers\ArrayHelper::without($defaultOptions, key($categoryLink));
      }
  );
  
  ```
  
  > **Comments:**
  > **username_0**: That works, and learned a bit more about setting op a Module, thanks!  
  
  ---
  
  