added file download on cartel
This commit is contained in:
@@ -204,7 +204,7 @@ function edlptheme_prepare_audio_link(&$vars){
|
||||
}
|
||||
|
||||
function edlptheme_preprocess_node__enregistrement__player_cartel(&$vars){
|
||||
// dpm($vars);
|
||||
dpm($vars);
|
||||
$node = $vars['node'];
|
||||
|
||||
$vars['col_left'] = false;
|
||||
@@ -249,6 +249,39 @@ function edlptheme_preprocess_node__enregistrement__player_cartel(&$vars){
|
||||
if($vars['col_left'] || $vars['col_right']){
|
||||
$vars['second_cartel'] = true;
|
||||
}
|
||||
|
||||
// get the audio file url
|
||||
$field_son_values = $node->get('field_son')->getValue();
|
||||
$son_fid = count($field_son_values) ? $field_son_values[0]['target_id'] : "";
|
||||
$son_file = \Drupal\file\Entity\File::load($son_fid);
|
||||
if($son_file){
|
||||
$son_uri = $son_file->getFileUri();
|
||||
$son_url = file_create_url($son_uri);
|
||||
|
||||
$base = log($son_file->getSize(), 1024);
|
||||
$suffixes = array('', 'K', 'M', 'G', 'T');
|
||||
$file_size = round(pow(1024, $base - floor($base)), 0) .' '. $suffixes[floor($base)];
|
||||
|
||||
preg_match('/^.*(\.\S+)$/', $son_uri, $matches);
|
||||
$extension = $matches[1];
|
||||
|
||||
$node_title = $node->getTitle();
|
||||
$new_file_name = str_replace(' ', '_', $node_title) . $extension;
|
||||
|
||||
$config = \Drupal::config('system.site');
|
||||
$site_title = str_replace(' ', '_', $config->get('name'));
|
||||
|
||||
$url = Url::fromUri($son_url);
|
||||
$url->setOptions(array(
|
||||
'attributes' => array(
|
||||
'class' => ['link-audio-download'],
|
||||
'download' => $site_title .'__'. $new_file_name,
|
||||
'title' => $new_file_name . ' ('.$file_size.')'
|
||||
)
|
||||
));
|
||||
$vars['link_audio_download'] = Link::fromTextAndUrl(t("Download"), $url);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -285,5 +318,5 @@ function edlptheme_preprocess_links__language_block(&$vars){
|
||||
}
|
||||
|
||||
function edlptheme_preprocess_file_link(&$vars){
|
||||
|
||||
// dpm($vars);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user