Skip to content
Snippets Groups Projects
Commit 7a5addda authored by catch's avatar catch
Browse files

Issue #3021804 by andypost, scott_euser, YurkinPark, mrinalini9, voleger,...

Issue #3021804 by andypost, scott_euser, YurkinPark, mrinalini9, voleger, Lendude, longwave: Remove optional dependency on menu_ui module in \Drupal\views\Plugin\views\wizard\WizardPluginBase
parent f8dbc98a
Branches
Tags
19 merge requests!12227Issue #3181946 by jonmcl, mglaman,!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1896Issue #2940605: Can only intentionally re-render an entity with references 20 times,!1101Issue #2412669 by claudiu.cristea, Julfabre, sidharrell, catch, daffie,...,!1039Issue #2556069 by claudiu.cristea, bnjmnm, lauriii, pfrenssen, Tim Bozeman,...,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!1012Issue #3226887: Hreflang on non-canonical content pages,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!594Put each entity type table into a details element on admin/config/regional/content-language,!592Issue #2957953: Editing menus user-experience has regressed,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!512Issue #3207771: Menu UI node type form documentation points to non-existent function,!485Sets the autocomplete attribute for username/password input field on login form.,!449Issue #2784233: Allow multiple vocabularies in the taxonomy filter,!231Issue #2671162: summary text wysiwyg patch working fine on 9.2.0-dev,!43Resolve #3173180: Add UI for 'loading' html attribute to images,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
Showing
with 98 additions and 59 deletions
......@@ -7,6 +7,7 @@
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Menu\MenuParentFormSelectorInterface;
use Drupal\views\Plugin\views\wizard\WizardPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -61,9 +62,15 @@ class Node extends WizardPluginBase {
* The entity display repository service.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
* @param \Drupal\Core\Menu\MenuParentFormSelectorInterface $parent_form_selector
* The parent form selector service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeBundleInfoInterface $bundle_info_service, EntityDisplayRepositoryInterface $entity_display_repository, EntityFieldManagerInterface $entity_field_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $bundle_info_service);
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeBundleInfoInterface $bundle_info_service, EntityDisplayRepositoryInterface $entity_display_repository, EntityFieldManagerInterface $entity_field_manager, MenuParentFormSelectorInterface $parent_form_selector = NULL) {
if (!$parent_form_selector) {
@trigger_error('Calling ' . __METHOD__ . '() without the $parent_form_selector argument is deprecated in drupal:9.3.0 and the $parent_form_selector argument will be required in drupal:10.0.0. See https://www.drupal.org/node/3027559', E_USER_DEPRECATED);
$parent_form_selector = \Drupal::service('menu.parent_form_selector');
}
parent::__construct($configuration, $plugin_id, $plugin_definition, $bundle_info_service, $parent_form_selector);
$this->entityDisplayRepository = $entity_display_repository;
$this->entityFieldManager = $entity_field_manager;
......@@ -79,7 +86,8 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_definition,
$container->get('entity_type.bundle.info'),
$container->get('entity_display.repository'),
$container->get('entity_field.manager')
$container->get('entity_field.manager'),
$container->get('menu.parent_form_selector')
);
}
......
......@@ -5,6 +5,7 @@
use Drupal\Component\Utility\Xss;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Menu\MenuParentFormSelectorInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -49,6 +50,13 @@ class Page extends PathPluginBase {
*/
protected $menuStorage;
/**
* The parent form selector service.
*
* @var \Drupal\Core\Menu\MenuParentFormSelectorInterface
*/
protected $parentFormSelector;
/**
* Constructs a Page object.
*
......@@ -64,10 +72,17 @@ class Page extends PathPluginBase {
* The state key value store.
* @param \Drupal\Core\Entity\EntityStorageInterface $menu_storage
* The menu storage.
* @param \Drupal\Core\Menu\MenuParentFormSelectorInterface $parent_form_selector
* The parent form selector service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider, StateInterface $state, EntityStorageInterface $menu_storage) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider, StateInterface $state, EntityStorageInterface $menu_storage, MenuParentFormSelectorInterface $parent_form_selector = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $route_provider, $state);
$this->menuStorage = $menu_storage;
if (!$parent_form_selector) {
@trigger_error('Calling ' . __METHOD__ . '() without the $parent_form_selector argument is deprecated in drupal:9.3.0 and the $parent_form_selector argument will be required in drupal:10.0.0. See https://www.drupal.org/node/3027559', E_USER_DEPRECATED);
$parent_form_selector = \Drupal::service('menu.parent_form_selector');
}
$this->parentFormSelector = $parent_form_selector;
}
/**
......@@ -80,7 +95,8 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_definition,
$container->get('router.route_provider'),
$container->get('state'),
$container->get('entity_type.manager')->getStorage('menu')
$container->get('entity_type.manager')->getStorage('menu'),
$container->get('menu.parent_form_selector')
);
}
......@@ -311,36 +327,24 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
'#description' => $this->t('If selected and this menu link has children, the menu will always appear expanded.'),
];
// Only display the parent selector if Menu UI module is enabled.
$menu_parent = $menu['menu_name'] . ':' . $menu['parent'];
if (\Drupal::moduleHandler()->moduleExists('menu_ui')) {
$menu_link = 'views_view:views.' . $form_state->get('view')->id() . '.' . $form_state->get('display_id');
$form['menu']['parent'] = \Drupal::service('menu.parent_form_selector')->parentSelectElement($menu_parent, $menu_link);
$form['menu']['parent'] += [
'#title' => $this->t('Parent'),
'#description' => $this->t('The maximum depth for a link and all its children is fixed. Some menu links may not be available as parents if selecting them would exceed this limit.'),
'#attributes' => ['class' => ['menu-title-select']],
'#states' => [
'visible' => [
[
':input[name="menu[type]"]' => ['value' => 'normal'],
],
[
':input[name="menu[type]"]' => ['value' => 'tab'],
],
$menu_link = 'views_view:views.' . $form_state->get('view')->id() . '.' . $form_state->get('display_id');
$form['menu']['parent'] = $this->parentFormSelector->parentSelectElement($menu_parent, $menu_link);
$form['menu']['parent'] += [
'#title' => $this->t('Parent'),
'#description' => $this->t('The maximum depth for a link and all its children is fixed. Some menu links may not be available as parents if selecting them would exceed this limit.'),
'#attributes' => ['class' => ['menu-title-select']],
'#states' => [
'visible' => [
[
':input[name="menu[type]"]' => ['value' => 'normal'],
],
[
':input[name="menu[type]"]' => ['value' => 'tab'],
],
],
];
}
else {
$form['menu']['parent'] = [
'#type' => 'value',
'#value' => $menu_parent,
];
$form['menu']['markup'] = [
'#markup' => $this->t('Menu selection requires the activation of Menu UI module.'),
];
}
],
];
$form['menu']['weight'] = [
'#title' => $this->t('Weight'),
'#type' => 'textfield',
......
......@@ -6,6 +6,7 @@
use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Menu\MenuParentFormSelectorInterface;
use Drupal\Core\Url;
use Drupal\views\Entity\View;
use Drupal\views\Views;
......@@ -116,6 +117,13 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface {
*/
protected $bundleInfoService;
/**
* The parent form selector service.
*
* @var \Drupal\Core\Menu\MenuParentFormSelectorInterface
*/
protected $parentFormSelector;
/**
* {@inheritdoc}
*/
......@@ -124,19 +132,26 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_type.bundle.info')
$container->get('entity_type.bundle.info'),
$container->get('menu.parent_form_selector')
);
}
/**
* Constructs a WizardPluginBase object.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeBundleInfoInterface $bundle_info_service) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeBundleInfoInterface $bundle_info_service, MenuParentFormSelectorInterface $parent_form_selector = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->bundleInfoService = $bundle_info_service;
$this->base_table = $this->definition['base_table'];
if (!$parent_form_selector) {
@trigger_error('Calling ' . __METHOD__ . '() without the $parent_form_selector argument is deprecated in drupal:9.3.0 and the $parent_form_selector argument will be required in drupal:10.0.0. See https://www.drupal.org/node/3027559', E_USER_DEPRECATED);
$parent_form_selector = \Drupal::service('menu.parent_form_selector');
}
$this->parentFormSelector = $parent_form_selector;
$entity_types = \Drupal::entityTypeManager()->getDefinitions();
foreach ($entity_types as $entity_type_id => $entity_type) {
if (in_array($this->base_table, [$entity_type->getBaseTable(), $entity_type->getDataTable(), $entity_type->getRevisionTable(), $entity_type->getRevisionDataTable()], TRUE)) {
......@@ -305,20 +320,9 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#prefix' => '<div id="edit-page-link-properties-wrapper">',
'#suffix' => '</div>',
];
if (\Drupal::moduleHandler()->moduleExists('menu_ui')) {
$menu_options = menu_ui_get_menus();
}
else {
// These are not yet translated.
$menu_options = menu_list_system_menus();
foreach ($menu_options as $name => $title) {
$menu_options[$name] = $this->t($title);
}
}
$form['displays']['page']['options']['link_properties']['menu_name'] = [
$form['displays']['page']['options']['link_properties']['parent'] = $this->parentFormSelector->parentSelectElement('admin:');
$form['displays']['page']['options']['link_properties']['parent'] += [
'#title' => $this->t('Menu'),
'#type' => 'select',
'#options' => $menu_options,
];
$form['displays']['page']['options']['link_properties']['title'] = [
'#title' => $this->t('Link text'),
......@@ -1092,7 +1096,7 @@ protected function pageDisplayOptions(array $form, FormStateInterface $form_stat
if (!empty($page['link'])) {
$display_options['menu']['type'] = 'normal';
$display_options['menu']['title'] = $page['link_properties']['title'];
$display_options['menu']['menu_name'] = $page['link_properties']['menu_name'];
list($display_options['menu']['menu_name'], $display_options['menu']['parent']) = explode(':', $page['link_properties']['parent'], 2);
}
return $display_options;
}
......
......@@ -27,7 +27,7 @@ class DisplayPageWebTest extends ViewTestBase {
*
* @var array
*/
protected static $modules = ['menu_ui', 'block', 'views_ui'];
protected static $modules = ['block', 'views_ui'];
/**
* {@inheritdoc}
......@@ -123,6 +123,7 @@ public function testPageDisplayMenu() {
$menu_link = $this->cssSelect('nav.block-menu ul.menu a');
$this->assertEquals('Test menu link', $menu_link[0]->getText());
$this->container->get('module_installer')->install(['menu_ui', 'menu_link_content']);
// Update the menu link.
$this->drupalGet("admin/structure/menu/link/views_view:views.test_page_display_menu.page_3/edit");
......
......@@ -29,7 +29,7 @@ class MenuLinkTest extends ViewTestBase {
'views_ui',
'user',
'node',
'menu_ui',
'menu_link_content',
'block',
];
......
......@@ -32,7 +32,7 @@ public function testMenus() {
$view['page[title]'] = $this->randomMachineName(16);
$view['page[path]'] = $this->randomMachineName(16);
$view['page[link]'] = 1;
$view['page[link_properties][menu_name]'] = 'main';
$view['page[link_properties][parent]'] = 'main:';
$view['page[link_properties][title]'] = $this->randomMachineName(16);
$this->drupalGet('admin/structure/views/add');
$this->submitForm($view, 'Save and edit');
......
......@@ -15,7 +15,6 @@ class ViewsMenuLinkTest extends ViewsKernelTestBase {
* {@inheritdoc}
*/
protected static $modules = [
'menu_ui',
'user',
'views',
];
......
......@@ -22,11 +22,6 @@ protected function setUp($import_test_views = TRUE): void {
$this->placeBlock('page_title_block');
}
/**
* {@inheritdoc}
*/
protected static $modules = ['menu_ui'];
/**
* {@inheritdoc}
*/
......@@ -268,6 +263,23 @@ public function testDefaultMenuTabRegression() {
'tab_options[title]' => 'Parent title',
], 'Apply');
// Open the menu options again.
$this->clickLink(t('Tab: Menu title'));
// Assert a menu can be selected as a parent.
$this->assertSession()->optionExists('menu[parent]', 'admin:');
// Assert a parent menu item can be selected from within a menu.
$this->assertSession()->optionExists('menu[parent]', 'admin:system.admin');
// Check that parent menu item can now be
// added without the menu_ui module being enabled.
$this->submitForm([
'menu[type]' => 'normal',
'menu[parent]' => 'admin:system.admin',
'menu[title]' => 'Menu title',
], 'Apply');
$this->submitForm([], 'Save');
// Assert that saving the view will not cause an exception.
$this->assertSession()->statusCodeEquals(200);
......
......@@ -29,7 +29,7 @@ protected function setUp(): void {
parent::setUp();
$admin_user = $this->drupalCreateUser([
'administer site configuration',
'access administration pages',
'administer views',
]);
$this->drupalLogin($admin_user);
......@@ -58,6 +58,15 @@ public function testCreateViewWizard() {
$page->findField('page[link]')->click();
$this->assertEquals($label_value, $page->findField('page[link_properties][title]')->getValue());
// Wait for conditional field to show.
$this->assertSession()->waitForElementVisible('named', ['select', 'page[link_properties][parent]']);
// Assert a menu can be selected as a parent.
$this->assertSession()->optionExists('page[link_properties][parent]', 'admin:');
// Assert a parent menu item can be selected from within a menu.
$this->assertSession()->optionExists('page[link_properties][parent]', 'admin:entity.view.collection');
// Add a block display.
$page->findField('block[create]')->click();
$this->assertEquals($label_value, $page->findField('block[title]')->getValue());
......
......@@ -9,6 +9,7 @@
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Menu\MenuParentFormSelector;
use Drupal\Tests\UnitTestCase;
use Drupal\views\Entity\View;
use Drupal\views\ViewExecutableFactory;
......@@ -82,9 +83,10 @@ public function testBuildRowEntityList() {
$route_provider = $this->createMock('Drupal\Core\Routing\RouteProviderInterface');
$state = $this->createMock('\Drupal\Core\State\StateInterface');
$menu_storage = $this->createMock('\Drupal\Core\Entity\EntityStorageInterface');
$parent_form_selector = $this->createMock(MenuParentFormSelector::class);
$page_display = $this->getMockBuilder('Drupal\views\Plugin\views\display\Page')
->setMethods(['initDisplay', 'getPath'])
->setConstructorArgs([[], 'default', $display_manager->getDefinition('page'), $route_provider, $state, $menu_storage])
->setConstructorArgs([[], 'default', $display_manager->getDefinition('page'), $route_provider, $state, $menu_storage, $parent_form_selector])
->getMock();
$page_display->expects($this->any())
->method('getPath')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment