- core-recommended/scaffold/project-message ^11.4, platform php 8.3.37, symfony/runtime allow-plugin - drush ^13, toutes les contraintes modules montées vers D11 (racine + profil starterkit) - modules abandonnés D11 pris en custom: path_alias_xt, content_type_clone, bulkdelete, imagestyleflush (flush_single_image), audiofield (annotations -> attributs PHP 8), adminimal_theme (theme) - decoupled + theme caravane: core_version_requirement || ^11 - .gitmodules du profil -> gitea (gogs mort) - patch page_manager 3438993 retiré (ne s'applique plus sur 4.1.0, refactor upstream) - sync: retrait ban/actions_permissions/seven (modules core supprimés en D11) + normalisation cex D11 - config_pages: conflit intro_partenaire résolu Tests local (docker php 8.3.37): updb OK, cim OK, getChangeList vide, 6 pages clés hash-identiques avant/après, watchdog sans erreur nouvelle. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
83 lines
2.5 KiB
PHP
83 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Drupal\audiofield\Plugin\AudioPlayer;
|
|
|
|
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
|
use Drupal\audiofield\Attribute\AudioPlayer;
|
|
|
|
|
|
use Drupal\Core\Field\FieldItemListInterface;
|
|
use Drupal\audiofield\AudioFieldPluginBase;
|
|
use Drupal\Component\Serialization\Json;
|
|
|
|
#[AudioPlayer(
|
|
id: 'mediaelement_audio_player',
|
|
title: new TranslatableMarkup('MediaElement audio player'),
|
|
description: new TranslatableMarkup('A dependable HTML media framework.'),
|
|
fileTypes: ['mp3', 'oga', 'ogg', 'wav'],
|
|
libraryName: 'mediaelement',
|
|
website: 'http://mediaelementjs.com/',
|
|
)]
|
|
class MediaElementAudioPlayer extends AudioFieldPluginBase {
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function renderPlayer(FieldItemListInterface $items, $langcode, array $settings) {
|
|
// Check to make sure we're installed.
|
|
if (!$this->checkInstalled()) {
|
|
// Show the error.
|
|
$this->showInstallError();
|
|
|
|
// Simply return the default rendering so the files are still displayed.
|
|
return $this->renderDefaultPlayer($items, $settings);
|
|
}
|
|
|
|
// Start building settings to pass to the javascript MediaElement builder.
|
|
$player_settings = [
|
|
// MediaElement expects this as a 0 - 1 range.
|
|
'volume' => ($settings['audio_player_initial_volume'] / 10),
|
|
'elements' => [],
|
|
];
|
|
|
|
// Format files for output.
|
|
$template_files = $this->getItemRenderList($items);
|
|
foreach ($template_files as $renderInfo) {
|
|
// Pass the element name for the player so we know what to render.
|
|
$player_settings['elements'][] = '#mediaelement_player_' . $renderInfo->id;
|
|
}
|
|
|
|
return [
|
|
'audioplayer' => [
|
|
'#theme' => 'audioplayer',
|
|
'#plugin_id' => 'mediaelement',
|
|
'#settings' => $settings,
|
|
'#files' => $template_files,
|
|
],
|
|
'downloads' => $this->createDownloadList($items, $settings),
|
|
'#attached' => [
|
|
'library' => [
|
|
// Attach the MediaElement library.
|
|
'audiofield/audiofield.' . $this->getPluginLibraryName(),
|
|
],
|
|
'drupalSettings' => [
|
|
'audiofieldmediaelement' => [
|
|
$this->getUniqueRenderId() => $player_settings,
|
|
],
|
|
],
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function getPluginLibraryVersion() {
|
|
// Parse the JSON file for version info.
|
|
$library_path = $this->fileSystem->realpath(DRUPAL_ROOT . $this->getPluginLibraryPath() . '/package.json');
|
|
$library_data = Json::decode(file_get_contents($library_path));
|
|
return $library_data['version'];
|
|
}
|
|
|
|
}
|