Skip to content

Commit 95a2b51

Browse files
Merge branch 'fix-terms'
2 parents 1b136bc + d4e780c commit 95a2b51

4 files changed

+12
-2
lines changed

src/EntryRelationship.php

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class EntryRelationship
1414
public $leftType = '';
1515
public $rightType = '';
1616

17+
public $taxonomyName = '';
18+
1719
public $index = 0;
1820
public $type = self::TYPE_MANY_TO_MANY;
1921
public $leftCollection = '';

src/Listeners/TermDeletedListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function handle(TermDeleted $event)
2727
return;
2828
}
2929

30-
$relationships = $this->manager->getAllTermRelationships();
30+
$relationships = $this->manager->getTermRelationshipsFor($term->taxonomy()->handle());
3131

3232
$this->manager->processor()->setIsDeleting()->setEntryId($term->slug())
3333
->setPristineDetails($term, false)->process($relationships);

src/Listeners/TermSavedListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function handle(TermSaved $event)
2727

2828
$this->manager->processor()->setUpdatedEntryDetails($term);
2929

30-
$relationships = $this->manager->getAllTermRelationships();
30+
$relationships = $this->manager->getTermRelationshipsFor($term->taxonomy()->handle());
3131

3232
$this->manager->processor()->process($relationships);
3333
}

src/RelationshipManager.php

+8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function term($termName)
7878
$relationship->leftType = 'term';
7979
$relationship->leftField = $termName;
8080
$relationship->leftCollection = '[term]';
81+
$relationship->taxonomyName = $termName;
8182

8283
if (! array_key_exists('terms', $this->relationships)) {
8384
$this->relationships['terms'] = [];
@@ -351,6 +352,13 @@ public function getAllTermRelationships()
351352
return $this->getEntityTypeRelationships('terms');
352353
}
353354

355+
public function getTermRelationshipsFor($term)
356+
{
357+
return collect($this->getAllTermRelationships())->filter(function (EntryRelationship $relationship) use ($term) {
358+
return $relationship->leftType == 'term' && $relationship->taxonomyName == $term;
359+
})->all();
360+
}
361+
354362
public function getAllRelationships()
355363
{
356364
$relationships = [];

0 commit comments

Comments
 (0)