You are here

public function JwplayerFormatter::settingsSummary in JW Player 8

Returns a short summary for the current formatter settings.

If an empty result is returned, a UI can still be provided to display a settings form in case the formatter has configurable settings.

Return value

string[] A short summary of the formatter settings.

Overrides FormatterBase::settingsSummary

File

src/Plugin/Field/FieldFormatter/JwplayerFormatter.php, line 130

Class

JwplayerFormatter
Plugin implementation of the 'foo_formatter' formatter.

Namespace

Drupal\jw_player\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {
  $settings = $this
    ->getSettings();
  $summary = [];
  if (isset($settings['jwplayer_preset'])) {
    $preset = $this
      ->loadPreset();
    if (!$preset) {
      return $summary;
    }
    $preset_settings = $preset
      ->settingsDisplay('array');

    // Formatted preset name and player type.
    $summary[] = $preset_settings['name'];
    if (stripos($preset_settings['source'], 'drupal') !== FALSE) {

      // Skin, dimensions, enabled options, and sharing sites.
      if (isset($preset_settings['skin'])) {
        $summary[] = $preset_settings['skin'];
      }
      $summary[] = $preset_settings['dimensions'];
      if (isset($preset_settings['enabled'])) {
        $summary[] = $preset_settings['enabled'];
      }
      if (isset($preset_settings['sharing'])) {
        $summary[] = $preset_settings['sharing'];
      }
    }
    else {
      $summary[] = $preset_settings['source'];
    }

    // Preview image settings.
    if (isset($settings['preview_image_field']) && !empty($settings['preview_image_field'])) {

      // Get image field label.
      $split = explode('|', $settings['preview_image_field']);
      $field_definitions = \Drupal::service('entity_field.manager')
        ->getFieldDefinitions($this->fieldDefinition
        ->getTargetEntityTypeId(), $this->fieldDefinition
        ->getTargetBundle());
      $info = $field_definitions[$split[1]];

      // Get image style label.
      if (!empty($settings['preview_image_style'])) {
        $style = ImageStyle::load($settings['preview_image_style']);
        $preview_image_style = $style
          ->label();
      }
      else {
        $preview_image_style = 'Original';
      }
      $summary[] = $this
        ->t('Preview: @field (@style)', array(
        '@field' => $info
          ->label(),
        '@style' => $preview_image_style,
      ));
    }
  }
  else {
    $summary[] = $this
      ->t('No preset selected');
  }
  return $summary;
}