Link to unique content

Created on 13 October 2021, over 2 years ago
Updated 20 September 2023, 9 months ago

Problem/Motivation

We wanted an easy way to see which content had already used a unique title, so we added a link on the node title in the error message.

Steps to reproduce

Configure this module to have unique content titles. Submit a new piece of content with a conflicting title.

Proposed resolution

diff --git a/src/Plugin/Validation/Constraint/NodeTitleConstraintValidator.php b/src/Plugin/Validation/Constraint/NodeTitleConstraintValidator.php
index 3fb9e391f..322f8553d 100644
--- a/src/Plugin/Validation/Constraint/NodeTitleConstraintValidator.php
+++ b/src/Plugin/Validation/Constraint/NodeTitleConstraintValidator.php
@@ -184,7 +184,7 @@ public function validate($items, Constraint $constraint) {
           }
           // Show error.
           if (!empty($nodes)) {
-            $message = $this->t("The title must be unique. Other content is already using this title: @title", ['@title' => $value_title]);
+            $message = $this->t("The title must be unique. Other content is already using this title: <a href='@nodeurl'>@title</a>", ['@nodeurl'=> reset($nodes)->toUrl()->toString(), '@title' => $value_title]);
             $this->context->addViolation($message);
           }
         }

Remaining tasks

testing?

User interface changes

Adds a link to the content that already has a unique title

API changes

None.

Data model changes

None.

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States realgt

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.

  • First commit to issue fork.
Production build 0.69.0 2024