Configuration form for a custom fetcher and parser

Created on 14 June 2023, over 1 year ago
Updated 15 June 2023, over 1 year ago

I'm writing a custom parser and fetcher for a SharePoint API endpoint with authentication. I've worked out the parser and fetcher, but I'd like to add the custom URL and authentication fields to the Feed Type Configuration. This way, I can query the SharePoint List and get a list of fields available for import. Ideally, add a tab with fields such as "Settings," "Fetcher Settings," etc., etc. or a form such as "Mapping." I've spent hours looking through forms in the module, and I'm at a loss on how to do this.

Thank you,
Sean

πŸ’¬ Support request
Status

Fixed

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States couloir007

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @couloir007
  • Status changed to Fixed over 1 year ago
  • πŸ‡³πŸ‡±Netherlands megachriz

    How to add configuration fields on the feed type for a custom fetcher

    1. In the annotation of your custom fetcher plugin, set a class for form > configuration:
      /**
       * Defines an HTTP fetcher.
       *
       * @FeedsFetcher(
       (...)
       *   form = {
       *     "configuration" = "Drupal\feeds\Feeds\Fetcher\Form\HttpFetcherForm",
       (...)
       */
      
    2. Implement the form class. If your fetcher works in a similar way as an existing fetcher, you could extend an existing fetcher form. Else extend \Drupal\feeds\Plugin\Type\ExternalPluginFormBase.
    3. In your module's config/schema folder add config schema for your fetcher plugin:
      # Fetcher configurations.
      feeds.fetcher.myfetcher:
        type: mapping
        label: 'My fetcher settings'
        mapping:
          foo:
            type: string
      

      From the above example, change fetcher name and mappings accordingly.

    How to add source fields to choose from on the mapping form

    If you want additional predefined sources to appear on the mapping form, implement getMappingSources(). I've written a parser where I used configuration from the fetcher. You could use that technique to get the details you need for connecting to the SharePoint API and then query the SharePoint List.

    $fetcher = $this->feedType->getFetcher();
    $server_id = $fetcher->getConfiguration('server_id');
    $getconnector = $fetcher->getConfiguration('getconnector');
    

    (That code does make the assumption of what fetcher is being used, so that would error if you try to combine it with other fetchers. So for making it foolproof, you may want to add some checks to see if the parser is combined with a compatible fetcher).
    See also the code attached in the zip for more context about the above idea.

    Does this help you further? If not, feel free to reopen this issue.

  • πŸ‡ΊπŸ‡ΈUnited States couloir007

    Thank you. I'll give this a try.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024