diff --git a/app/Models/Concerns/Nested.php b/app/Models/Concerns/Nested.php index 5e15d41ec9..d1e89980d9 100644 --- a/app/Models/Concerns/Nested.php +++ b/app/Models/Concerns/Nested.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Http\Client\RequestException; use Illuminate\Support\Arr; use Kalnoy\Nestedset\AncestorsRelation; use Kalnoy\Nestedset\Collection; @@ -1231,7 +1232,12 @@ protected function dirtyBounds() protected function assertNotDescendant(self $node) { if ($node == $this || $node->isDescendantOf($this)) { - throw new LogicException('Node must not be a descendant.'); + $field = $node->getParentIdName(); + $error = \Illuminate\Validation\ValidationException::withMessages([ + $field => [__('crud.errors.node_must_not_be_a_descendant')] + ]); + throw $error; + //throw new LogicException('Node must not be a descendant.'); } return $this; @@ -1245,7 +1251,11 @@ protected function assertNotDescendant(self $node) protected function assertNodeExists(self $node) { if (! $node->getLft() || ! $node->getRgt()) { - throw new LogicException('Node must exists.'); + $field = $node->getParentIdName(); + $error = \Illuminate\Validation\ValidationException::withMessages([ + $field => [__('crud.errors.invalid_node')] + ]); + throw $error; } return $this; diff --git a/app/Services/EntityService.php b/app/Services/EntityService.php index 9cac08f2dc..3d7a1dd209 100644 --- a/app/Services/EntityService.php +++ b/app/Services/EntityService.php @@ -685,6 +685,12 @@ public function makeNewMentionEntity(MiscModel $model, string $name) $model->name = $name; $model->is_private = $defaultPrivate; $model->campaign_id = $campaign->id; + + // If the modal is a tree, it needs to be placed in its own bounds + if (method_exists($model, 'makeRoot')) { + $model->recalculateTreeBounds(); + } + $model->saveQuietly(); $model->createEntity(); if (!$model->entity->isTag()) { diff --git a/lang/en/crud.php b/lang/en/crud.php index dc4dd1cc22..04e01252d4 100644 --- a/lang/en/crud.php +++ b/lang/en/crud.php @@ -115,9 +115,10 @@ 'errors' => [ 'boosted' => 'This feature is only available to boosted campaigns.', 'boosted_campaigns' => 'This feature is only available for :boosted.', - 'cannot_move_node_into_itself' => 'The selected parent entity is invalid. This could be due to it having this entity as the parent.', - 'node_must_not_be_a_descendant' => 'Invalid node (tag, parent location): it would be a descendant of itself.', + //'cannot_move_node_into_itself' => 'The selected parent is invalid. This could be due to it having this entity as the parent.', + 'node_must_not_be_a_descendant' => 'The selected parent is invalid. It would be a descendant of itself.', 'unavailable_feature' => 'Unavailable feature', + 'invalid_node' => 'The selected parent is invalid. This can usually be fixed by giving the selected parent a parent of its own, then removing it.', ], 'export' => 'Export', 'fields' => [