Skip to content

Commit

Permalink
applied feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
yeniatencio committed Dec 19, 2024
1 parent ce09a15 commit 1d65d1f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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().
*/
Expand All @@ -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();
}
32 changes: 0 additions & 32 deletions modules/tide_media/tide_media.install
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

0 comments on commit 1d65d1f

Please sign in to comment.