entity-form.js 2.1 KB

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