From 7d066a8abc877d80c3c650e95aa568ad02018609 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Renato=20Gon=C3=A7alves=20H?=
 <34697-renatog@users.noreply.drupalcode.org>
Date: Fri, 3 Mar 2023 00:35:52 -0300
Subject: [PATCH] Issue #3345645: Implement the hook_update to make the link
 field required by default on existing sites

---
 ebt_bootstrap_button.install | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 ebt_bootstrap_button.install

diff --git a/ebt_bootstrap_button.install b/ebt_bootstrap_button.install
new file mode 100644
index 0000000..fb17917
--- /dev/null
+++ b/ebt_bootstrap_button.install
@@ -0,0 +1,30 @@
+<?php
+
+/**
+ * @file
+ * Install, update and uninstall logic for EBT Bootstrap Button.
+ */
+
+use Drupal\field\Entity\FieldConfig;
+
+/**
+ * Set the field "field_ebt_bootstrap_button_link" as required.
+ */
+function ebt_bootstrap_button_update_9101() {
+
+  // Set the machine names.
+  $block_type_id = 'ebt_bootstrap_button';
+  $field_name = 'field_ebt_bootstrap_button_link';
+
+  // Load the field configuration object.
+  $field_config = FieldConfig::loadByName('block_content', $block_type_id, $field_name);
+
+  // If the field doesn't exists, skip.
+  if (empty($field_config)) {
+    return;
+  }
+
+  // Set the field as required.
+  $field_config->setRequired(TRUE)->save();
+
+}
-- 
GitLab