public function Jw_player::settingsDisplay in JW Player 8
Helper function to display JW Player preset settings.
Parameters
string $format (optional): Whether the preset settings are returned as an 'array' or formatted 'string'.
Return value
array|string The preset settings stored in an array or as an imploded string for rendering.
Overrides Jw_playerInterface::settingsDisplay
File
- src/
Entity/ Jw_player.php, line 99
Class
- Jw_player
- Defines the JW Player preset entity.
Namespace
Drupal\jw_player\EntityCode
public function settingsDisplay($format = 'string') {
$summary = [];
$preset_settings = $this
->getSettings();
// Name and description.
$summary['name'] = $this
->t('Preset: @name', [
'@name' => $this
->label(),
]);
if (!empty($this->description)) {
$summary['description'] = $this
->t('Description: @desc', [
'@desc' => $this->description,
]);
}
// Skin.
if (!isset($preset_settings['preset_source']) || $preset_settings['preset_source'] == 'drupal') {
$summary['source'] = $this
->t('Preset source: Drupal');
if (!empty($preset_settings['skin'])) {
$skin_label = $preset_settings['skin'];
$summary['skin'] = $this
->t('Skin: @skin', [
'@skin' => $skin_label,
]);
}
// Dimensions and stretching.
if (isset($preset_settings['stretching'])) {
switch ($preset_settings['stretching']) {
case 'exactfit':
$stretch = 'exact fit';
break;
case 'uniform':
$stretch = 'uniform';
break;
case 'fill':
$stretch = 'fill';
break;
default:
$stretch = '';
break;
}
}
if (!empty($stretch)) {
if (!empty($preset_settings['responsive'])) {
$summary['dimensions'] = $this
->t('Dimensions: @width width (@aspect_ratio), @stretch', [
'@width' => $preset_settings['width'],
'@aspect_ratio' => $preset_settings['aspectratio'],
'@stretch' => $stretch,
]);
}
else {
$summary['dimensions'] = $this
->t('Dimensions: @widthx@height, @stretch', [
'@width' => $preset_settings['width'],
'@height' => $preset_settings['height'],
'@stretch' => $stretch,
]);
}
}
else {
if (!empty($preset_settings['responsive'])) {
$summary['dimensions'] = $this
->t('Dimensions: @width width (@aspect_ratio)', [
'@width' => $preset_settings['width'],
'@aspect_ratio' => $preset_settings['aspectratio'],
]);
}
else {
$summary['dimensions'] = $this
->t('Dimensions: @widthx@height', [
'@width' => $preset_settings['width'],
'@height' => $preset_settings['height'],
]);
}
}
// Enabled options.
$enabled = [];
if (!empty($preset_settings['autostart'])) {
$enabled[] = $this
->t('Autostart');
}
if (!empty($preset_settings['mute'])) {
$enabled[] = $this
->t('Mute');
}
if (isset($preset_settings['sharing']) && $preset_settings['sharing']) {
$enabled[] = $this
->t('Sharing');
}
if (!empty($enabled)) {
$enabled_string = implode(', ', $enabled);
$summary['enabled'] = t('Enabled options: @enabled', [
'@enabled' => $enabled_string,
]);
}
// Sharing sites.
$sharing_weights = NULL;
if (isset($preset_settings['sharing_sites']['sites'])) {
foreach ($preset_settings['sharing_sites']['sites'] as $key => $value) {
if ($value['enabled'] == TRUE) {
$sharing_weights[$key] = $value['weight'];
}
}
if ($sharing_weights) {
asort($sharing_weights);
$sharing_sites = jw_player_sharing_sites();
$sharing_sorted = array_intersect_key($sharing_sites, $sharing_weights);
$sharing_sorted_string = implode(', ', $sharing_sorted);
$summary['sharing'] = $this
->t('Sharing sites: @sharing', [
'@sharing' => $sharing_sorted_string,
]);
}
}
}
else {
$summary['source'] = $this
->t('Preset source: JW Player');
}
return $format == 'string' ? implode('<br />', $summary) : $summary;
}