Extending FES Like the Booking Form?

This topic contains 4 replies, has 3 voices, and was last updated by  Sadik Bhimani 7 years, 5 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #24540

    I’ve been doing a lot of looking through the site docs and through the codebase and am having a problems trying to figure out how to add custom field types to the form customizer (and then customizing the output on the front-end).

    As the most basic example, we have a custom taxonomy registered to events. We would like people to be able to add a dropdown for the custom taxonomy to their submission forms just like with categories and tags.

    I found the custom-taxonomies.php file which seems to hook into eventorganiser_event_form_element_types and looks like it should already be adding any object taxonomies registered to the event CPT (which I have registered both through the eventorganiser_event_properties hook and through register_taxonomy‘s second parameter. Tried adjusting the priority on the hook with no luck. Maybe this just isn’t linked up yet?

    I understand that there already seems to be a well documented API for adding custom fields to the booking form via hooks and element factories. Does this functionality exist for FES in some sort of undocumented state? I’m sure it is something you are working towards but wondering what is available as of now.

    P.S. for now, we have been able to use the ability to specify a hook name to render custom fields, but it’s not the most user friendly option! However, it works – so good looks.

    Brian Hanna
    #24604

    Hi Brian,

    That is what the file is intending to do, however there appears to be a bug (the registering of the form element happens before the taxonomies). I shall look into this and get back to you.

    Stephen Harris
    #24708

    Hi Brian,

    Apologies for the delay in getting back to you. Here is a snippet that will register a form field for a custom taxonomy (it will allow users to select on or more terms from the taxonomy, but not create new terms). For the purposes of the example, I’m using a custom taxonomy event-type:

    add_action( 'eventorganiser_event_form_element_types', 'eventorganiser_fes_add_my_custom_tax' );
    function eventorganiser_fes_add_my_custom_tax( $element_types ){
        //The key should be event_ct_{taxonomy}
        $element_types['event']['event_ct_event-type'] = 'EO_Event_Form_Element_Event_Type_Taxonomy';
        return $element_types;
    }
    
    
    /**
     * The Form element class
     */
    class EO_Event_Form_Element_Event_Type_Taxonomy extends EO_Event_Form_Element_Custom_Taxonomy{
    
        //The type property should match the key above
        //i.e. it should be of the form event_ct_{taxonomy}
        public $type = 'event_ct_event-type';
    
        //The name as it appears in the form customiser
        static function get_type_name(){
            return 'Event type';
        }
    }
    
    //You can create your own view class, but there is a default 
    //template you can use.
    class EO_Event_Form_Element_Event_Type_Taxonomy_View extends EO_Event_Form_Element_View{
        public $template = 'elements/eo-event-form-custom-taxonomy.php';
    }
    
    Stephen Harris
    #27929

    HI Stephen, I want to do the same thing. But I am unable to get the above to work. What i have done is in my child theme’s functions.php, I have added the code you have provided, changing the key to match my custom taxonomy name (job_listing_region).

    Also in my register_taxonomy call, I have added the event post type. This makes the taxonomy appear when creating events in admin backend. However the custom taxonomy field does not appear in the Event Submission Form options for FES in admin.

    Here is what I have done,

    In my child theme’s functions.php,

    require_once( __DIR__ . '/includes/fes_city.php');
    

    Then in fes_city.php

    <?php
    add_filter('eventorganiser_event_properties', 'hk_event_fes_city', 10, 1);
    
    function hk_event_fes_city($args)
    {
        $args['taxonomies'][] = 'job_listing_region';
    
        return $args;
    }
    
    add_action('eventorganiser_event_form_element_types', 'eventorganiser_fes_add_city');
    
    function eventorganiser_fes_add_city($element_types)
    {
        //The key should be event_ct_{taxonomy}
        $element_types['event']['event_ct_job_listing_region'] = 'EO_Event_Form_Element_Event_Type_Taxonomy';
        return $element_types;
    }
    
    /**
     * The Form element class
     */
    class EO_Event_Form_Element_Event_Type_Taxonomy extends EO_Event_Form_Element_Custom_Taxonomy
    {
        //The type property should match the key above
        //i.e. it should be of the form event_ct_{taxonomy}
        public $type = 'event_ct_job_listing_region';
    
        //The name as it appears in the form customiser
        static function get_type_name()
        {
            return 'City';
        }
    
    }
    
    //You can create your own view class, but there is a default 
    //template you can use.
    class EO_Event_Form_Element_Event_Type_Taxonomy_View extends EO_Event_Form_Element_View
    {
        public $template = 'elements/eo-event-form-custom-taxonomy.php';
    
    }
    

    What am I missing?

    Thanks for your help.

    Sadik Bhimani
    #27931

    OK I was able to solve this. Here’s my final code if anyone wants to do the same thing. Note that this needs to be a plugin and cannot go in your theme’s functions.php, because the filter needs to be added (inside a plugin) before the apply_filters is run, as per wordpress hierarchy of execution.

    add_filter('eventorganiser_event_form_element_types', 'eventorganiser_fes_add_city');
    
    function eventorganiser_fes_add_city($element_types)
    {
        //The key should be event_ct_{taxonomy}
        $element_types['event']['event_ct_job_listing_region'] = 'EO_Event_Form_Element_Event_Type_Taxonomy';
    
        return $element_types;
    }
    
    /**
     * The Form element class
     */
    class EO_Event_Form_Element_Event_Type_Taxonomy extends EO_Event_Form_Element_Custom_Taxonomy
    {
        //The type property should match the key above
        //i.e. it should be of the form event_ct_{taxonomy}
        public $type = 'event_ct_job_listing_region';
    
        //The name as it appears in the form customiser
        static function get_type_name()
        {
            return 'Event City';
        }
    }
    
    //You can create your own view class, but there is a default 
    //template you can use.
    class EO_Event_Form_Element_Event_Type_Taxonomy_View extends EO_Event_Form_Element_View
    {
        public $template = 'eo-event-form-custom-taxonomy.php';
    }
    
    Sadik Bhimani
Viewing 5 posts - 1 through 5 (of 5 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.