summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchrisgross2018-01-26 19:41:52 (GMT)
committerjoseph.olstad2018-01-26 19:41:52 (GMT)
commit240c9d8a37d1d2aae2d73efc915fd1b4dd11720c (patch)
tree2601843a0a355db77cf7d6ddc30a6bb295f0d729
parent12602390f58ac642dbe5bb0d4db20e54a0384919 (diff)
Issue #2297685 by chrisgross, peterx: Edit URI for remote files
-rw-r--r--modules/media_internet/media_internet.module44
1 files changed, 44 insertions, 0 deletions
diff --git a/modules/media_internet/media_internet.module b/modules/media_internet/media_internet.module
index a6bf5f2..f6fd11f 100644
--- a/modules/media_internet/media_internet.module
+++ b/modules/media_internet/media_internet.module
@@ -321,3 +321,47 @@ function media_internet_add_submit($form, &$form_state) {
$form_state['storage']['upload'] = $file->fid;
}
}
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ */
+function media_internet_form_file_entity_edit_alter(&$form, &$form_state) {
+ if (!empty($form['#entity'])) {
+ $embed_code = file_create_url($form['#entity']->uri);
+
+ try {
+ $provider = get_class(media_internet_get_provider($embed_code));
+ }
+ catch (Exception $e) {
+ form_set_error('embed_code', $e->getMessage());
+ $provider = NULL;
+ }
+ if (!empty($provider) && $provider != 'MediaInternetFileHandler') {
+ $form['embed_code'] = array(
+ '#type' => 'textfield',
+ '#title' => t('File URL'),
+ '#description' => t('Enter the URL of this file.'),
+ '#attributes' => array('class' => array('media-add-from-url')),
+ '#maxlength' => 2083,
+ '#required' => TRUE,
+ '#default_value' => $embed_code,
+ );
+
+ $form['#validators'] = array();
+
+ array_unshift($form['actions']['submit']['#validate'], 'media_internet_add_validate');
+ array_unshift($form['actions']['submit']['#submit'], 'media_internet_edit_submit');
+ }
+ }
+}
+
+/**
+ * Submit callback that updates managed file URI.
+ */
+function media_internet_edit_submit($form, &$form_state) {
+ $embed_code = $form_state['values']['embed_code'];
+ $provider = get_class(media_internet_get_provider($embed_code));
+ $handler = new $provider($embed_code);
+
+ $form_state['values']['uri'] = $handler->parse($embed_code);
+}