View source
<?php
namespace Drupal\jw_player\Entity;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\jw_player\Jw_playerInterface;
class Jw_player extends ConfigEntityBase implements Jw_playerInterface {
use StringTranslationTrait;
public $id;
public $label;
public $description;
public $settings = array();
public function getSettings() {
if (isset($this->settings['responsive']) && $this->settings['responsive']) {
unset($this->settings['height']);
$this->settings['width'] .= '%';
}
else {
unset($this->settings['aspectratio']);
}
return $this->settings;
}
public function getSetting($key, $default = NULL) {
$exists = NULL;
$value =& NestedArray::getValue($this->settings, (array) $key, $exists);
if (!$exists) {
$value = $default;
}
return $value;
}
public function settingsDisplay($format = 'string') {
$summary = [];
$preset_settings = $this
->getSettings();
$summary['name'] = $this
->t('Preset: @name', [
'@name' => $this
->label(),
]);
if (!empty($this->description)) {
$summary['description'] = $this
->t('Description: @desc', [
'@desc' => $this->description,
]);
}
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,
]);
}
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 = [];
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_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;
}
}