entity-form.es6.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 behaviour 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.find('.entity-content-form-revision-information').drupalSetSummary((context) => {
  21. const $revisionContext = $(context);
  22. const revisionCheckbox = $revisionContext.find('.js-form-item-revision input');
  23. // Return 'New revision' if the 'Create new revision' checkbox is checked,
  24. // or if the checkbox doesn't exist, but the revision log does. For users
  25. // without the "Administer content" permission the checkbox won't appear,
  26. // but the revision log will if the content type is set to auto-revision.
  27. if (revisionCheckbox.is(':checked') || (!revisionCheckbox.length && $revisionContext.find('.js-form-item-revision-log textarea').length)) {
  28. return Drupal.t('New revision');
  29. }
  30. return Drupal.t('No revision');
  31. });
  32. $context.find('details.entity-translation-options').drupalSetSummary((context) => {
  33. const $translationContext = $(context);
  34. let translate;
  35. let $checkbox = $translationContext.find('.js-form-item-translation-translate input');
  36. if ($checkbox.length) {
  37. translate = $checkbox.is(':checked') ? Drupal.t('Needs to be updated') : Drupal.t('Does not need to be updated');
  38. }
  39. else {
  40. $checkbox = $translationContext.find('.js-form-item-translation-retranslate input');
  41. translate = $checkbox.is(':checked') ? Drupal.t('Flag other translations as outdated') : Drupal.t('Do not flag other translations as outdated');
  42. }
  43. return translate;
  44. });
  45. },
  46. };
  47. }(jQuery, Drupal));