Skip to content

Commit

Permalink
UHF-6294: Allow weight to be changed
Browse files Browse the repository at this point in the history
  • Loading branch information
tuutti committed Sep 14, 2023
1 parent f5fab16 commit a15cf27
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Entity/Form/MenuLinkFormTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ protected function attachMenuLinkForm(array $form, FormStateInterface $formState
->menuParentSelector
->parentSelectElement($default, $id, $this->getAvailableMenus());

$form['menu']['link']['weight'] = [
'#type' => 'number',
'#title' => t('Weight'),
'#default_value' => $menuLink->getWeight(),
'#description' => $this->t('Menu links with lower weights are displayed before links with higher weights.'),
];

$form['actions']['submit']['#submit'][] = '::attachMenuLinkFormSubmit';

return $form;
Expand Down Expand Up @@ -199,6 +206,7 @@ public function attachMenuLinkFormSubmit(array $form, FormStateInterface $formSt
->set('menu_name', $menuName)
->set('parent', $parent)
->set('langcode', $entity->language()->getId())
->set('weight', $values['weight'])
->save();

$entity->set($this->menuLinkFieldName, $menuLink)->save();
Expand Down
2 changes: 2 additions & 0 deletions tests/src/Functional/MenuLinkFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function testMenuLinkForm() : void {
$this->submitForm([
'menu[enabled]' => 1,
'menu[title]' => 'Test title ' . $langcode,
'menu[weight]' => 9,
], 'Save');

// Make sure menu link is show in edit form.
Expand All @@ -119,6 +120,7 @@ public function testMenuLinkForm() : void {
->entity
->getTranslation($langcode);

$this->assertEquals(9, $menuLink->getWeight());
$this->assertEquals('Test title ' . $langcode, $menuLink->getTitle());
}

Expand Down

0 comments on commit a15cf27

Please sign in to comment.