Skip to:
Content

BuddyPress.org

Changeset 11144


Ignore:
Timestamp:
09/21/2016 10:40:12 PM (3 years ago)
Author:
r-a-y
Message:

Groups: In bp_groups_register_group_type(), introduce new arguments for frontend integration.

This commit introduces the following $args parameters:

  • 'has_directory'
  • 'show_in_create_screen'
  • 'show_in_list'
  • 'description'

Read the inline documentation for full information. The Group Types codex
article will be updated to outline these parameters.

See #7210.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-functions.php

    r11142 r11144  
    21162116 *
    21172117 * @since 2.6.0
     2118 * @since 2.7.0 Introduce $has_directory, $show_in_create_screen, $show_in_list, and
     2119 *              $description as $args parameters.
    21182120 *
    21192121 * @param string $group_type Unique string identifier for the group type.
     
    21212123 *     Array of arguments describing the group type.
    21222124 *
    2123  *     @type array $labels {
     2125 *     @type string|bool $has_directory         Set the slug to be used for custom group directory page. eg.
     2126 *                                              example.com/groups/type/MY_SLUG. Default: false.
     2127 *     @type bool        $show_in_create_screen Whether this group type is allowed to be selected on the group creation
     2128 *                                              page. Default: false.
     2129 *     @type bool|null   $show_in_list          Whether this group type should be shown in lists rendered by
     2130 *                                              bp_group_type_list(). Default: null. If $show_in_create_screen is true,
     2131 *                                              this will default to true, unless this is set explicitly to false.
     2132 *     @type string      $description           A short descriptive summary of what the group type is. Currently shown
     2133 *                                              on a group's "Manage > Settings" page when selecting group types.
     2134 *     @type array       $labels {
    21242135 *         Array of labels to use in various parts of the interface.
    21252136 *
     
    21382149
    21392150    $r = bp_parse_args( $args, array(
    2140         'labels'        => array(),
     2151        'has_directory'         => false,
     2152        'show_in_create_screen' => false,
     2153        'show_in_list'          => null,
     2154        'description'           => '',
     2155        'labels'                => array(),
    21412156    ), 'register_group_type' );
    21422157
     
    21682183        'singular_name' => $default_name,
    21692184    ), $r['labels'] );
     2185
     2186    // Directory slug.
     2187    if ( ! empty( $r['has_directory'] ) ) {
     2188        // A string value is intepreted as the directory slug.
     2189        if ( is_string( $r['has_directory'] ) ) {
     2190            $directory_slug = $r['has_directory'];
     2191
     2192        // Otherwise fall back on group type.
     2193        } else {
     2194            $directory_slug = $group_type;
     2195        }
     2196
     2197        // Sanitize for use in URLs.
     2198        $r['directory_slug'] = sanitize_title( $directory_slug );
     2199        $r['has_directory']  = true;
     2200    } else {
     2201        $r['directory_slug'] = '';
     2202        $r['has_directory']  = false;
     2203    }
     2204
     2205    // Type lists.
     2206    if ( true === $r['show_in_create_screen'] && is_null( $r['show_in_list'] ) ) {
     2207        $r['show_in_list'] = true;
     2208    } else {
     2209        $r['show_in_list'] = (bool) $r['show_in_list'];
     2210    }
    21702211
    21712212    $bp->groups->types[ $group_type ] = $type = (object) $r;
  • trunk/tests/phpunit/testcases/groups/types.php

    r11142 r11144  
    265265    }
    266266
     267    public function test_bp_groups_register_group_type_show_in_list_true_when_show_in_create_screen_true() {
     268        $object = bp_groups_register_group_type( 'foo', array(
     269            'show_in_create_screen' => true,
     270        ) );
     271
     272        $this->assertTrue( $object->show_in_list );
     273    }
     274
     275    public function test_bp_groups_register_group_type_show_in_list_false_when_show_in_create_screen_false() {
     276        $object = bp_groups_register_group_type( 'foo', array(
     277            'show_in_create_screen' => false,
     278        ) );
     279
     280        $this->assertFalse( $object->show_in_list );
     281    }
     282
     283    public function test_bp_groups_register_group_type_show_in_list_false_and_show_in_create_screen_true() {
     284        $object = bp_groups_register_group_type( 'foo', array(
     285            'show_in_create_screen' => true,
     286            'show_in_list' => false,
     287        ) );
     288
     289        $this->assertFalse( $object->show_in_list );
     290    }
     291
     292    public function test_bp_groups_set_group_type_should_remove_types_when_passing_an_empty_value() {
     293        $g = $this->factory->group->create( array( 'creator_id' => self::$u1 ) );
     294        bp_groups_register_group_type( 'foo' );
     295        bp_groups_set_group_type( $g, 'foo' );
     296
     297        // Make sure it's set up.
     298        $this->assertSame( 'foo', bp_groups_get_group_type( $g ) );
     299
     300        $this->assertSame( array(), bp_groups_set_group_type( $g, '' ) );
     301        $this->assertFalse( bp_groups_get_group_type( $g ) );
     302    }
     303
    267304    public function test_bp_groups_set_group_type_should_set_multiple_types_when_passing_array_of_types() {
    268305        $g = $this->factory->group->create( array( 'creator_id' => self::$u1 ) );
Note: See TracChangeset for help on using the changeset viewer.