2

I have a Craft 2 project which is using an older version of the FeedMe plugin 1.x. In order to use a specific XML feed this site uses, a custom XML feed service was implemented with a custom feed type available to select from the feed type option in Craft FeedMe back-end, but this involved directly editing the FeedMe plugin files.

The reason for this is because a specific authentication mechanism is required before being able to interact with the feed in the form of a unique token passed by the Authorization HTTP header obtained from a separate auth endpoint first. This is then added to the feed request via curl, so its authenticated and returns data.

The current implementation added an additional service within feedme/services/ which extends FeedMe_FeedXMLService to handle the token authorisation part and added an additional enum type, record type, model type. In theory could a separate plugin be created that provides the service without having to modify the core plugin? Or could the approach be different given the changes with the 2.x version of the plugin?

It looks v2.x has changed quite a bit looking at the core plugin files with potentially more options for customisation, but I'm not sure if the implementation we have is possible to move to 2.x easily.

1 Answer 1

1

So, here's what I've found after after some research. It is certainly possible to create your own datatypes. Support for it, looks to have been added since around 2.0.1. Previously, the feed type field wasn't able to have custom types as it was a fixed list, but with hooks it is now possible. There is a great plugin that shows how to add custom data types here:

https://github.com/surprisehighway/craft-feedmehelper

You do need a Pro license to use custom data types however.

Unfortunately, the documentation for data types is currently TBA on Verbb's website: https://verbb.io/craft-plugins/feed-me/docs/developers/data-types, so this is going off looking through the code of both the helper plugin and FeedMe itself. Hopefully that will be added at some point.

The way to add your own data/feed type is to call the registerFeedMeDataTypes() function in a plugin, register the datatype:

public function registerFeedMeDataTypes()
{
    return array(
        new MyCustomFeedMeDataType(),
    );
}

You'd import the MyCustomFeedMeDataType class, with Craft::import in the plugin init() function

Then in your datatype class:

<?php
namespace Craft;

class MyCustomFeedMeDataType extends BaseFeedMeDataType
{
   // Custom data type stuff here
}

The datatype should then appear in the feed type dropdown within the FeedMe feeds section in Craft for selection. By default it will use part of the class name for the field label/value, you can also set a specific name, according to this pull request:

https://github.com/verbb/feed-me/pull/172

Quick and reasonably simple in the end, but certainly provides better custom integration options for my project now!

Hope this helps other Craft CMS folk!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.