node.es6.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @file
  3. * Defines Javascript behaviors for the node module.
  4. */
  5. (function ($, Drupal, drupalSettings) {
  6. /**
  7. * Behaviors for tabs in the node edit form.
  8. *
  9. * @type {Drupal~behavior}
  10. *
  11. * @prop {Drupal~behaviorAttach} attach
  12. * Attaches summary behavior for tabs in the node edit form.
  13. */
  14. Drupal.behaviors.nodeDetailsSummaries = {
  15. attach(context) {
  16. const $context = $(context);
  17. $context.find('.node-form-author').drupalSetSummary((context) => {
  18. const $authorContext = $(context);
  19. const name = $authorContext.find('.field--name-uid input').val();
  20. const date = $authorContext.find('.field--name-created input').val();
  21. if (name && date) {
  22. return Drupal.t('By @name on @date', { '@name': name, '@date': date });
  23. }
  24. else if (name) {
  25. return Drupal.t('By @name', { '@name': name });
  26. }
  27. else if (date) {
  28. return Drupal.t('Authored on @date', { '@date': date });
  29. }
  30. });
  31. $context.find('.node-form-options').drupalSetSummary((context) => {
  32. const $optionsContext = $(context);
  33. const vals = [];
  34. if ($optionsContext.find('input').is(':checked')) {
  35. $optionsContext.find('input:checked').next('label').each(function () {
  36. vals.push(Drupal.checkPlain($.trim($(this).text())));
  37. });
  38. return vals.join(', ');
  39. }
  40. return Drupal.t('Not promoted');
  41. });
  42. },
  43. };
  44. }(jQuery, Drupal, drupalSettings));