Commit 992fc7fd authored by Hawkeye Tenderwolf's avatar Hawkeye Tenderwolf Committed by Mateu Aguiló Bosch
Browse files

Issue #3255013 by hawkeye.twolf, e0ipso: Move "Other" option group to the...

Issue #3255013 by hawkeye.twolf, e0ipso: Move "Other" option group to the bottom of Widget Types select list
parent 26c27ebc
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -91,11 +91,12 @@ function widget_instance_options_list_alter(array &$options, array $context) {
  $widget_types = \Drupal::entityTypeManager()
    ->getStorage('widget_type')
    ->loadMultiple($widget_type_ids);
  $no_registry_source = '_widget_instance__no_widget_type_registry_source';
  $options = array_reduce(
    $widget_types,
    static function (array $carry, WidgetTypeInterface $widget_type): array {
    static function (array $carry, WidgetTypeInterface $widget_type) use ($no_registry_source): array {
      $registry_source = $widget_type->widget_registry_source->entity ?? NULL;
      $option_group = (string) new TranslatableMarkup('Other');
      $option_group = $no_registry_source;
      if ($registry_source instanceof EntityInterface) {
        $option_group = $registry_source->label();
      }
@@ -110,4 +111,8 @@ function widget_instance_options_list_alter(array &$options, array $context) {
  array_walk($options, static function (array &$option_group): void {
    sort($option_group);
  });
  // Move the 'Other' option group (for widget types with no registry source)
  // to the bottom of the select list.
  $options[(string) new TranslatableMarkup('Other')] = $options[$no_registry_source];
  unset($options[$no_registry_source]);
}