You are here

public function SwitchField::settingsSummary in Display Suite 8.4

Same name and namespace in other branches
  1. 8.2 modules/ds_extras/src/Plugin/DsField/SwitchField.php \Drupal\ds_extras\Plugin\DsField\SwitchField::settingsSummary()
  2. 8.3 modules/ds_extras/src/Plugin/DsField/SwitchField.php \Drupal\ds_extras\Plugin\DsField\SwitchField::settingsSummary()

Returns the summary of the chosen settings.

Parameters

array $settings: Contains the settings of the field.

Return value

array A render array containing the summary.

Overrides DsFieldBase::settingsSummary

File

modules/ds_extras/src/Plugin/DsField/SwitchField.php, line 154

Class

SwitchField
Plugin that generates a link to switch view mode with via ajax.

Namespace

Drupal\ds_extras\Plugin\DsField

Code

public function settingsSummary($settings) {
  $entity_type = $this
    ->getEntityTypeId();
  $bundle = $this
    ->bundle();
  $settings = isset($settings['vms']) ? $settings['vms'] : [];
  $view_modes = $this->entityDisplayRepository
    ->getViewModes($entity_type);
  $summary = [];
  $summary[] = 'View mode labels';
  foreach ($view_modes as $key => $value) {
    $entity_display = $this->entityTypeManager
      ->getStorage('entity_view_display')
      ->load($entity_type . '.' . $bundle . '.' . $key);
    if (!empty($entity_display)) {
      if ($entity_display
        ->status()) {
        $label = isset($settings[$key]) ? $settings[$key] : $key;
        $summary[] = $key . ' : ' . $label;
      }
    }
  }
  return $summary;
}