Verified Commit f9b363c0 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3375887 by srishtiiee, Berdir, Utkarsh_33: Add a weight for the options...

Issue #3375887 by srishtiiee, Berdir, Utkarsh_33: Add a weight for the options within a field category
parent 39cf4d22
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -57,6 +57,13 @@ class FieldType extends DataType {
   */
  public $category = '';

  /**
   * The weight of the field type.
   *
   * @var int
   */
  public $weight = 0;

  /**
   * The plugin_id of the default widget for this field type.
   *
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
 *     @Translation("For example, 12.34 km or € when used for further detailed calculations (such as summing many of these)"),
 *   },
 *   category = "number",
 *   weight = -30,
 *   default_widget = "number",
 *   default_formatter = "number_decimal"
 * )
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
 *     @Translation("For example, 123.4 km when used in imprecise contexts such as a walking trail distance"),
 *   },
 *   category = "number",
 *   weight = -10,
 *   default_widget = "number",
 *   default_formatter = "number_decimal"
 * )
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
 *     @Translation("For example, 123"),
 *   },
 *   category = "number",
 *   weight = -50,
 *   default_widget = "number",
 *   default_formatter = "number_integer"
 * )
+4 −1
Original line number Diff line number Diff line
@@ -292,6 +292,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t
              '#items' => $unique_definitions[$selected_field_type][$option_key]['description'],
            ],
            '#id' => $option['unique_identifier'],
            '#weight' => $option['weight'],
            '#parents' => ['group_field_options_wrapper'],
            '#attributes' => [
              'class' => ['field-option-radio'],
@@ -307,8 +308,10 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t
            $radio_element['#title'] = 'Other';
            $radio_element['#weight'] = 10;
          }
          $form['group_field_options_wrapper']['fields'][$option['unique_identifier']] = $radio_element;
          $group_field_options[$option['unique_identifier']] = $radio_element;
        }
        uasort($group_field_options, [SortArray::class, 'sortByWeightProperty']);
        $form['group_field_options_wrapper']['fields'] += $group_field_options;
      }
    }
    $field_prefix = $this->config('field_ui.settings')->get('field_prefix');
Loading