From 93d0ad1b6dc1bf9f5657dbd1e844fc59fc9a20cc Mon Sep 17 00:00:00 2001
From: Adam Vessey <adam@discoverygarden.ca>
Date: Fri, 13 Jan 2023 15:24:58 -0400
Subject: [PATCH] Index `field_weight`'s value.

---
 .../field.storage.node.field_weight.yml       |  4 +++-
 .../islandora_core_feature.post_update.php    | 20 +++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 modules/islandora_core_feature/islandora_core_feature.post_update.php

diff --git a/modules/islandora_core_feature/config/install/field.storage.node.field_weight.yml b/modules/islandora_core_feature/config/install/field.storage.node.field_weight.yml
index 97619cd2..4976d1d6 100644
--- a/modules/islandora_core_feature/config/install/field.storage.node.field_weight.yml
+++ b/modules/islandora_core_feature/config/install/field.storage.node.field_weight.yml
@@ -14,6 +14,8 @@ module: core
 locked: false
 cardinality: 1
 translatable: true
-indexes: {  }
+indexes:
+  value:
+    - value
 persist_with_no_fields: false
 custom_storage: false
diff --git a/modules/islandora_core_feature/islandora_core_feature.post_update.php b/modules/islandora_core_feature/islandora_core_feature.post_update.php
new file mode 100644
index 00000000..10547231
--- /dev/null
+++ b/modules/islandora_core_feature/islandora_core_feature.post_update.php
@@ -0,0 +1,20 @@
+<?php
+
+/**
+ * @file
+ * Post-update hooks.
+ */
+
+/**
+ * Add index to field_weight.
+ */
+function islandora_core_feature_post_update_add_index_to_field_weight() {
+  $storage = \Drupal::entityTypeManager()->getStorage('field_storage_config');
+  $field = $storage->load('node.field_weight');
+  $indexes = $field->getIndexes();
+  $indexes += [
+    'value' => ['value'],
+  ];
+  $field->setIndexes($indexes);
+  $field->save();
+}