Universal Content Puller

Developing Content Sources

The content sources provided by Universal Content Puller are pluggable and expandable. Universal Content Puller will automatically detect new content sources as they are added to a site.

If you are considering developing further content sources, I strongly recommend you install the Universal Content Puller developer addon as this provides provides tools to expose data structures, learn how Universal Content Puller works, and assist with development.

Further content sources can easily be added as root level models or in packages. Each source should be a model within the root level or package folder /models/universal_content_puller/content_sources/. The name of the file should map to the name of the model class, as per the usual concrete5 naming conventions.

A content source should inherit from the class UniversalContentPullerContentPluginBase, loaded from:

Loader::library('universal_content_puller/content_plugin_base', 'jl_universal_content_puller');

Each source must define methods for basic identification and help

public function getName(){
  // return the name of the content source plugin
}

public function getDescription(){
  // return a description of what the content source plugin does
}

public function getHelp(){
  // return more detailed help for users of the content source plugin
}

Only two further methods are mandatory:

public function edit($block, $data){
  // return a form fragment to be used in the edit interface to enter source specific data.
}

public function view($block, $data){
  // return an html fragment for the display of the content source.
}

For both of these methods:

$block is the block object for the specific Universal Content Puller block.

$data is an array of source specific parameters. These need to coexist with other plugins on the same edit dialog, so they must have a prefix of their handle that gives them a unique name-space. For example, for the Stack source, all source specific data should begin 'cs_stack_'.

If a source has specific header requirements, it may provide the method

public function on_page_view($block, $data){
  // call addHeaderItem() and addFooterItem() for scripts and css.
}

Some sources may provide one further optional public method to extract source specific data from a saved add/edit form and to validate that data. In general, if the content source parameter naming convention has been followed, this method can be inherited and parameter extraction will be automatic.

public function extract_data($block, $all_data){
  // return an array of source specific parameters extracted from $all_data.
}

$all_data is all the form parameters from saving the add/edit form. Where validation is needed and fails, returning a simple string will display it as an error message.

Last updated: over a year ago