From fe9ab75f7338ccd393b1b3f7dc40eb68db6f2804 Mon Sep 17 00:00:00 2001 From: Jamie White Date: Wed, 18 Jun 2025 10:00:34 +0100 Subject: [PATCH] Add the "multiple" label to collections where appropriate --- src/controllers/CollectionsController.php | 49 ++++++++++++----------- src/jobs/SyncDocumentsJob.php | 4 +- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/controllers/CollectionsController.php b/src/controllers/CollectionsController.php index 426452b..9cbfc4d 100755 --- a/src/controllers/CollectionsController.php +++ b/src/controllers/CollectionsController.php @@ -1,4 +1,5 @@ getSettings()->collections; foreach ($indexes as $index) { + + $nameOverride = false; + if (is_array($index->section)) { + $nameOverride = 'Multiple'; + } + $element = $index->criteria->one(); switch ($index->elementType) { @@ -110,9 +113,9 @@ public function actionCollections(): Response if ($volume) { $variables['sections'][] = [ 'id' => 1, - 'name' => $volume->name, + 'name' => ($nameOverride ? $nameOverride : $volume->name), 'handle' => $volume->handle, - 'type' => 'Asset: ' . $volume->handle, + 'type' => 'Asset: ' . ($nameOverride ? $nameOverride : $volume->handle), 'entryCount' => $index->criteria->count(), 'index' => $index->indexName, ]; @@ -125,9 +128,9 @@ public function actionCollections(): Response if ($section) { $variables['sections'][] = [ 'id' => $section->id, - 'name' => $section->name, + 'name' => ($nameOverride ? $nameOverride : $section->name), 'handle' => $section->handle, - 'type' => 'Entry: ' . $element->type->handle, + 'type' => 'Entry: ' . ($nameOverride ? $nameOverride : $element->type->handle), 'entryCount' => $index->criteria->count(), 'index' => $index->indexName, ]; @@ -140,9 +143,9 @@ public function actionCollections(): Response if ($group) { $variables['sections'][] = [ 'id' => $group->id, - 'name' => $group->name, + 'name' => ($nameOverride ? $nameOverride : $group->name), 'handle' => $group->handle, - 'type' => 'Category: ' . $element->group->handle, + 'type' => 'Category: ' . ($nameOverride ? $nameOverride : $element->group->handle), 'entryCount' => $index->criteria->count(), 'index' => $index->indexName, ]; @@ -154,9 +157,9 @@ public function actionCollections(): Response if ($type) { $variables['sections'][] = [ 'id' => $type->id, - 'name' => $type->name, + 'name' => ($nameOverride ? $nameOverride : $type->name), 'handle' => $type->handle, - 'type' => 'Product: ' . $element->type->handle, + 'type' => 'Product: ' . ($nameOverride ? $nameOverride : $element->type->handle), 'entryCount' => $index->criteria->count(), 'index' => $index->indexName, ]; @@ -168,9 +171,9 @@ public function actionCollections(): Response if ($type) { $variables['sections'][] = [ 'id' => $type->id, - 'name' => $type->name, + 'name' => ($nameOverride ? $nameOverride : $type->name), 'handle' => $type->handle, - 'type' => 'Variant: ' . $type->handle, + 'type' => 'Variant: ' . ($nameOverride ? $nameOverride : $type->handle), 'entryCount' => $index->criteria->count(), 'index' => $index->indexName, ]; @@ -180,9 +183,9 @@ public function actionCollections(): Response case 'craft\shopify\elements\Product': $variables['sections'][] = [ 'id' => 'shopify-products', - 'name' => 'Products', + 'name' => ($nameOverride ? $nameOverride : 'Products'), 'handle' => 'products', - 'type' => 'Shopify: Products', + 'type' => 'Shopify: ' . ($nameOverride ? $nameOverride : 'Products'), 'entryCount' => $index->criteria->count(), 'index' => $index->indexName, ]; @@ -454,13 +457,13 @@ public function actionDocuments(): Response|string // Render the template return $this->renderTemplate('typesense/documents/index', $variables); // $request = Craft::$app->getRequest(); -// $index = $request->getBodyParam('index'); -// -// if (isset(Typesense::$plugin->getClient()->client()->collections[$index])) { -// return $this->asJson(Typesense::$plugin->getClient()->client()->collections[$index]->documents->export()); -// } -// -// return "this index doesn't exist"; + // $index = $request->getBodyParam('index'); + // + // if (isset(Typesense::$plugin->getClient()->client()->collections[$index])) { + // return $this->asJson(Typesense::$plugin->getClient()->client()->collections[$index]->documents->export()); + // } + // + // return "this index doesn't exist"; } /** diff --git a/src/jobs/SyncDocumentsJob.php b/src/jobs/SyncDocumentsJob.php index bb0fc6f..573b280 100755 --- a/src/jobs/SyncDocumentsJob.php +++ b/src/jobs/SyncDocumentsJob.php @@ -1,4 +1,5 @@ criteria['type'] ?? 'Unkown') . ' documents for ' . $this->criteria['index']); + return Craft::t('typesense', ($this->criteria['type'] ?? 'Unknown') . ' documents for ' . $this->criteria['index']); } }