Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / misc / entity-form.es6.js
1 /**
2  * @file
3  * Defines Javascript behaviors for the block_content module.
4  */
5
6 (function($, Drupal) {
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(context) {
20       const $context = $(context);
21       $context
22         .find('.entity-content-form-revision-information')
23         .drupalSetSummary(context => {
24           const $revisionContext = $(context);
25           const revisionCheckbox = $revisionContext.find(
26             '.js-form-item-revision input',
27           );
28
29           // Return 'New revision' if the 'Create new revision' checkbox is checked,
30           // or if the checkbox doesn't exist, but the revision log does. For users
31           // without the "Administer content" permission the checkbox won't appear,
32           // but the revision log will if the content type is set to auto-revision.
33           if (
34             revisionCheckbox.is(':checked') ||
35             (!revisionCheckbox.length &&
36               $revisionContext.find('.js-form-item-revision-log textarea')
37                 .length)
38           ) {
39             return Drupal.t('New revision');
40           }
41
42           return Drupal.t('No revision');
43         });
44
45       $context
46         .find('details.entity-translation-options')
47         .drupalSetSummary(context => {
48           const $translationContext = $(context);
49           let translate;
50           let $checkbox = $translationContext.find(
51             '.js-form-item-translation-translate input',
52           );
53
54           if ($checkbox.length) {
55             translate = $checkbox.is(':checked')
56               ? Drupal.t('Needs to be updated')
57               : Drupal.t('Does not need to be updated');
58           } else {
59             $checkbox = $translationContext.find(
60               '.js-form-item-translation-retranslate input',
61             );
62             translate = $checkbox.is(':checked')
63               ? Drupal.t('Flag other translations as outdated')
64               : Drupal.t('Do not flag other translations as outdated');
65           }
66
67           return translate;
68         });
69     },
70   };
71 })(jQuery, Drupal);