function views_atom_rules_action_add_to_feed in Views Atom 7
Same name and namespace in other branches
- 6 views_atom.rules.inc \views_atom_rules_action_add_to_feed()
Rule implementation callback for adding a node to a feed.
Parameters
$data: A wrapped Drupal entity
$views_diplay: A concatenation of views name and display id
1 string reference to 'views_atom_rules_action_add_to_feed'
- views_atom_rules_action_info in ./
views_atom.rules.inc - Implements hook_rules_action_info().
File
- ./
views_atom.rules.inc, line 137
Code
function views_atom_rules_action_add_to_feed($data, $views_display, $settings, RulesState $state, RulesPlugin $element) {
// @todo, ideally this rules_action would go in push_hub or a more generic atom module.
if (module_exists('push_hub')) {
// @todo, revisit this variable name.
// There is inconsistency between plural and singular because it is unclear
// if a rule should only deal with a single display or n displays.
$views_displays = $views_display;
// @todo, question whether Views is necessary at all for the atomization.
// parts of render() inside of views_plugin_row_rdf_node could be abstracted out.
$nid = $data
->getIdentifier();
foreach ($views_displays as $view_name_and_display) {
list($view_name, $view_display_name) = explode('-', $view_name_and_display);
$view = views_get_view($view_name);
$view
->set_display($view_display_name);
if ($view
->access($view_display_name)) {
// Set this version of the node object on the View so it can be accessed by views_plugin_row_rdf_node.inc
// @todo, This is somewhat of a hack and should be replaced by a proper external atom libary.
$node = $data
->value();
$view->views_atom_nodes = array(
$nid => $node,
);
// Get the atom-formatted-data for this node.
$result = $view
->preview($view_display_name, array(
$nid,
));
// Only PuSH the feed if there is actual data. The view may have filtered
// our nids down to 0, in which case we don't want to send anything. Because
// normal View requests (Pull-based) are unaffected, Atom subscriptions still
// work as normal.
if (!empty($view->result)) {
// @todo, make aliasing configurable.
// Note the confusing alias flag. TRUE means "this has already been aliased,
// which is the way to prevent url from trying to find an alia.
$topic_url = url($view
->get_url(), array(
'absolute' => TRUE,
'alias' => TRUE,
));
// @todo, make a send_mode configurable?
push_hub_notify($topic_url, $result, PUSH_HUB_IMMEDIATE | PUSH_HUB_CRON);
}
}
}
}
}