[ create a new paste ] login | about

Link: http://codepad.org/Q5fWvM28    [ raw code | fork ]

randomblink - PHP, pasted on May 30:
<?php
/**
 * @} End of "defgroup field".
 */

/**
 * Returns HTML for a field.
 *
 * This is the default theme implementation to display the value of a field.
 * Theme developers who are comfortable with overriding theme functions may do
 * so in order to customize this markup. This function can be overridden with
 * varying levels of specificity. For example, for a field named 'body'
 * displayed on the 'article' content type, any of the following functions will
 * override this default implementation. The first of these functions that
 * exists is used:
 * - THEMENAME_field__body__article()
 * - THEMENAME_field__article()
 * - THEMENAME_field__body()
 * - THEMENAME_field()
 *
 * Theme developers who prefer to customize templates instead of overriding
 * functions may copy the "field.tpl.php" from the "modules/field/theme" folder
 * of the Drupal installation to somewhere within the theme's folder and
 * customize it, just like customizing other Drupal templates such as
 * page.tpl.php or node.tpl.php. However, it takes longer for the server to
 * process templates than to call a function, so for websites with many fields
 * displayed on a page, this can result in a noticeable slowdown of the website.
 * For these websites, developers are discouraged from placing a field.tpl.php
 * file into the theme's folder, but may customize templates for specific
 * fields. For example, for a field named 'body' displayed on the 'article'
 * content type, any of the following templates will override this default
 * implementation. The first of these templates that exists is used:
 * - field--body--article.tpl.php
 * - field--article.tpl.php
 * - field--body.tpl.php
 * - field.tpl.php
 * So, if the body field on the article content type needs customization, a
 * field--body--article.tpl.php file can be added within the theme's folder.
 * Because it's a template, it will result in slightly more time needed to
 * display that field, but it will not impact other fields, and therefore,
 * is unlikely to cause a noticeable change in website performance. A very rough
 * guideline is that if a page is being displayed with more than 100 fields and
 * they are all themed with a template instead of a function, it can add up to
 * 5% to the time it takes to display that page. This is a guideline only and
 * the exact performance impact depends on the server configuration and the
 * details of the website.
 *
 * @param $variables
 *   An associative array containing:
 *   - label_hidden: A boolean indicating to show or hide the field label.
 *   - title_attributes: A string containing the attributes for the title.
 *   - label: The label for the field.
 *   - content_attributes: A string containing the attributes for the content's
 *     div.
 *   - items: An array of field items.
 *   - item_attributes: An array of attributes for each item.
 *   - classes: A string containing the classes for the wrapping div.
 *   - attributes: A string containing the attributes for the wrapping div.
 *
 * @see template_preprocess_field()
 * @see template_process_field()
 * @see field.tpl.php
 *
 * @ingroup themeable
 */
function blinks_responsive_preprocess_field_netrunner_card(&$variables)
{
	// Use DVM for the DEVEL module to output variables better.
	// http://ratatosk.net/drupal/tutorials/debugging-drupal.html
	
	$variables['TheTest'] = '<pre>Poop!</pre>';

	$output = '';
	$subImg = '';
	$addEnc = '';
	// We set $blinksFieldName to equal the name of the field being processed
	$blinksFieldName = $variables['element']['#field_name'];

	switch( $blinksFieldName )
	{
		case 'field_card_subtype':
			if( $variables['element'][0]['#title'] == 'Icebreaker' )
			{
				$variables['content']['isIcebreaker'] = True;
				//dvm( $variables, 'variables' );	
			}			
			break;
		case 'field_unique_card':
			$variables['card_is_unique'] = $variables['element']['#items'][0]['value'];
			break;
		case 'field_faction_affiliation':
			$base_path = base_path();
			$faction_icon_href = $base_path . $variables['element'][0]['#href'];
			$faction_icon_title = $variables['element'][0]['#title'];
			$faction_icon_url = file_create_url($variables['element']['#object']->field_faction_affiliation['und'][0]['taxonomy_term']->field_faction_icon['und'][0]['uri']);
			$output = "<a href='$faction_icon_href'><img alt='$faction_icon_title' class='faction-thumb' src='$faction_icon_url' /></a>";
			return $output;
			break;
		case 'field_subroutines':
			$subImg .= '<div class="field-subroutine">';
			$subImg .= '<img id="subroutineImage" src="http://netrunner.randomblink.com/sites/default/files/styles/large/public/Subroutine.png" />';
			$subImg .= '</div>';
			$subImg .= '<p class="subroutine-text">';
			break;
		case 'field_card':
			// We need to create a class for each View Mode type
			$variables['classes'].=' blinks-'.$variables['element']['#view_mode'].'-card';
			break;
		case 'field_minimum_deck_size':
			$addEnc = 'p';
			break;
		case 'field_influence_limit':
			$addEnc = 'p';
			break;
		default:
			// what to do if the field isn't in the list.
	}
	
	// Render the label, if it's not hidden.
	if (!$variables['label_hidden']) 
	{
		$output .= '<div class="field-label"' . $variables['title_attributes'] . '>' . $variables['label'] . ':&nbsp;</div>';
	}

	$subTypeSpacer = '';
	// Render the items.
	$output .= '<div class="field-items"' . $variables['content_attributes'] . '>';
	
	foreach ($variables['items'] as $delta => $item) 
	{
		switch( $blinksFieldName )
		{
			case 'field_card_subtype':
				if( $delta > 0 ){ $subTypeSpacer = ' - '; }
				break;
			case 'field_subroutines':
				// We need to modify the Subroutine output to show the subroutine symbol.
				// We need to add in the subroutine image now.
				$item = str_replace("<p>", $subImg, $item);
				break;
			default:
		}
		
		$classes = 'field-item ' . ($delta % 2 ? 'odd' : 'even');
		$output .= '<div class="' . $classes . '"' . $variables['item_attributes'][$delta] . '>';
		$output .= $subTypeSpacer;
		$output .= ( $addEnc == '' )? '': '<' . $addEnc . '>';
		$output .= drupal_render($item);
		$output .= ( $addEnc == '' )? '': '</' . $addEnc . '>';
		$output .= '</div>';
	}
	$output .= '</div>';

	// Render the top-level DIV.
	$output = '<div class="' . $variables['classes'] . '"' . $variables['attributes'] . '>' . $output . '</div>';

	return $output;
}
?>


Create a new paste based on this one


Comments: