6 (function ($, Drupal) {
8 * Set a summary on the menu link form.
10 * @type {Drupal~behavior}
12 * @prop {Drupal~behaviorAttach} attach
13 * Find the form and call `drupalSetSummary` on it.
15 Drupal.behaviors.menuUiDetailsSummaries = {
17 $(context).find('.menu-link-form').drupalSetSummary((context) => {
18 const $context = $(context);
19 if ($context.find('.js-form-item-menu-enabled input').is(':checked')) {
20 return Drupal.checkPlain($context.find('.js-form-item-menu-title input').val());
23 return Drupal.t('Not in menu');
29 * Automatically fill in a menu link title, if possible.
31 * @type {Drupal~behavior}
33 * @prop {Drupal~behaviorAttach} attach
34 * Attaches change and keyup behavior for automatically filling out menu
37 Drupal.behaviors.menuUiLinkAutomaticTitle = {
39 const $context = $(context);
40 $context.find('.menu-link-form').each(function () {
41 const $this = $(this);
42 // Try to find menu settings widget elements as well as a 'title' field
43 // in the form, but play nicely with user permissions and form
45 const $checkbox = $this.find('.js-form-item-menu-enabled input');
46 const $link_title = $context.find('.js-form-item-menu-title input');
47 const $title = $this.closest('form').find('.js-form-item-title-0-value input');
48 // Bail out if we do not have all required fields.
49 if (!($checkbox.length && $link_title.length && $title.length)) {
52 // If there is a link title already, mark it as overridden. The user
53 // expects that toggling the checkbox twice will take over the node's
55 if ($checkbox.is(':checked') && $link_title.val().length) {
56 $link_title.data('menuLinkAutomaticTitleOverridden', true);
58 // Whenever the value is changed manually, disable this behavior.
59 $link_title.on('keyup', () => {
60 $link_title.data('menuLinkAutomaticTitleOverridden', true);
62 // Global trigger on checkbox (do not fill-in a value when disabled).
63 $checkbox.on('change', () => {
64 if ($checkbox.is(':checked')) {
65 if (!$link_title.data('menuLinkAutomaticTitleOverridden')) {
66 $link_title.val($title.val());
71 $link_title.removeData('menuLinkAutomaticTitleOverridden');
73 $checkbox.closest('.vertical-tabs-pane').trigger('summaryUpdated');
74 $checkbox.trigger('formUpdated');
76 // Take over any title change.
77 $title.on('keyup', () => {
78 if (!$link_title.data('menuLinkAutomaticTitleOverridden') && $checkbox.is(':checked')) {
79 $link_title.val($title.val());
80 $link_title.val($title.val()).trigger('formUpdated');