entity-form.es6.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @file
  3. * Defines Javascript behaviors for the block_content module.
  4. */
  5. (function($, Drupal) {
  6. /**
  7. * Sets summaries about revision and translation of entities.
  8. *
  9. * @type {Drupal~behavior}
  10. *
  11. * @prop {Drupal~behaviorAttach} attach
  12. * Attaches summary behavior entity form tabs.
  13. *
  14. * Specifically, it updates summaries to the revision information and the
  15. * translation options.
  16. */
  17. Drupal.behaviors.entityContentDetailsSummaries = {
  18. attach(context) {
  19. const $context = $(context);
  20. $context
  21. .find('.entity-content-form-revision-information')
  22. .drupalSetSummary(context => {
  23. const $revisionContext = $(context);
  24. const revisionCheckbox = $revisionContext.find(
  25. '.js-form-item-revision input',
  26. );
  27. // Return 'New revision' if the 'Create new revision' checkbox is checked,
  28. // or if the checkbox doesn't exist, but the revision log does. For users
  29. // without the "Administer content" permission the checkbox won't appear,
  30. // but the revision log will if the content type is set to auto-revision.
  31. if (
  32. revisionCheckbox.is(':checked') ||
  33. (!revisionCheckbox.length &&
  34. $revisionContext.find('.js-form-item-revision-log textarea')
  35. .length)
  36. ) {
  37. return Drupal.t('New revision');
  38. }
  39. return Drupal.t('No revision');
  40. });
  41. $context
  42. .find('details.entity-translation-options')
  43. .drupalSetSummary(context => {
  44. const $translationContext = $(context);
  45. let translate;
  46. let $checkbox = $translationContext.find(
  47. '.js-form-item-translation-translate input',
  48. );
  49. if ($checkbox.length) {
  50. translate = $checkbox.is(':checked')
  51. ? Drupal.t('Needs to be updated')
  52. : Drupal.t('Does not need to be updated');
  53. } else {
  54. $checkbox = $translationContext.find(
  55. '.js-form-item-translation-retranslate input',
  56. );
  57. translate = $checkbox.is(':checked')
  58. ? Drupal.t('Flag other translations as outdated')
  59. : Drupal.t('Do not flag other translations as outdated');
  60. }
  61. return translate;
  62. });
  63. },
  64. };
  65. })(jQuery, Drupal);