Links to unpublished nodes should be plain text if user access denied.

Created on 16 July 2019, over 5 years ago
Updated 11 August 2024, 5 months ago

It's great that I can add links to unpublished nodes, but it would be really great if the text filter rendered them as plain text until I publish that node.

✨ Feature request
Status

Closed: works as designed

Version

5.0

Component

Code

Created by

πŸ‡³πŸ‡ΏNew Zealand sphism

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Thanks for the suggestion! After careful consideration, I do not think that a plaintext rendering when a node is unpublished is a standard convention, nor that it would be intuitive, nor that most content maintainers would want this behavior (they'd prefer a link that goes to a 403).

    Therefore, I'm going to close this issue, as I do not see this feature being in the module's roadmap.

    If more people in the community feel differently, I'm open to listening!

  • πŸ‡ͺπŸ‡ΈSpain foreveryo

    It would be great to have the option (on the linkit url converter filter) to enable this.

    I think a behaviour that everyone can agree would be that if this new selector is selected that users without access to the unpublished content will just see the anchor text without any link html markup.

    Example:
    <p>Bla bla bla <a href="/url-to-link" data-entity-type="node" data-entity-uuid="2fd2a6d6-9e61-4d51-b916-6297f6ceebb1" data-entity-substitution="canonical" title="Title of the url">anchor text</a> bla bla bla.</p>

    on users without unpublished view permission will just see:
    <p>Bla bla bla anchor text bla bla bla.</p>

    I've made a test (only for anonymous users) on my site modifying the LinkitFilter.php > process():

    if(!$entity->isPublished() && \Drupal::currentUser()->isAnonymous()) {
                  $element->removeAttribute('href');
    
                  // Create new element  <span>
                  $span = $dom->createElement('span', $element->textContent);
    
                  // Copiar attributes from current element to the new span element
                  foreach ($element->attributes as $attr) {
                      $span->setAttribute($attr->name, $attr->value);
                  }
    
                  // Reemplazar link <a> with <span> 
                  $element->parentNode->replaceChild($span, $element);
                  continue;
                }

    The part copying the element attributes might be unnecessary.

Production build 0.71.5 2024