You are here

public function DynamicEntityReferenceEntityFormatter::settingsSummary in Dynamic Entity Reference 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/DynamicEntityReferenceEntityFormatter.php \Drupal\dynamic_entity_reference\Plugin\Field\FieldFormatter\DynamicEntityReferenceEntityFormatter::settingsSummary()

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 EntityReferenceEntityFormatter::settingsSummary

File

src/Plugin/Field/FieldFormatter/DynamicEntityReferenceEntityFormatter.php, line 49

Class

DynamicEntityReferenceEntityFormatter
Plugin implementation of the 'rendered entity' formatter.

Namespace

Drupal\dynamic_entity_reference\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {
  $labels = \Drupal::service('entity_type.repository')
    ->getEntityTypeLabels(TRUE);
  $options = $labels[(string) t('Content', [], [
    'context' => 'Entity type group',
  ])];
  $entity_type_ids = DynamicEntityReferenceItem::getTargetTypes($this
    ->getFieldSettings());
  $available = [];
  foreach ($this
    ->getSettings() as $key => $value) {
    if (in_array($key, array_values($entity_type_ids))) {
      $available[$key] = $value;
    }
  }
  if (!empty($available)) {
    return array_map(function ($entity_type_id, $settings) use ($options) {
      $view_mode = $this->entityDisplayRepository
        ->getViewModeOptions($entity_type_id);
      return t('@entity view mode: @mode', [
        '@entity' => $options[$entity_type_id],
        '@mode' => $view_mode[$settings['view_mode']],
      ]);
    }, array_keys($available), $available);
  }
  else {
    return [];
  }
}