Skip to content

Instantly share code, notes, and snippets.

@e2thex
Created June 28, 2012 13:08
Show Gist options
  • Select an option

  • Save e2thex/3011273 to your computer and use it in GitHub Desktop.

Select an option

Save e2thex/3011273 to your computer and use it in GitHub Desktop.
Prposal for plugin hooks for sps module
A-----------------. I-----------------.
| Widget |-------------->| WidgetInterface |
'-----------------' '-----------------'
|
.-------'---------------.
v v
.------------------------. .-----------------.
| SelectWidgetCollection | | GenericWidget |
'------------------------' '-----------------'
A-----------------. I-------------------.
| Override |-------------->| OverrideInterface |
'-----------------' '-------------------'
|
.---------'--------------.
v v
.------------------. .--------------------------.
| GenericOverride | | EntityCollectionOverride |
'------------------' '--------------------------'
A-----------------. I--------------------.
| Condition |-------------->| ConditionInterface |
'-----------------' '--------------------'
|
.-------'-----------------.
v v
.------------------. A--------------------------.
| GenericCondition | | WrapperCondition |
'------------------' '--------------------------'
|
v
.--------------------------.
| SingleWrapperCondition |
'--------------------------'
A-----------------. I-------------------.
| Reaction |-------------->| ReactionInterface |
'-----------------' '-------------------'
|
.-----'-------------------------.
v v
.------------------------. .----------------------.
| EntityQueryReaction | | PageLoadNoadReaction |
'------------------------' '----------------------'
array(
'active_conditions' => array(
array(
'Title' => 'Publish Date',
'condition' => 'publish_date',
'widget_settings' => array(
'widget' => 'textfield_timestamp',
),
),
array(
'Title' => 'Release Collection',
'condition' => 'collection',
'widget_settings' => array(
'widget' => 'collection_select',
),
)
),
'form_base_condition' => array(
'condition' => 'single_condition_wrapper',
'widget_settings' => array()
),
'active_reactions' => array(
'entity_query_alter',
'page_load_node',
);
)
<?php
/*******************PLUGIN HOOKS***********************************/
/*
* implements hook_sps_plugin_type_info()
*/
function sps_sps_plugin_type_info() {
return array(
'widget' => array(
'interface' =>'\Drupal\sps\Plugin\WidgetInterface',
'defaults' => array(
'class' =>'\Drupal\sps\Plugin\Widget\GenericWidget'
'instance_settings' => array(),
'require_settings' => array('data_api'),
),
'override' => array(
'interface' =>'\Drupal\sps\Plugin\OverrideInterface',
'defaults' => array(
'class' =>'\Drupal\sps\Plugin\Override\GenericOverride'
'instance_settings' => array(),
),
'require' => array('condition', 'type', 'data_api'),
),
'condition' => array(
'interface' =>'\Drupal\sps\Plugin\ConditionInterface',
'default' => array(
'class' =>'\Drupal\sps\Plugin\Condition\GenericCondition'
'instance_settings' => array(),
),
),
'reaction' => array(
'interface' =>'\Drupal\sps\Plugin\ReactionInterface',
'defaults' => array(
'instance_settings' => array(),
),
'require' => array('class')
),
)
}
/**
* implements hook_sps_widget_plugin_info()
*/
function sps_sps_widget_plugin_info() {
return array(
'textfield_timestamp' => array(
'instance_settings' => array(
'validate_element_callback' => 'sps_timestamp_widget_validate',
'form_element_callback' => 'sps_timestamp_widget_form',
'extract_data_callback' => 'sps_timestamp_widget_extract_data',
'include_file' => drupal_get_path('module'. 'sps') . 'sps_timestamp_widget.inc',
),
'data_api' => 'timestamp'
),
'collection_select' => array(
'class' => '\Drupal\sps\plugins\Collection\SelectWidgetCollection',
'data_api' => 'collection_name'
),
)
}
/**
* implements hook_sps_override_plugin_info()
*/
function sps_sps_override_plugin_info() {
return array(
'node_publish_date' => array(
'instance_settings' => array(
'get_overrides_callback' => 'sps_override_node_publish_date',
'include_file' => drupal_get_path('module'. 'sps') . 'sps_overrode_node_publish_date.inc',
),
'condition' => 'publish_date'
'data_api' => 'timestamp'
'type'=> 'node',
),
'node_collection' => array(
'class' => '\Drupal\sps\plugins\Override\EntityCollectionOverride',
'instance_settings' => array('type' => 'node'),
'condition' => 'collection',
'data_api' => 'collection_name'
'type'=> 'node'
),
)
}
/**
* implements hook_sps_condition_plugin_info()
*/
function sps_sps_condition_plugin_info() {
return array(
'publish_date' => array(
'instance_settings' => array(
'data_api' => 'time_stamp',
'name' => 'publish_date',
),
),
'collection' => array(
'instance_settings' => array(
'data_api' => 'collection_name',
'name' => 'collection',
),
),
'single_condition_wrapper' => array(
'class' => '\Drupal\sps\plugins\condition\SingleWrapperCondition'
),
)
}
/**
* implements hook_sps_reaction_plugin_info()
*/
function sps_sps_reaction_plugin_info() {
return array(
'entity_query_alter' => array(
'class' => '\Drupal\sps\plugins\reaction\EntityQueryAlterReaction',
),
'page_load_node' => array(
'class' => '\Drupal\sps\plugins\reaction\PageLoadNoadReaction',
),
),
);
}
/*********************PLUGIN FUNCTIONS*******************************/
/**
* retrieve info for a plugin or for all of a plugin type
*
*/
function get_plugin_info($type, $name=NULL) {
$plugin_infos = get_plugin_infos();
if($name) {
return $plugin_infos[$type][$name];
}
return $plugin_infos[$type]
}
/**
* return instance of a plugin
*/
function get_plugin($type, $name) {
$info = $get_plugin_info($type, $name);
$manager = sps_get_manager()
return new {$info['class']}($info['instance_settings'], $manager);
}
/**
* return cache version of plugin data or
* create the cache version and return
*
* in creating add defaults to types, and validate that the plugins
* have required fields as well as that the class implements the correct interface
*/
function get_plugin_infos() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment