You are here

function insert_field_widget_settings_summary_alter in Insert 8.2

Implements hook_field_widget_settings_summary_alter().

File

./insert.module, line 710

Code

function insert_field_widget_settings_summary_alter(array &$summary, array $context) {

  /** @var \Drupal\Core\Field\WidgetInterface $plugin */
  $plugin = $context['widget'];
  $pluginId = $plugin
    ->getPluginId();
  if (InsertUtility::isSourceWidget($pluginId, [
    INSERT_TYPE_FILE,
    INSERT_TYPE_IMAGE,
  ])) {
    $styles = InsertUtility::aggregateStyles(INSERT_TYPE_IMAGE);
    $settings = _insert_settings($plugin);
    $activeStyles = array_intersect_key($styles, array_filter($settings['styles']));
    $summary[] = t('Insert') . ': ' . (count($activeStyles) ? implode(', ', array_map(function ($style) {

      /** @var array|ImageStyle $style */
      return is_array($style) ? $style['label'] : $style
        ->label();
    }, $activeStyles)) : t('disabled'));
  }
}