Skip to:
Content

BuddyPress.org

Changeset 12358


Ignore:
Timestamp:
03/14/2019 05:37:11 AM (5 years ago)
Author:
imath
Message:

BP Nouveau: Improve Activity Post Form backcompat with legacy hooks

  • Make sure the bp_before_activity_post_form hook is fired inside the form tag.
  • Wrap action buttons and form options into the same container #whats-new-options.
  • Make sure the bp_activity_post_form_options is fired inside this container.

Fixes #8065

Location:
trunk/src/bp-templates/bp-nouveau
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/buddypress/common/js-templates/activity/form.php

    r12156 r12358  
    33 * Activity Post form JS Templates
    44 *
    5  * @version 3.1.0
     5 * @since 3.0.0
     6 * @version 5.0.0
    67 */
    78?>
     9
     10<script type="text/html" id="tmpl-activity-before-post-form-inputs">
     11    <?php bp_nouveau_activity_hook( 'before', 'post_form' ); ?>
     12</script>
    813
    914<script type="text/html" id="tmpl-activity-post-form-feedback">
  • trunk/src/bp-templates/bp-nouveau/includes/activity/functions.php

    r12283 r12358  
    44 *
    55 * @since 3.0.0
    6  * @version 3.1.0
     6 * @version 5.0.0
    77 */
    88
     
    6868        'user_id'     => bp_loggedin_user_id(),
    6969        'object'      => 'user',
    70         'backcompat'  => (bool) has_action( 'bp_activity_post_form_options' ),
     70        'backcompat'  => array(
     71            'before_post_form'  => (bool) has_action( 'bp_before_activity_post_form' ),
     72            'post_form_options' => (bool) has_action( 'bp_activity_post_form_options' ),
     73        ),
    7174        'post_nonce'  => wp_create_nonce( 'post_update', '_wpnonce_post_update' ),
    7275    );
  • trunk/src/bp-templates/bp-nouveau/includes/activity/template-tags.php

    r12348 r12358  
    44 *
    55 * @since 3.0.0
    6  * @version 3.1.0
     6 * @version 5.0.0
    77 */
    88
     
    6868 *
    6969 * @since 3.0.0
     70 * @since 5.0.0 Move the `bp_before_activity_post_form` hook inside the Activity post form.
    7071 */
    7172function bp_nouveau_before_activity_post_form() {
     
    7374        wp_enqueue_script( 'bp-nouveau-activity-post-form' );
    7475    }
    75 
    76     /**
    77      * Fires before the activity post form.
    78      *
    79      * @since 1.2.0
    80      */
    81     do_action( 'bp_before_activity_post_form' );
    8276}
    8377
  • trunk/src/bp-templates/bp-nouveau/js/buddypress-activity-post-form.js

    r12156 r12358  
    11/* global bp, BP_Nouveau, _, Backbone */
    2 /* @version 3.1.0 */
     2/* @since 3.0.0 */
     3/* @version 5.0.0 */
    34window.wp = window.wp || {};
    45window.bp = window.bp || {};
     
    376377    } );
    377378
     379    bp.Views.BeforeFormInputs = bp.View.extend( {
     380        tagName  : 'div',
     381        template : bp.template( 'activity-before-post-form-inputs' )
     382    } );
     383
    378384    bp.Views.FormTarget = bp.View.extend( {
    379385        tagName   : 'div',
     
    587593                ['user_id', 'item_id', 'object' ]
    588594            ) );
     595            this.options.backcompat = BP_Nouveau.activity.params.backcompat;
     596            var staticViews = [
     597                new bp.Views.FormAvatar(),
     598                new bp.Views.FormContent( { activity: this.model } )
     599            ];
     600
     601            // Backcompat to take the `bp_before_activity_post_form` action in account.
     602            if ( true === this.options.backcompat.before_post_form ) {
     603                staticViews.unshift( new bp.Views.BeforeFormInputs() );
     604            }
    589605
    590606            // Clone the model to set the resetted one
    591607            this.resetModel = this.model.clone();
    592608
    593             this.views.set( [
    594                 new bp.Views.FormAvatar(),
    595                 new bp.Views.FormContent( { activity: this.model } )
    596             ] );
     609            this.views.set( staticViews );
    597610
    598611            this.model.on( 'change:errors', this.displayFeedback, this );
     
    600613
    601614        displayFull: function( event ) {
     615            var numStaticViews = true === this.options.backcompat.before_post_form ? 3 : 2;
    602616
    603617            // Remove feedback.
    604618            this.cleanFeedback();
    605619
    606             if ( 2 !== this.views._views[''].length ) {
     620            if ( numStaticViews !== this.views._views[''].length ) {
    607621                return;
    608622            }
     
    613627            } );
    614628
    615             // Backcompat custom fields
    616             if ( true === BP_Nouveau.activity.params.backcompat ) {
     629            // Add the container view for buttons or custom fields.
     630            if ( true === this.options.backcompat.post_form_options ) {
    617631                this.views.add( new bp.Views.FormOptions( { model: this.model } ) );
     632            } else {
     633                this.views.add( new bp.View( { id: 'whats-new-options' } ) );
    618634            }
    619635
     
    622638                // Global
    623639                bp.Nouveau.Activity.postForm.buttons.set( BP_Nouveau.activity.params.buttons );
    624                 this.views.add( new bp.Views.FormButtons( { collection: bp.Nouveau.Activity.postForm.buttons, model: this.model } ) );
     640                this.views.add( '#whats-new-options', new bp.Views.FormButtons( { collection: bp.Nouveau.Activity.postForm.buttons, model: this.model } ) );
    625641            }
    626642
    627643            // Select box for the object
    628644            if ( ! _.isUndefined( BP_Nouveau.activity.params.objects ) && 1 < _.keys( BP_Nouveau.activity.params.objects ).length ) {
    629                 this.views.add( new bp.Views.FormTarget( { model: this.model } ) );
    630             }
    631 
    632             this.views.add( new bp.Views.FormSubmit( { model: this.model } ) );
     645                this.views.add( '#whats-new-options', new bp.Views.FormTarget( { model: this.model } ) );
     646            }
     647
     648            this.views.add( '#whats-new-options', new bp.Views.FormSubmit( { model: this.model } ) );
    633649        },
    634650
    635651        resetForm: function() {
     652            var self = this, indexStaticViews = self.options.backcompat.before_post_form ? 2 : 1;
     653
    636654            _.each( this.views._views[''], function( view, index ) {
    637                 if ( index > 1 ) {
     655                if ( index > indexStaticViews ) {
    638656                    view.remove();
    639657                }
Note: See TracChangeset for help on using the changeset viewer.