Support

Account

Home Forums Bug Reports Custom field type throws fatal error

Solving

Custom field type throws fatal error

  • I’ve been maintaining a plugin which provides a custom field type for the selection of a Gravity Form.

    Recently, adding a field which uses this field type as a subfield of a Flexible Content field throws a fatal error:

    Fatal error: Uncaught Error: Call to undefined method stdClass::get_rest_schema() in /path/to/local/install/app/public/wp-content/plugins/advanced-custom-fields-pro/includes/rest-api/acf-rest-api-functions.php on line 11

    Another user is getting the following error, but I can’t confirm this in my installation (yet).

    Fatal error: Uncaught Error: Call to undefined method stdClass::format_value_for_rest() in /path/to/local/install/app/public/wp-content/plugins/advanced-custom-fields-pro/includes/rest-api/acf-rest-api-functions.php on line 69

    My code is based on this template code. According to the documentation, the class method get_rest_schema can be added to override the REST response, but there is no indication that this must be defined.

    Is this error being thrown because of ACF or in my custom field type?

    (Additional: the documentation uses the syntax acf_field::get_rest_schema() but the method get_rest_schema isn’t static, so using it in that way also throws an error.)

  • I made an account just for this post. I’m also having roughly the same issues. I’m trying to access a custom post type in the rest api, but get the follow stack trace:

    [14-Mar-2022 15:30:35 UTC] PHP Fatal error:  Uncaught Error: Call to undefined method stdClass::get_rest_schema() in /Users/nnn/Local Sites/ff2022/app/public/wp-content/plugins/advanced-custom-fields-pro/includes/rest-api/acf-rest-api-functions.php:11
    Stack trace:
    #0 /Users/nnn/Local Sites/ff2022/app/public/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-flexible-content.php(1780): acf_get_field_rest_schema(Array)
    #1 /Users/nnn/Local Sites/ff2022/app/public/wp-content/plugins/advanced-custom-fields-pro/includes/rest-api/acf-rest-api-functions.php(12): acf_field_flexible_content->get_rest_schema(Array)
    #2 /Users/nnn/Local Sites/ff2022/app/public/wp-content/plugins/advanced-custom-fields-pro/includes/rest-api/class-acf-rest-api.php(112): acf_get_field_rest_schema(Array)
    #3 /Users/nnn/Local Sites/ff2022/app/public/wp-content/plugins/advanced-custom-fields-pro/includes/rest-api/class-acf-rest-api.php(64): ACF_Rest_Api->get_schema()
    #4 /Users/nnn/Local Sites/ff2022/app/public/wp-content in /Users/jordanlewis/Local Sites/ff2022/app/public/wp-content/plugins/advanced-custom-fields-pro/includes/rest-api/acf-rest-api-functions.php on line 11

    The custom post type has flexible content available to it, and this flexible content has quite a few layouts. When I query a different custom post type that does not have flexible content available to it, I’m able to get the information.

  • There is not a get_rest_schema() method in the base class “acf_field”. The custom field template code was last updated 4 years ago. I assume that this function was added to the classes for each custom field after that.

    You will need to create this method in your new class.

    I do not know how this works. The only suggestion I can make is that you look at this method ACF’s custom field classes to see how it works to figure out what you need to do.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.