From 1d65d1f5579bc9b2c3da17cee9682a0b64f6afc8 Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Fri, 20 Dec 2024 07:32:44 +1100 Subject: [PATCH] applied feedback --- ...wser.browser.tide_media_browser_iframe.yml | 11 ----- .../tide_media_secure_files.install | 43 +++++++++++++++++++ modules/tide_media/tide_media.install | 32 -------------- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/config/install/entity_browser.browser.tide_media_browser_iframe.yml b/config/install/entity_browser.browser.tide_media_browser_iframe.yml index 3d0c10b9d..700578524 100644 --- a/config/install/entity_browser.browser.tide_media_browser_iframe.yml +++ b/config/install/entity_browser.browser.tide_media_browser_iframe.yml @@ -69,14 +69,3 @@ widgets: weight: -9 label: 'Add audio' id: entity_form - 514a147d-5e8c-4006-8bdd-6959b6239548: - id: entity_form - uuid: 514a147d-5e8c-4006-8bdd-6959b6239548 - label: 'Add secure file' - weight: 6 - settings: - submit_text: 'Save secure file' - entity_type: media - bundle: secure_file - form_mode: default - diff --git a/modules/tide_media/modules/tide_media_secure_files/tide_media_secure_files.install b/modules/tide_media/modules/tide_media_secure_files/tide_media_secure_files.install index ccf9536a8..a46459b65 100644 --- a/modules/tide_media/modules/tide_media_secure_files/tide_media_secure_files.install +++ b/modules/tide_media/modules/tide_media_secure_files/tide_media_secure_files.install @@ -52,6 +52,40 @@ function tide_media_secure_files_uninstall() { \Drupal::service('module_installer')->uninstall(['pfdp']); } +/** + * Adds a secure file widget to entity browser. + * + * @return void + */ +function _create_secure_file_widget() { + if (\Drupal::moduleHandler()->moduleExists('entity_browser')) { + $uuid = \Drupal::service('uuid')->generate(); + $secure_file_widget = [ + 'id' => 'entity_form', + 'uuid' => $uuid, + 'label' => 'Add secure file', + 'weight' => 6, + 'settings' => [ + 'submit_text' => 'Save secure file', + 'entity_type' => 'media', + 'bundle' => 'secure_file', + 'form_mode' => 'default', + ], + ]; + + $config = \Drupal::configFactory()->getEditable('entity_browser.browser.tide_media_browser_iframe'); + $widgets = $config->get('widgets'); + if (!is_array($widgets)) { + $widgets = []; + } + if (!in_array($secure_file_widget, $widgets)) { + $widgets[$uuid] = $secure_file_widget; + $config->set('widgets', $widgets); + $config->save(); + } + } +} + /** * Implements hook_install(). */ @@ -71,4 +105,13 @@ function tide_media_secure_files_install() { user_role_grant_permissions($role->id(), ['view field_secure_file']); } } + + _create_secure_file_widget(); +} + +/** + * Adds secure file widget to entity browser. + */ +function tide_media_secure_files_update_10001() { + _create_secure_file_widget(); } diff --git a/modules/tide_media/tide_media.install b/modules/tide_media/tide_media.install index 63029cf7c..dc5a250da 100644 --- a/modules/tide_media/tide_media.install +++ b/modules/tide_media/tide_media.install @@ -81,35 +81,3 @@ function tide_media_update_10005() { $config->set('track_enabled_target_entity_types', $result); $config->save(); } - -/** - * Adds secure file widget to entity browser. - */ -function tide_media_update_10006() { - if (\Drupal::moduleHandler()->moduleExists('tide_media_secure_files')) { - $uuid = \Drupal::service('uuid')->generate(); - $secure_file_widget = [ - 'id' => 'entity_form', - 'uuid' => $uuid, - 'label' => 'Add secure file', - 'weight' => 6, - 'settings' => [ - 'submit_text' => 'Save secure file', - 'entity_type' => 'media', - 'bundle' => 'secure_file', - 'form_mode' => 'default', - ], - ]; - - $config = \Drupal::configFactory()->getEditable('entity_browser.browser.tide_media_browser_iframe'); - $widgets = $config->get('widgets'); - if (!is_array($widgets)) { - $widgets = []; - } - if (!in_array($secure_file_widget, $widgets)) { - $widgets[$uuid] = $secure_file_widget; - $config->set('widgets', $widgets); - $config->save(); - } - } -}