added file download on cartel
This commit is contained in:
@@ -319,3 +319,30 @@ function edlp_corpus_node_update(EntityInterface $node) {
|
||||
function edlp_corpus_node_delete(EntityInterface $node) {
|
||||
_edlp_corpus_invalidate_corpus_cache($node);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_theme_suggestions_HOOK().
|
||||
*/
|
||||
function edlp_corpus_theme_suggestions_file_link(array $vars) {
|
||||
// dpm($vars);
|
||||
$suggestions = [];
|
||||
|
||||
// /** @var \Drupal\edlp_studio\CompositionInterface $compo */
|
||||
// $compo = $vars['elements']['#composition'];
|
||||
//
|
||||
$file = $vars['file'];
|
||||
// dpm($file);
|
||||
$mime = str_replace('/', '-',$file->getMimeType());
|
||||
// $owner = $file->getOwner();
|
||||
// dpm($owner);
|
||||
// $refentities = $file->referencedEntities();
|
||||
// dpm($refentities);
|
||||
|
||||
$suggestions[] = 'file-link';
|
||||
$suggestions[] = 'file-link__' . $mime;
|
||||
// $suggestions[] = 'file-link__' . $owner;
|
||||
|
||||
// dpm($suggestions);
|
||||
return $suggestions;
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1076,7 +1076,8 @@ main[role="main"]{
|
||||
}
|
||||
.col-left{
|
||||
// position: relative;
|
||||
a.ajax-link{
|
||||
a.ajax-link,
|
||||
a.link-audio-download{
|
||||
display: block;
|
||||
font-size: 0.82em;
|
||||
font-weight: 600;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
{#
|
||||
/**
|
||||
* @file
|
||||
* Theme override for a field.
|
||||
*
|
||||
* To override output, copy the "field.html.twig" from the templates directory
|
||||
* to your theme's directory and customize it, just like customizing other
|
||||
* Drupal templates such as page.html.twig or node.html.twig.
|
||||
*
|
||||
* Instead of overriding the theming for all fields, you can also just override
|
||||
* theming for a subset of fields using
|
||||
* @link themeable Theme hook suggestions. @endlink For example,
|
||||
* here are some theme hook suggestions that can be used for a field_foo field
|
||||
* on an article node type:
|
||||
* - field--node--field-foo--article.html.twig
|
||||
* - field--node--field-foo.html.twig
|
||||
* - field--node--article.html.twig
|
||||
* - field--field-foo.html.twig
|
||||
* - field--text-with-summary.html.twig
|
||||
* - field.html.twig
|
||||
*
|
||||
* Available variables:
|
||||
* - attributes: HTML attributes for the containing element.
|
||||
* - label_hidden: Whether to show the field label or not.
|
||||
* - title_attributes: HTML attributes for the title.
|
||||
* - label: The label for the field.
|
||||
* - multiple: TRUE if a field can contain multiple items.
|
||||
* - items: List of all the field items. Each item contains:
|
||||
* - attributes: List of HTML attributes for each item.
|
||||
* - content: The field item's content.
|
||||
* - entity_type: The entity type to which the field belongs.
|
||||
* - field_name: The name of the field.
|
||||
* - field_type: The type of the field.
|
||||
* - label_display: The display settings for the label.
|
||||
*
|
||||
*
|
||||
* @see template_preprocess_field()
|
||||
*/
|
||||
#}
|
||||
{%
|
||||
set classes = [
|
||||
'field',
|
||||
'field--name-' ~ field_name|clean_class,
|
||||
'field--type-' ~ field_type|clean_class,
|
||||
'field--label-' ~ label_display,
|
||||
]
|
||||
%}
|
||||
{%
|
||||
set title_classes = [
|
||||
'field__label',
|
||||
label_display == 'visually_hidden' ? 'visually-hidden',
|
||||
]
|
||||
%}
|
||||
|
||||
{% if label_hidden %}
|
||||
{% if multiple %}
|
||||
<div{{ attributes.addClass(classes, 'field__items') }}>
|
||||
{% for item in items %}
|
||||
<div{{ item.attributes.addClass('field__item') }}>{{ item.content }}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{% for item in items %}
|
||||
<div{{ attributes.addClass(classes, 'field__item') }}>{{ item.content }}</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<div{{ attributes.addClass(classes) }}>
|
||||
<div{{ title_attributes.addClass(title_classes) }}>{{ label }}</div>
|
||||
{% if multiple %}
|
||||
<div class="field__items">
|
||||
{% endif %}
|
||||
{% for item in items %}
|
||||
<div{{ item.attributes.addClass('field__item') }}>{{ item.content }}</div>
|
||||
{% endfor %}
|
||||
{% if multiple %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
+1
@@ -108,6 +108,7 @@
|
||||
<div class="col-left">
|
||||
{{ link_transcript }}
|
||||
{{ link_article }}
|
||||
{{ link_audio_download }}
|
||||
{{ content.addtoany }}
|
||||
</div>
|
||||
{# endif #}
|
||||
|
||||
Reference in New Issue
Block a user