Changeset 38513
- Timestamp:
- 09/02/2016 10:34:48 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/customize-controls.js
r38492 r38513 3462 3462 if ( _.isObject( validity ) ) { 3463 3463 _.each( validity, function( params, code ) { 3464 var notification = new api.Notification( code, params ), existingNotification, needsReplacement = false; 3464 var notification, existingNotification, needsReplacement = false; 3465 notification = new api.Notification( code, _.extend( { fromServer: true }, params ) ); 3465 3466 3466 3467 // Remove existing notification if already exists for code but differs in parameters. 3467 3468 existingNotification = setting.notifications( notification.code ); 3468 3469 if ( existingNotification ) { 3469 needsReplacement = ( notification.type !== existingNotification.type )|| ! _.isEqual( notification.data, existingNotification.data );3470 needsReplacement = notification.type !== existingNotification.type || notification.message !== existingNotification.message || ! _.isEqual( notification.data, existingNotification.data ); 3470 3471 } 3471 3472 if ( needsReplacement ) { … … 3716 3717 api.each( function( setting ) { 3717 3718 setting.notifications.each( function( notification ) { 3718 if ( 'error' === notification.type && ( ! notification.data || ! notification.data.from_server )) {3719 if ( 'error' === notification.type && ! notification.fromServer ) { 3719 3720 invalidSettings.push( setting.id ); 3720 3721 } -
trunk/src/wp-includes/class-wp-customize-manager.php
r38470 r38513 1047 1047 $notification = array(); 1048 1048 foreach ( $validity->errors as $error_code => $error_messages ) { 1049 $error_data = $validity->get_error_data( $error_code );1050 if ( is_null( $error_data ) ) {1051 $error_data = array();1052 }1053 $error_data = array_merge(1054 $error_data,1055 array( 'from_server' => true )1056 );1057 1049 $notification[ $error_code ] = array( 1058 1050 'message' => join( ' ', $error_messages ), 1059 'data' => $ error_data,1051 'data' => $validity->get_error_data( $error_code ), 1060 1052 ); 1061 1053 } -
trunk/src/wp-includes/js/customize-base.js
r37476 r38513 763 763 * @since 4.6.0 764 764 * 765 * @param {string} code The error code. 766 * @param {object} params Params. 767 * @param {string} params.message The error message. 768 * @param {string} [params.type=error] The notification type. 769 * @param {*} [params.data] Any additional data. 765 * @param {string} code - The error code. 766 * @param {object} params - Params. 767 * @param {string} params.message=null - The error message. 768 * @param {string} [params.type=error] - The notification type. 769 * @param {boolean} [params.fromServer=false] - Whether the notification was server-sent. 770 * @param {string} [params.setting=null] - The setting ID that the notification is related to. 771 * @param {*} [params.data=null] - Any additional data. 770 772 */ 771 773 api.Notification = api.Class.extend({ 772 774 initialize: function( code, params ) { 775 var _params; 773 776 this.code = code; 774 this.message = params.message; 775 this.type = params.type || 'error'; 776 this.data = params.data || null; 777 _params = _.extend( 778 { 779 message: null, 780 type: 'error', 781 fromServer: false, 782 data: null, 783 setting: null 784 }, 785 params 786 ); 787 delete _params.code; 788 _.extend( this, _params ); 777 789 } 778 790 }); -
trunk/tests/phpunit/tests/customize/manager.php
r37942 r38513 304 304 $this->assertTrue( $this->manager->prepare_setting_validity_for_js( true ) ); 305 305 $error = new WP_Error(); 306 $error->add( 'bad_letter', 'Bad letter' );307 $error->add( 'bad_letter', 'Bad letra' );306 $error->add( 'bad_letter', 'Bad letter', 'A' ); 307 $error->add( 'bad_letter', 'Bad letra', 123 ); 308 308 $error->add( 'bad_number', 'Bad number', array( 'number' => 123 ) ); 309 309 $validity = $this->manager->prepare_setting_validity_for_js( $error ); … … 314 314 $this->assertEquals( join( ' ', $messages ), $validity[ $code ]['message'] ); 315 315 $this->assertArrayHasKey( 'data', $validity[ $code ] ); 316 $this->assert ArrayHasKey( 'from_server', $validity[ $code ]['data']);316 $this->assertEquals( $validity[ $code ]['data'], $error->get_error_data( $code ) ); 317 317 } 318 318 $this->assertArrayHasKey( 'number', $validity['bad_number']['data'] ); -
trunk/tests/qunit/wp-admin/js/customize-base.js
r37476 r38513 165 165 'message': 'Hello World', 166 166 'type': 'update', 167 'setting': 'blogname', 168 'fromServer': true, 167 169 'data': { 'foo': 'bar' } 168 170 } ); … … 171 173 assert.equal( 'Hello World', notification.message ); 172 174 assert.equal( 'update', notification.type ); 175 assert.equal( 'blogname', notification.setting ); 176 assert.equal( true, notification.fromServer ); 173 177 assert.deepEqual( { 'foo': 'bar' }, notification.data ); 174 178
Note: See TracChangeset
for help on using the changeset viewer.