6 (function ($, Drupal) {
11 * Set a summary on the menu link form.
13 * @type {Drupal~behavior}
15 * @prop {Drupal~behaviorAttach} attach
16 * Find the form and call `drupalSetSummary` on it.
18 Drupal.behaviors.menuUiDetailsSummaries = {
19 attach: function (context) {
20 $(context).find('.menu-link-form').drupalSetSummary(function (context) {
21 var $context = $(context);
22 if ($context.find('.js-form-item-menu-enabled input').is(':checked')) {
23 return Drupal.checkPlain($context.find('.js-form-item-menu-title input').val());
26 return Drupal.t('Not in menu');
33 * Automatically fill in a menu link title, if possible.
35 * @type {Drupal~behavior}
37 * @prop {Drupal~behaviorAttach} attach
38 * Attaches change and keyup behavior for automatically filling out menu
41 Drupal.behaviors.menuUiLinkAutomaticTitle = {
42 attach: function (context) {
43 var $context = $(context);
44 $context.find('.menu-link-form').each(function () {
46 // Try to find menu settings widget elements as well as a 'title' field
47 // in the form, but play nicely with user permissions and form
49 var $checkbox = $this.find('.js-form-item-menu-enabled input');
50 var $link_title = $context.find('.js-form-item-menu-title input');
51 var $title = $this.closest('form').find('.js-form-item-title-0-value input');
52 // Bail out if we do not have all required fields.
53 if (!($checkbox.length && $link_title.length && $title.length)) {
56 // If there is a link title already, mark it as overridden. The user
57 // expects that toggling the checkbox twice will take over the node's
59 if ($checkbox.is(':checked') && $link_title.val().length) {
60 $link_title.data('menuLinkAutomaticTitleOverridden', true);
62 // Whenever the value is changed manually, disable this behavior.
63 $link_title.on('keyup', function () {
64 $link_title.data('menuLinkAutomaticTitleOverridden', true);
66 // Global trigger on checkbox (do not fill-in a value when disabled).
67 $checkbox.on('change', function () {
68 if ($checkbox.is(':checked')) {
69 if (!$link_title.data('menuLinkAutomaticTitleOverridden')) {
70 $link_title.val($title.val());
75 $link_title.removeData('menuLinkAutomaticTitleOverridden');
77 $checkbox.closest('.vertical-tabs-pane').trigger('summaryUpdated');
78 $checkbox.trigger('formUpdated');
80 // Take over any title change.
81 $title.on('keyup', function () {
82 if (!$link_title.data('menuLinkAutomaticTitleOverridden') && $checkbox.is(':checked')) {
83 $link_title.val($title.val());
84 $link_title.val($title.val()).trigger('formUpdated');