function bynder_upload in Bynder 7
Create a form to add media from Bynder.
2 string references to 'bynder_upload'
- BynderMediaUpload::view in includes/
BynderMediaUpload.inc - Implements MediaBrowserPlugin::view().
- bynder_menu in ./
bynder.module - Implements hook_menu().
File
- includes/
bynder_upload.inc, line 9
Code
function bynder_upload($form, &$form_state) {
unset($_SESSION['bynder_upload_browser']);
$bynderApi = BynderMediaApi::getBynderApi();
$tokens = $bynderApi
->hasAccessToken();
if (!$bynderApi
->hasSettings()) {
$form['message'] = [
'#markup' => t('You haven\'t set up the <a href="' . url(BYNDER_SETTINGS_URL, array(
'absolute' => true,
)) . '" class="oauth-link" target="_blank">Bynder settings</a> properly, please do so before importing assets.'),
'#prefix' => '<p>',
'#suffix' => '</p>',
];
}
elseif (!variable_get('bynder_brand_selected')) {
$form['message'] = [
'#markup' => t('You need to set up the brand associated to file uploads before you can use this functionality:
<a href="' . url(BYNDER_SETTINGS_URL, array(
'absolute' => true,
)) . '" class="oauth-link" target="_blank">Bynder settings</a>.'),
'#prefix' => '<p>',
'#suffix' => '</p>',
];
}
elseif (!$tokens || isset($tokens['isRequestToken'])) {
$form['message'] = [
'#markup' => t('You need to <a href="' . url('bynder-oauth', array(
'absolute' => true,
)) . '" class="oauth-link" target="_blank">log into Bynder</a> before uploading assets.'),
'#prefix' => '<p>',
'#suffix' => '</p>',
];
$form['reload'] = [
'#type' => 'button',
'#value' => 'Reload after submit',
'#attributes' => [
'class' => [
'oauth-reload',
'visually-hidden',
],
],
];
$_SESSION['bynder_oauth_login'] = true;
}
elseif ($bynderApi
->hasUploadPermissions()) {
$form['bynder_dropzone'] = array(
'#type' => 'fieldset',
'#attributes' => array(
'class' => array(
'dropzone',
),
),
);
$form['bynder_dropzone']['bynder_dropzone_url'] = array(
'#type' => 'hidden',
'#value' => url('bynder/upload/process', array(
'absolute' => true,
)),
'#attributes' => array(
'id' => 'bynder-dropzone-url',
),
);
$form_token = drupal_get_token('bynder_upload');
$form['bynder_dropzone']['bynder_form_token'] = array(
'#type' => 'hidden',
'#attributes' => array(
'class' => 'bynder-token',
),
'#value' => $form_token,
);
$form['#attached']['library'][] = array(
'bynder',
'media_dropzone',
);
$form['#attributes'] = array(
'class' => array(
'dropzone-form',
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
'#attributes' => array(
'id' => array(
'dropzone-submit',
),
),
);
}
else {
$form['message'] = [
'#markup' => t("Your account doesn't have enough permissions to upload assets to Bynder"),
];
}
return $form;
}