Skip to content
Snippets Groups Projects
Verified Commit 246b571c authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3379293 by benjifisher, lauriii, pooja saraah, smustgrave, poker10:...

Issue #3379293 by benjifisher, lauriii, pooja saraah, smustgrave, poker10: Make it easier to add a child menu item
parent d6f9f1d4
Branches
Tags
44 merge requests!12227Issue #3181946 by jonmcl, mglaman,!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!4868Issue #1428520: Improve menu parent link selection,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3546refactored dialog.pcss file,!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3502Issue #3335308: Confusing behavior with FormState::setFormState and FormState::setMethod,!3478Issue #3337882: Deleted menus are not removed from content type config,!3452Issue #3332701: Refactor Claro's tablesort-indicator stylesheet,!3451Issue #2410579: Allows setting the current language programmatically.,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3147Issue #3328457: Replace most substr($a, $i) where $i is negative with str_ends_with(),!3146Issue #3328456: Replace substr($a, 0, $i) with str_starts_with(),!3133core/modules/system/css/components/hidden.module.css,!31312878513-10.1.x,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2614Issue #2981326: Replace non-test usages of \Drupal::logger() with IoC injection,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1591Issue #3199697: Add JSON:API Translation experimental module,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!844Resolve #3036010 "Updaters",!673Issue #3214208: FinishResponseSubscriber could create duplicate headers,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
Pipeline #20240 canceled
Pipeline: drupal

#20241

    ......@@ -89,7 +89,8 @@ public static function create(ContainerInterface $container) {
    public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form, $form_state);
    $default = $this->entity->getMenuName() . ':' . $this->entity->getParentId();
    $parent_id = $this->entity->getParentId() ?: $this->getRequest()->query->get('parent');
    $default = $this->entity->getMenuName() . ':' . $parent_id;
    $id = $this->entity->isNew() ? '' : $this->entity->getPluginId();
    if ($this->entity->isNew()) {
    $menu_id = $this->entity->getMenuName();
    ......
    ......@@ -3,6 +3,7 @@
    namespace Drupal\menu_ui;
    use Drupal\Component\Utility\NestedArray;
    use Drupal\Component\Utility\SortArray;
    use Drupal\Core\Cache\CacheableMetadata;
    use Drupal\Core\Entity\EntityForm;
    use Drupal\Core\Form\FormStateInterface;
    ......@@ -434,6 +435,21 @@ protected function buildOverviewTreeForm($tree, $delta) {
    '#default_value' => $link->getParent(),
    ];
    $operations = $link->getOperations();
    if ($element->depth < $this->menuTree->maxDepth()) {
    $add_link_url = Url::fromRoute(
    'entity.menu.add_link_form',
    ['menu' => $this->entity->id()],
    ['query' => ['parent' => $link->getPluginId()]]
    );
    $operations += [
    'add-child' => [
    'title' => $this->t('Add child'),
    'weight' => 20,
    'url' => $add_link_url,
    ],
    ];
    uasort($operations, [SortArray::class, 'sortByWeightElement']);
    }
    foreach ($operations as $key => $operation) {
    if (!isset($operations[$key]['query'])) {
    // Bring the user back to the menu overview.
    ......
    ......@@ -504,6 +504,10 @@ public function doMenuTests() {
    $this->toggleMenuLink($item1);
    $this->toggleMenuLink($item2);
    // Test the "Add child" link for two siblings.
    $this->verifyAddChildLink($item5);
    $this->verifyAddChildLink($item6);
    // Move link and verify that descendants are updated.
    $this->moveMenuLink($item2, $item5->getPluginId(), $menu_name);
    // Hierarchy
    ......@@ -787,7 +791,7 @@ public function addInvalidMenuLink() {
    */
    public function checkInvalidParentMenuLinks() {
    $last_link = NULL;
    $created_links = [];
    $plugin_ids = [];
    // Get the max depth of the tree.
    $menu_link_tree = \Drupal::service('menu.link_tree');
    ......@@ -810,18 +814,28 @@ public function checkInvalidParentMenuLinks() {
    $this->submitForm($edit, 'Save');
    $menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(['title' => $title]);
    $last_link = reset($menu_links);
    $created_links[] = 'tools:' . $last_link->getPluginId();
    $plugin_ids[] = $last_link->getPluginId();
    }
    $last_plugin_id = array_pop($plugin_ids);
    // The last link cannot be a parent in the new menu link form.
    $this->drupalGet('admin/structure/menu/manage/tools/add');
    $value = 'tools:' . $last_link->getPluginId();
    $value = 'tools:' . $last_plugin_id;
    $this->assertSession()->optionNotExists('edit-menu-parent', $value);
    // All but the last link can be parents in the new menu link form.
    array_pop($created_links);
    foreach ($created_links as $key => $link) {
    $this->assertSession()->optionExists('edit-menu-parent', $link);
    foreach ($plugin_ids as $plugin_id) {
    $this->assertSession()->optionExists('edit-menu-parent', 'tools:' . $plugin_id);
    }
    // The last link does not have an "Add child" operation.
    $this->drupalGet('admin/structure/menu/manage/tools');
    $this->assertSession()->linkByHrefNotExists('parent=' . urlencode($last_plugin_id));
    // All but the last link do have an "Add child" operation.
    foreach ($plugin_ids as $plugin_id) {
    $this->assertSession()->linkByHrefExists('parent=' . urlencode($plugin_id));
    }
    }
    ......@@ -909,6 +923,25 @@ public function modifyMenuLink(MenuLinkContent $item) {
    $this->assertSession()->pageTextContains($title);
    }
    /**
    * Verifies that the "Add child" link selects the correct parent item.
    *
    * @param \Drupal\menu_link_content\Entity\MenuLinkContent $item
    * Menu link entity.
    */
    public function verifyAddChildLink(MenuLinkContent $item): void {
    $menu_name = $item->getMenuName();
    $this->drupalGet('admin/structure/menu/manage/' . $menu_name);
    $links = $this->xpath('//a[normalize-space()=:item_label]/following::a[normalize-space()=:link_label]', [
    ':item_label' => $item->getTitle(),
    ':link_label' => 'Add child',
    ]);
    $links[0]->click();
    $option = $this->assertSession()->optionExists('edit-menu-parent', $menu_name . ':' . $item->getPluginId());
    $this->assertTrue($option->isSelected());
    }
    /**
    * Resets a standard menu link using the UI.
    *
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment