You are here

public function ConditionsWidget::settingsSummary in Commerce Core 8.2

Returns a short summary for the current widget settings.

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

Return value

array A short summary of the widget settings.

Overrides WidgetBase::settingsSummary

File

src/Plugin/Field/FieldWidget/ConditionsWidget.php, line 123

Class

ConditionsWidget
Plugin implementation of the 'commerce_conditions' widget.

Namespace

Drupal\commerce\Plugin\Field\FieldWidget

Code

public function settingsSummary() {
  $summary = [];
  $selected_entity_types = array_filter($this
    ->getSetting('entity_types'));
  if (!empty($selected_entity_types)) {
    $entity_types = $this->entityTypeManager
      ->getDefinitions();
    $entity_types = array_filter($entity_types, function ($entity_type) use ($selected_entity_types) {

      /** @var \Drupal\Core\Entity\EntityType $entity_type */
      return in_array($entity_type
        ->id(), $selected_entity_types);
    });
    $entity_types = array_map(function ($entity_type) {

      /** @var \Drupal\Core\Entity\EntityType $entity_type */
      return $entity_type
        ->getLabel();
    }, $entity_types);
    $summary[] = $this
      ->t('Entity types: @entity_types', [
      '@entity_types' => implode(', ', $entity_types),
    ]);
  }
  return $summary;
}