Issue #2660486 by pwolanin, dawehner, rrrob: MenuLinkDefaultForm::extractFormValues() does not include the plugin ID
parent
b13450f677
commit
af1f11e736
|
@ -110,6 +110,10 @@ class MenuLinkDefaultForm implements MenuLinkFormInterface, ContainerInjectionIn
|
|||
'#type' => 'item',
|
||||
'#title' => $this->t('This link is provided by the @name module. The title and path cannot be edited.', array('@name' => $this->moduleHandler->getName($provider))),
|
||||
);
|
||||
$form['id'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => $this->menuLink->getPluginId(),
|
||||
);
|
||||
$link = array(
|
||||
'#type' => 'link',
|
||||
'#title' => $this->menuLink->getTitle(),
|
||||
|
@ -158,7 +162,11 @@ class MenuLinkDefaultForm implements MenuLinkFormInterface, ContainerInjectionIn
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function extractFormValues(array &$form, FormStateInterface $form_state) {
|
||||
$new_definition = array();
|
||||
// Start from the complete, original, definition.
|
||||
$new_definition = $this->menuLink->getPluginDefinition();
|
||||
// Since the ID may not be present in the definition used to construct the
|
||||
// plugin, add it here so it's available to any consumers of this method.
|
||||
$new_definition['id'] = $form_state->getValue('id');
|
||||
$new_definition['enabled'] = $form_state->getValue('enabled') ? 1 : 0;
|
||||
$new_definition['weight'] = (int) $form_state->getValue('weight');
|
||||
$new_definition['expanded'] = $form_state->getValue('expanded') ? 1 : 0;
|
||||
|
|
|
@ -38,7 +38,8 @@ interface MenuLinkFormInterface extends PluginFormInterface {
|
|||
* The current state of the form.
|
||||
*
|
||||
* @return array
|
||||
* The new plugin definition values taken from the form values.
|
||||
* The new plugin definition values taken from the form values. The plugin
|
||||
* ID must be returned as part of the definition.
|
||||
*/
|
||||
public function extractFormValues(array &$form, FormStateInterface $form_state);
|
||||
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Menu\MenuLinkDefaultFormTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Menu;
|
||||
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Form\FormState;
|
||||
use Drupal\Core\Menu\Form\MenuLinkDefaultForm;
|
||||
use Drupal\Core\Menu\MenuLinkDefault;
|
||||
use Drupal\Core\Menu\MenuLinkManagerInterface;
|
||||
use Drupal\Core\Menu\MenuParentFormSelectorInterface;
|
||||
use Drupal\Core\Menu\StaticMenuLinkOverridesInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Core\Menu\Form\MenuLinkDefaultForm
|
||||
* @group Menu
|
||||
*/
|
||||
class MenuLinkDefaultFormTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::extractFormValues
|
||||
*/
|
||||
public function testExtractFormValues() {
|
||||
$menu_link_manager = $this->prophesize(MenuLinkManagerInterface::class);
|
||||
$menu_parent_form_selector = $this->prophesize(MenuParentFormSelectorInterface::class);
|
||||
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
|
||||
$menu_link_form = new MenuLinkDefaultForm($menu_link_manager->reveal(), $menu_parent_form_selector->reveal(), $this->getStringTranslationStub(), $module_handler->reveal());
|
||||
|
||||
$static_override = $this->prophesize(StaticMenuLinkOverridesInterface::class);
|
||||
$menu_link = new MenuLinkDefault([], 'my_plugin_id', [], $static_override->reveal());
|
||||
$menu_link_form->setMenuLinkInstance($menu_link);
|
||||
|
||||
$form_state = new FormState();
|
||||
$form_state->setValue('id', 'my_plugin_id');
|
||||
$form_state->setValue('enabled', FALSE);
|
||||
$form_state->setValue('weight', 5);
|
||||
$form_state->setValue('expanded', TRUE);
|
||||
$form_state->setValue('menu_parent', 'foo:bar');
|
||||
|
||||
$form = [];
|
||||
$result = $menu_link_form->extractFormValues($form, $form_state);
|
||||
|
||||
$this->assertEquals([
|
||||
'id' => 'my_plugin_id',
|
||||
'enabled' => 0,
|
||||
'weight' => 5,
|
||||
'expanded' => 1,
|
||||
'parent' => 'bar',
|
||||
'menu_name' => 'foo'
|
||||
], $result);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue