Skip to content

Commit

Permalink
Fix node issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ilestis committed Mar 31, 2023
1 parent 0b8321a commit 2d12866
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
14 changes: 12 additions & 2 deletions app/Models/Concerns/Nested.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions app/Services/EntityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
5 changes: 3 additions & 2 deletions lang/en/crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down

0 comments on commit 2d12866

Please sign in to comment.