Creating your own fieldtype

DataGrab has the ability to register custom 3rd party fieldtypes.

To add a custom fieldtype add add the folder "datagrab_fieldytpes" in the addons directory at the same level as your "datagrab" add-on folder. For example:

If you create a file with the same name as an existing file in the datagrab/fieldtypes directory, it will be loaded first, effectively giving you the ability to override core DataGrab functionality. With great power comes great responsibility. While we provide the ability to do this, we do not offer support for debugging or assisting creating these override files. You're on your own should you choose this path.

Your datatype class will need to extend the AbstractDataType class. At minimum it will need to implement a few methods.

<?php

class Datagrab_my_fieldtype extends AbstractFieldType
{
    public function register_setting(string $fieldName)
    {
    }

    public function display_configuration(Datagrab_model $DG, string $fieldName, string $fieldLabel, string $fieldType, bool $fieldRequired = false, array $data = []): array
    {
    }
    
    // Optional
    public function final_post_data(Datagrab_model $DG, array $item = [], int $fieldId = 0, string $fieldName = '', array &$data = [], int $updateEntryId = 0)
    {
    }
    
    // Optional
    public function prepare_post_data(Datagrab_model $DG, array $item = [], int $fieldId = 0, string $fieldName = '', array &$data = [], int $updateEntryId = 0)
    {
    }
}

Last updated