Skip to content

Commit

Permalink
[5.x] Fix error when deleting collections (#10908)
Browse files Browse the repository at this point in the history
Co-authored-by: duncanmcclean <[email protected]>
Co-authored-by: Jason Varga <[email protected]>
  • Loading branch information
3 people authored Oct 11, 2024
1 parent 5757396 commit 3bae31d
Show file tree
Hide file tree
Showing 31 changed files with 14 additions and 52 deletions.
12 changes: 0 additions & 12 deletions resources/js/components/collections/Listing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@
:actions="collection.actions"
@completed="actionCompleted"
></data-list-inline-actions>
<dropdown-item
v-if="collection.deleteable"
:text="__('Delete Collection')"
class="warning"
@click="$refs[`deleter_${collection.id}`].confirm()"
>
<resource-deleter
:ref="`deleter_${collection.id}`"
:resource="collection"
@deleted="removeRow(collection)">
</resource-deleter>
</dropdown-item>
</dropdown-list>
</template>
</data-list-table>
Expand Down
1 change: 0 additions & 1 deletion resources/lang/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@
"Delete": "حذف",
"Delete :resource": "حذف :resource",
"Delete child entry|Delete :count child entries": "حذف الإدخال الفرعي|حذف :count الإدخالات الفرعية",
"Delete Collection": "حذف المجموعة",
"Delete Column": "حذف العمود",
"Delete Container": "حذف الحاوية",
"Delete Entry": "حذف الإدخال",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/az.json
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@
"Delete": "Sil",
"Delete :resource": "Bunu sil: :resource",
"Delete child entry|Delete :count child entries": "Uşaq girişi sil|:count uşaq girişi sil",
"Delete Collection": "Kolleksiyanı Sil",
"Delete Column": "Sütunu Sil",
"Delete Container": "Konteyneri Sil",
"Delete Entry": "Girişi Sil",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@
"Delete": "Smazat",
"Delete :resource": "Smazat :resource",
"Delete child entry|Delete :count child entries": "Smazat podzáznam|Smazat :count podzáznamů",
"Delete Collection": "Smazat kolekci",
"Delete Column": "Smazat sloupec",
"Delete Container": "Smazat kontejner",
"Delete Entry": "Smazat záznam",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
"Delete": "Slet",
"Delete :resource": "Slet :resource",
"Delete child entry|Delete :count child entries": "Slet underordnet post | Slet :count underordnede poster",
"Delete Collection": "Slet samling",
"Delete Column": "Slet kolonne",
"Delete Container": "Slet beholder",
"Delete Entry": "Slet post",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@
"Delete": "Löschen",
"Delete :resource": ":resource löschen",
"Delete child entry|Delete :count child entries": "Untergeordneten Eintrag löschen|:count untergeordnete Einträge löschen",
"Delete Collection": "Sammlung löschen",
"Delete Column": "Spalte löschen",
"Delete Container": "Container löschen",
"Delete Entry": "Eintrag löschen",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/de_CH.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@
"Delete": "Löschen",
"Delete :resource": ":resource löschen",
"Delete child entry|Delete :count child entries": "Untergeordneten Eintrag löschen|:count untergeordnete Einträge löschen",
"Delete Collection": "Sammlung löschen",
"Delete Column": "Spalte löschen",
"Delete Container": "Container löschen",
"Delete Entry": "Eintrag löschen",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
"Delete": "Eliminar",
"Delete :resource": "Eliminar :resource",
"Delete child entry|Delete :count child entries": "Eliminar entrada interna|Eliminar :count entradas internas",
"Delete Collection": "Eliminar colección",
"Delete Column": "Eliminar columna",
"Delete Container": "Eliminar contenedor",
"Delete Entry": "Eliminar entrada",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@
"Delete": "حذف",
"Delete :resource": "حذف :resource",
"Delete child entry|Delete :count child entries": "حذف مطلب فرزند|حذف :count مطلب فرزند",
"Delete Collection": "حذف کالکشن",
"Delete Column": "حذف ستون",
"Delete Container": "حذف کانتینر",
"Delete Entry": "حذف مطلب",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@
"Delete": "Supprimer",
"Delete :resource": "Supprimer :resource",
"Delete child entry|Delete :count child entries": "Supprimer l'entrée enfant|Supprimer :count entrées enfants",
"Delete Collection": "Supprimer la collection",
"Delete Column": "Supprimer la colonne",
"Delete Container": "Supprimer le conteneur",
"Delete Entry": "Supprimer l'entrée",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@
"Delete": "Töröl",
"Delete :resource": ":resource törlése",
"Delete child entry|Delete :count child entries": "Gyermek bejegyzés törlése|:count gyermek bejegyzés törlése",
"Delete Collection": "Gyűjtemény törlése",
"Delete Column": "Oszlop törlése",
"Delete Container": "Tároló törlése",
"Delete Entry": "Bejegyzés törlése",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
"Delete": "Hapus",
"Delete :resource": "Hapus :resource",
"Delete child entry|Delete :count child entries": "Hapus entri anak|Hapus :count entru anak",
"Delete Collection": "Hapus Koleksi",
"Delete Column": "Hapus Kolom",
"Delete Container": "Hapus Penampung",
"Delete Entry": "Hapus Entri",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
"Delete": "Elimina",
"Delete :resource": "Elimina :resource",
"Delete child entry|Delete :count child entries": "Elimina voce figlio|Elimina :count voci figlio",
"Delete Collection": "Elimina raccolta",
"Delete Column": "Elimina colonna",
"Delete Container": "Elimina contenitore",
"Delete Entry": "Elimina voce",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@
"Delete": "消去",
"Delete :resource": "削除:resource",
"Delete child entry|Delete :count child entries": "子エントリの削除| :countの子エントリを削除",
"Delete Collection": "コレクションの削除",
"Delete Column": "列の削除",
"Delete Container": "コンテナの削除",
"Delete Entry": "記入を消す",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/ms.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
"Delete": "Hapus",
"Delete :resource": "Hapus :resource",
"Delete child entry|Delete :count child entries": "Hapus entri anak|Hapus :count entri anak",
"Delete Collection": "Hapus Koleksi",
"Delete Column": "Hapus Lajur",
"Delete Container": "Hapus Penampung",
"Delete Entry": "Hapus Entri",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@
"Delete": "Slett",
"Delete :resource": "Slett :resource",
"Delete child entry|Delete :count child entries": "Slett underordnet oppføring|Slett :count underordnede oppføringer",
"Delete Collection": "Slett samling",
"Delete Column": "Slett kolonne",
"Delete Container": "Slett beholder",
"Delete Entry": "Slett oppføring",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@
"Delete": "Verwijderen",
"Delete :resource": "Verwijder :resource",
"Delete child entry|Delete :count child entries": "Verwijder child entry|Verwijder :count child entries",
"Delete Collection": "Verwijderd collectie",
"Delete Column": "Verwijderd kolom",
"Delete Container": "Verwijder container",
"Delete Entry": "Verwijder entry",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@
"Delete": "Usuń",
"Delete :resource": "Usuń :resource",
"Delete child entry|Delete :count child entries": "Usuń podrzędnyrekord|Usuń :count rekordy/ów podrzędne",
"Delete Collection": "Usuń kolekcję",
"Delete Column": "Usuń kolumnę",
"Delete Container": "Usuń kontener",
"Delete Entry": "Usuń rekord",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
"Delete": "Eliminar",
"Delete :resource": "Eliminar :resource",
"Delete child entry|Delete :count child entries": "Eliminar entrada-filho:Eliminar :count entrada(s)-filho(s)",
"Delete Collection": "Eliminar Coleção",
"Delete Column": "Eliminar Coluna",
"Delete Container": "Eliminar Biblioteca",
"Delete Entry": "Eliminar Entrada",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@
"Delete": "Excluir",
"Delete :resource": "Excluir :resource",
"Delete child entry|Delete :count child entries": "Excluir entrada-filha|Excluir :count entradas-filhas",
"Delete Collection": "Excluir Coleção",
"Delete Column": "Exlucir Coluna",
"Delete Container": "Excluir Contêiner",
"Delete Entry": "Excluir Entrada",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@
"Delete": "Удалить",
"Delete :resource": "Удалить :resource",
"Delete child entry|Delete :count child entries": "Удалить дочернюю запись|Удалить :count дочерние записи|Удалить :count дочерних записей",
"Delete Collection": "Удалить коллекцию",
"Delete Column": "Удалить столбец",
"Delete Container": "Удалить контейнер",
"Delete Entry": "Удалить запись",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/sl.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
"Delete": "Izbriši",
"Delete :resource": "Izbriši :resource",
"Delete child entry|Delete :count child entries": "Izbriši podrejeni vnos | Izbriši :count podrejene vnose",
"Delete Collection": "Izbriši zbirko",
"Delete Column": "Izbriši stolpec",
"Delete Container": "Izbriši vsebnik",
"Delete Entry": "Izbriši vnos",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@
"Delete": "Radera",
"Delete :resource": "Radera :resource",
"Delete child entry|Delete :count child entries": "Radera underordnat inlägg|Radera :count underordnade inlägg",
"Delete Collection": "Radera samling",
"Delete Column": "Radera kolumn",
"Delete Container": "Radera behållare",
"Delete Entry": "Radera inlägg",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@
"Delete": "Sil",
"Delete :resource": ":resource sil",
"Delete child entry|Delete :count child entries": "Alt girdiyi sil|:count alt girdiyi sil",
"Delete Collection": "Koleksiyonu Sil",
"Delete Column": "Sütunu Sil",
"Delete Container": "Konteyneri Sil",
"Delete Entry": "Girişi Sil",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@
"Delete": "Видалити",
"Delete :resource": "Видалити :resource",
"Delete child entry|Delete :count child entries": "Видалити дочірній запис|Видалити :count дочірніх записів",
"Delete Collection": "Видалити колекцію",
"Delete Column": "Видалити стовпець",
"Delete Container": "Видалити контейнер",
"Delete Entry": "Видалити запис",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@
"Delete": "删除",
"Delete :resource": "删除 :resource",
"Delete child entry|Delete :count child entries": "删除子条目|删除 :count 子条目",
"Delete Collection": "删除条目集合",
"Delete Column": "删除列",
"Delete Container": "删除容器",
"Delete Entry": "删除条目",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/zh_TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@
"Delete": "刪除",
"Delete :resource": "刪除 :resource",
"Delete child entry|Delete :count child entries": "刪除子條目|刪除 :count 個子條目",
"Delete Collection": "刪除條目集",
"Delete Column": "刪除欄位",
"Delete Container": "刪除容器",
"Delete Entry": "刪除條目",
Expand Down
11 changes: 0 additions & 11 deletions resources/views/collections/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,6 @@
:actions="{{ $actions }}"
@completed="actionCompleted"
></data-list-inline-actions>
@can('delete', $collection)
<dropdown-item :text="__('Delete Collection')" class="warning" @click="$refs.deleter.confirm()">
<resource-deleter
ref="deleter"
resource-title="{{ $collection->title() }}"
route="{{ cp_route('collections.destroy', $collection->handle()) }}"
redirect="{{ cp_route('collections.index') }}"
></resource-deleter>
</dropdown-item>
@endcan

</template>
@endif
</collection-view>
Expand Down
11 changes: 11 additions & 0 deletions src/Actions/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function visibleTo($item)
case $item instanceof Contracts\Entries\Entry && $item->collection()->sites()->count() === 1:
return ! $item->page()?->isRoot();
break;
case $item instanceof Contracts\Entries\Collection:
case $item instanceof Contracts\Taxonomies\Term:
case $item instanceof Contracts\Assets\Asset:
case $item instanceof Contracts\Assets\AssetFolder:
Expand Down Expand Up @@ -52,6 +53,14 @@ public function confirmationText()
return 'Are you sure you want to delete this?|Are you sure you want to delete these :count items?';
}

public function warningText()
{
if ($this->items->first() instanceof Contracts\Entries\Collection) {
/** @translation */
return 'This will delete the collection and all of its entries.|This will delete the collections and all of their entries.';
}
}

public function bypassesDirtyWarning(): bool
{
return true;
Expand Down Expand Up @@ -85,6 +94,8 @@ public function redirect($items, $values)
$item = $items->first();

switch (true) {
case $item instanceof Contracts\Entries\Collection:
return cp_route('collections.index');
case $item instanceof Contracts\Entries\Entry:
return cp_route('collections.show', $item->collection()->handle());
case $item instanceof Contracts\Taxonomies\Term:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function show(Request $request, $collection)
->all(),
'canCreate' => User::current()->can('create', [EntryContract::class, $collection]) && $collection->hasVisibleEntryBlueprint(),
'canChangeLocalizationDeleteBehavior' => count($authorizedSites) > 1 && (count($authorizedSites) == $collection->sites()->count()),
'actions' => Action::for($collection),
'actions' => Action::for($collection, ['view' => 'form']),
];

if ($collection->queryEntries()->count() === 0) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Collections/ViewCollectionListingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function it_shows_a_list_of_collections()
'editable' => true,
'blueprint_editable' => true,
'available_in_selected_site' => true,
'actions' => collect(),
'actions' => Facades\Action::for($collectionA, ['view' => 'list']),
'actions_url' => 'http://localhost/cp/collections/foo/actions',
],
[
Expand All @@ -61,7 +61,7 @@ public function it_shows_a_list_of_collections()
'editable' => true,
'blueprint_editable' => true,
'available_in_selected_site' => true,
'actions' => collect(),
'actions' => Facades\Action::for($collectionB, ['view' => 'list']),
'actions_url' => 'http://localhost/cp/collections/bar/actions',
],
]))
Expand Down

0 comments on commit 3bae31d

Please sign in to comment.