Last active
December 16, 2015 00:19
-
-
Save kraigh/5346733 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('JNET_VIEWS_PATH', drupal_get_path('module', 'jnet_views')); | |
include_once JNET_VIEWS_PATH . '/theme/theme.inc'; | |
/** | |
* Implements hook_views_api(). | |
*/ | |
function jnet_views_views_api() { | |
return array( | |
'api' => 2, | |
'path' => JNET_VIEWS_PATH . '/views', | |
); | |
} | |
/** | |
* Implements hook_field_formatter_info(). | |
*/ | |
function jnet_views_field_field_formatter_info() { | |
return array( | |
'jnet_views_image_as_url' => array( | |
'label' => t('My Fancy Label'), | |
'field types' => array('image'), | |
), | |
); | |
} | |
/** | |
* Implements hook_field_formatter_view(). | |
*/ | |
function jnet_views_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { | |
$element = array(); | |
foreach ($items as $delta => $item) { | |
// Do nothing with empty date fields. | |
if (empty($item['value'])) { | |
continue; | |
} | |
$element[$delta] = array( | |
'#markup' => $item->uri, | |
); | |
} | |
return $element; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class subsplash_xml_plugin_style_fields extends views_plugin_style { | |
function option_definition() { | |
$options = parent::option_definition(); | |
return $options; | |
} | |
/** | |
* Provide a form for setting options. | |
*/ | |
function options_form(&$form, &$form_state) { | |
parent::options_form($form, $form_state); | |
// Build a list of fields currently attached to this view display. | |
$field_list = array(); | |
$handlers = $this->display->handler->get_handlers('field'); | |
foreach ($handlers as $handler_id => $handler) { | |
$field_list[$handler_id] = "{$handler->definition['title']} ({$handler->field})"; | |
} | |
// Build a special field list various uses | |
$utility_field_list = array_merge(array('none' => 'None'), $field_list); | |
$xml_template_options = array( | |
'subtabs' => 'Sub Tabs View', | |
'table_view' => 'Table View', | |
'detail_view' => 'Standard Detail View', | |
'media_detail' => 'Media Detail View', | |
); | |
$form['xml_title'] = array( | |
'#type' => 'textfield', | |
'#title' => t("XML Title"), | |
'#description' => t('The title of the XML feed.'), | |
'#default_value' => $this->options['xml_title'], | |
); | |
$form['xml_title_field'] = array( | |
'#type' => 'select', | |
'#title' => 'Title Field', | |
'#description' => 'If you would like to use a field for the above title, please select one.', | |
'#options' => $utility_field_list, | |
'#default_value' => $this->options['xml_title_field'], | |
); | |
$form['xml_template'] = array( | |
'#type' => 'select', | |
'#title' => t("XML Template"), | |
'#description' => t('Select a tempalte to use for the XML feed.'), | |
'#options' => $xml_template_options, | |
'#default_value' => $this->options['xml_template'], | |
); | |
// Add an image to be used in "banner" field | |
$form['media_detail_image_field'] = array( | |
'#type' => 'select', | |
'#title' => 'Banner Image Field', | |
'#description' => 'Optionally, select the image to be used in the "banner" for this view.', | |
'#options' => $utility_field_list, | |
'#default_value' => $this->options['media_detail_image_field'], | |
); | |
// Show all fields with options to set the 'wrapper' for each. | |
$form['field_wrappers'] = array( | |
'#type' => 'fieldset', | |
'#title' => 'Field XML Wrappers', | |
'#tree' => TRUE, | |
'#description' => 'The field will be wrapped in an xml element. Please provide the element, minus < or >.', | |
); | |
foreach ($field_list as $field_machine => $field_human) { | |
$form['field_wrappers'][$field_machine] = array( | |
'#type' => 'textfield', | |
'#title' => $field_human, | |
'#default_value' => $this->options['field_wrappers'][$field_machine], | |
); | |
} | |
} | |
/** | |
* Allow other modules to validate options form values prior to submit. | |
*/ | |
function options_validate(&$form, &$form_state) { | |
} | |
/** | |
* Allow other modules to perform any necessary changes | |
* to options form values prior to storage. | |
*/ | |
function options_submit(&$form, &$form_state) { | |
} | |
/** | |
* Make sure the display and all associated handlers are valid. | |
*/ | |
function validate() { | |
parent::validate(); | |
$errors = array(); | |
// .. do stuff here | |
return $errors; | |
} | |
function pre_render($result) { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function template_preprocess_views_view_subsplash_xml(&$vars) { | |
$vars['subsplash_content'] = array(); | |
switch ($vars['view']->style_options['xml_template']) { | |
case 'subtabs': | |
break; | |
case 'table_view': | |
$view_style = 'Table View'; | |
$vars['subsplash_content'] = array( | |
'#prefix' => '<table>', | |
'#suffix' => '</table>', | |
'#markup' => '', | |
); | |
foreach ($vars['view']->style_plugin->rendered_fields as $row) { | |
$vars['subsplash_content']['#markup'] .= "<row>"; | |
// We only care about fields that have a wrapper defined for them. | |
foreach ($vars['view']->style_options['field_wrappers'] as $field => $wrapper) { | |
if (!empty($wrapper)) { | |
$vars['subsplash_content']['#markup'] .= "<{$wrapper}>{$row[$field]}</{$wrapper}>"; | |
} | |
} | |
$vars['subsplash_content']['#markup'] .= "</row>"; | |
} | |
break; | |
case 'media_detail': | |
break; | |
case 'detail_view': | |
$view_style = 'Detail View'; | |
$vars['subsplash_content'] = array( | |
'#prefix' => '<table>', | |
'#suffix' => '</table>', | |
'#markup' => '', | |
); | |
break; | |
default: | |
$view_style = 'ERROR: No View Style'; | |
break; | |
} | |
if (isset($vars['view']->style_options['xml_title_field']) && $vars['view']->style_options['xml_title_field'] !== 'none') { | |
// $vars['rows'][0]->_field_data['nid']['entity']->{$vars['view']->style_options['xml_title_field']}['und'][0]['#value']; | |
} else { | |
$vars['subsplash_title'] = $vars['view']->style_options['xml_title']; | |
} | |
if (isset($vars['view']->style_options['media_detail_image_field']) && $vars['view']->style_options['media_detail_image_field'] !== 'none') { | |
$vars['subsplash_header'] = array( | |
'#prefix' => '<banner>', | |
'#suffix' => '</banner>', | |
'#markup' => '', | |
); | |
// Set the image. | |
if(isset($vars['rows'][0]->_field_data['nid']['entity']->{$vars['view']->style_options['media_detail_image_field']}['und'][0]['uri'])) { | |
$uri = $vars['rows'][0]->_field_data['nid']['entity']->{$vars['view']->style_options['media_detail_image_field']}['und'][0]['uri']; | |
} | |
$image_url = image_style_url('churchapp_featured', $uri); | |
$image_double_url = image_style_url('churchapp_featured_dbl', $uri); | |
$vars['subsplash_header']['#markup'] = "<image>{$image_url}</image><double:image>{$image_double_url}</double:image>"; | |
} | |
// Set XML header. | |
drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8'); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment