refactored edlp_history redirection system, incorporated audio links in it
This commit is contained in:
@@ -24,6 +24,29 @@ function edlp_ajax_page_attachments(array &$attachments) {
|
||||
$current_language = \Drupal::languageManager()->getCurrentLanguage()->getId();
|
||||
$is_front = \Drupal::service('path.matcher')->isFrontPage();
|
||||
|
||||
$entity_type = null;
|
||||
$entity_bundle = null;
|
||||
$entity_id = null;
|
||||
$audio_url = null;
|
||||
foreach (['node', 'taxonomy_term'] as $type) {
|
||||
$entity = \Drupal::routeMatch()->getParameter($type);
|
||||
if($entity){
|
||||
$entity_type = $type;
|
||||
$entity_bundle = $entity->bundle();
|
||||
$entity_id = $entity->id();
|
||||
if($entity_bundle == 'enregistrement'){
|
||||
$field_son_values = $entity->get('field_son')->getValue();
|
||||
$audio_fid = count($field_son_values) ? $field_son_values[0]['target_id'] : null;
|
||||
if($audio_fid){
|
||||
$audio_file = \Drupal\file\Entity\File::load($audio_fid);
|
||||
$son_uri = $audio_file->getFileUri();
|
||||
$audio_url = file_create_url($son_uri);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// do not redirect if not node, term, or custom routing
|
||||
// FIXME: check with routes instead of path as path can change !!!
|
||||
if(preg_match('/^\/?node\/\d+/', $current_path)
|
||||
@@ -41,6 +64,10 @@ function edlp_ajax_page_attachments(array &$attachments) {
|
||||
is_front:".($is_front ? 'true':'false').",\n
|
||||
redirect:".($redirect ? 'true':'false').",\n
|
||||
lang_code:'".$current_language."',\n
|
||||
entity_type:'".$entity_type."',\n
|
||||
entity_bundle:'".$entity_bundle."',\n
|
||||
entity_id:'".$entity_id."',\n
|
||||
audio_url:'".$audio_url."',\n
|
||||
};";
|
||||
|
||||
$attachments['#attached']['html_head'][] = [
|
||||
|
||||
Reference in New Issue
Block a user