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:

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

Was this helpful?