Skip to content
Snippets Groups Projects
Commit 97c09fee authored by Carlos Gomez's avatar Carlos Gomez Committed by Carlos Gomez
Browse files

Issue #3000552 by Renrhaf, vishalkhode, yrocq, umirtma, Krzysztof Domański,...

Issue #3000552 by Renrhaf, vishalkhode, yrocq, umirtma, Krzysztof Domański, cgomezg: Entity browser fields giving error when clicked on add new or add existing button
parent 341b18d6
Branches
Tags
1 merge request!6Issue #3288790: Automated Drupal 10 compatibility fixes
......@@ -171,24 +171,19 @@ class NodeTitleConstraintValidator extends ConstraintValidator implements Contai
}
if ($config_key == 'unique-' . $node_type || $config_key == 'unique') {
if ($config_value == 1) {
$titleExists = FALSE;
// Get existing nodes with same title and type.
$nodes = $nodeStorage->loadByProperties([
'title' => $value_title,
'type' => $node_type,
]);
if (!empty($nodes)) {
$titleExists = TRUE;
if (!$node->isNew() && $node->getTitle() === $value_title) {
// If title is the current node one, do not display error.
$titleExists = FALSE;
}
// Unique node title for all content types('unique')
$properties = ['title' => $value_title];
if ($config_key == 'unique-' . $node_type) {
// Unique node title for one content type('unique-')
$properties['type'] = $node_type;
}
$nodes = $nodeStorage->loadByProperties($properties);
// Remove current node form list
if (isset($nodes[$node->id()])) {
unset($nodes[$node->id()]);
}
// Show error.
if ($titleExists) {
if (!empty($nodes)) {
$message = $this->t("The title must be unique. Other content is already using this title: @title", ['@title' => $value_title]);
$this->context->addViolation($message);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment