Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/21/2021 02:17:21 PM (3 years ago)
Author:
imath
Message:

Field Types can now declare supported features & field visibility

  • Edit the JavaScript file used by the xProfile Create field Administration screen to handle Field types requirements by showing/hiding screen metaboxes according to feature supports and to get ride of some jQuery deprecated methods.
  • Improve the xProfile Field API to take in account xProfile Field Types declared feature supports by adding two new methods to get (BP_XProfile_Field->get_field_type_supports()) & check (BP_XProfile_Field->field_type_supports( $feature_name )) the field type supported features.
  • The xProfile Create field Administration Screen Metaboxes displayed to set the field properties can now be disabled by the Field Type using the static variable $supported_features. See tests/phpunit/assets/bptest-xprofile-field-type.php for an example of use.
  • Improve the xProfile Field API to take in account the xProfile Field Types visibility property to use as default field visibility. NB: setting this Field Type visibility and its allow_custom_visibility feature support to false, a Field Type can now enforce the visibility to use for a field.
  • Introduce a new xProfile Fields loop argument $hide_field_types to avoid displaying fields according to an array of Field types. To customize this new argument you can use the bp_before_has_profile_parse_args filter for existing xProfile loop. For instance you can avoid to list xProfile fields according to their type from the WP-Admin/Extended profile screen checking the corresponding Administration Screen ID.
  • Add PHP unit tests to verify these improvements are working the right way.

Props DJPaul, Offereins, needle, netweb, vapvarun

See #7162

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/xprofile/class-bp-xprofile-field-type.php

    r12697 r12868  
    11<?php
     2// Include the xProfile Test Type
     3include_once BP_TESTS_DIR . 'assets/bptest-xprofile-field-type.php';
     4
    25/**
    36 * @group xprofile
     
    58 */
    69class BP_Tests_XProfile_Field_Type extends BP_UnitTestCase {
     10
     11    public function setUp() {
     12        parent::setUp();
     13
     14        add_filter( 'bp_xprofile_get_field_types', array( $this, 'get_field_types' ) );
     15    }
     16
     17    public function tearDown() {
     18        parent::tearDown();
     19
     20        remove_filter( 'bp_xprofile_get_field_types', array( $this, 'get_field_types' ) );
     21    }
     22
    723    public function test_unregistered_field_type_returns_textbox() {
    824        $field = bp_xprofile_create_field_type( 'fakeyfield' );
     
    184200        $this->assertTrue( $field->is_valid( '(212) 664-7665' ) );
    185201    }
     202
     203    /**
     204     * @ticket BP7162
     205     */
     206    public function test_xprofile_field_type_test_supports() {
     207        $group_id = self::factory()->xprofile_group->create();
     208        $field_id = self::factory()->xprofile_field->create(
     209            array(
     210                'field_group_id' => $group_id,
     211                'type'           => 'test-field-type',
     212                'name'           => 'Test Supports',
     213            )
     214        );
     215
     216        $field = xprofile_get_field( $field_id, null, false );
     217
     218        $this->assertTrue( $field->field_type_supports( 'switch_fieldtype' ) );
     219        $this->assertFalse( $field->field_type_supports( 'do_autolink' ) );
     220        $this->assertFalse( $field->field_type_supports( 'allow_custom_visibility' ) );
     221        $this->assertTrue( $field->field_type_supports( 'required' ) );
     222        $this->assertTrue( $field->field_type_supports( 'member_types' ) );
     223        $this->assertEquals( 'adminsonly', $field->get_default_visibility() );
     224    }
     225
     226    public function get_field_types( $types ) {
     227        $types['test-field-type'] = 'BPTest_XProfile_Field_Type';
     228        return $types;
     229    }
    186230}
Note: See TracChangeset for help on using the changeset viewer.