Skip to content

Commit

Permalink
Implements hook_theme
Browse files Browse the repository at this point in the history
  • Loading branch information
reynoldtan committed Mar 18, 2022
1 parent 5dfbe83 commit 1f872cc
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 79 deletions.
3 changes: 3 additions & 0 deletions includes/TripalFields/ncit__raw_data/ncit__raw_data.inc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class ncit__raw_data extends TripalField {
*
*/
public function load($entity) {
$path_module = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'rawpheno');
drupal_add_css($path_module . '/theme/css/abc.css', 'file');

// Arrays to hold phenotypes related to this germplasm.
$germplasm = array();
$icons = array();
Expand Down
92 changes: 14 additions & 78 deletions includes/TripalFields/ncit__raw_data/ncit__raw_data_formatter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,88 +45,24 @@ class ncit__raw_data_formatter extends TripalFieldFormatter {
*/
public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
if ($items[0]['value']) {
// Icons.
$icon_path = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'rawpheno') . '/includes/TripalFields/ncit__raw_data/theme/';
$path_module = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'rawpheno');

$icons = array();
$icons['leaf'] = $icon_path . 'icon-leaf.png';
$icons['export'] = $icon_path . 'icon-export.png';
$icons['raw'] = $icon_path . 'icon-raw.jpg';
$icons['download'] = $icon_path . 'icon-download.jpg';
// Add style and script.

$germplasm_raw_phenotypes = $items[0]['value'];
drupal_add_css($path_module . '/theme/css/rawpheno.germplasmfield.css');
drupal_add_js($path_module . '/theme/js/rawpheno.germplasm.field.js');

// Create markup.
// Refer to this ID for CSS styling.
$id = 'rawphenotypes-germplasm-raw-phenotypes-field';
$markup = '
<div id="' . $id . '">
<div id="rawphenotypes-germplasm-field-header">
<div>
<img src="' . $icons['raw'] . '" align="absmiddle"> &nbsp;&nbsp;<a href="#">What are Raw Phenotypes?</a>
</div>
<div>
<div class="rawphenotypes-germplasm-nav">
<a href="/phenotypes/raw/download">Go To Download Page &#10095;</a>
</div>
</div>
<div>&nbsp;</div>
</div>
<div id="rawphenotypes-define-raw-container" style="display: none;">
Raw Phenotypes are raw data, not computed or averaged values and have not been published. &nbsp;<a href="#">Okay, Got it!</a>
</div>
<div><h1>' . $germplasm_raw_phenotypes['germplasm']['name'] . ': <span>%d Traits / %d Experiments / %d Locations</span></h1></div>
<div id="rawphenotypes-germplasm-warning" class="messages warning">Please note that <i>some experiments</i> appear disabled. Please contact KnowPulse if you need access.</div>
<div id="rawphenotypes-germplasm-table-wrapper">
<div id="rawphenotypes-germplasm-export-table">
<div>%s</div>
</div>
</div>
<div><small>*Data export will launch a new window</small></div>
</div>';
$icon_img = '<img id="rawphenotypes-germplasm-field-trait-select-%s-img" src="%s" border="0" align="absmiddle" alt="Download Raw Phenotypic Data" title="Download Raw Phenotypic Data" />';

$response = '';

if ($germplasm_raw_phenotypes['user']['permission']) {
// Export summary table.
$table_row = array();

$id = 0;
foreach($germplasm_raw_phenotypes['traits'] as $trait => $exp_loc) {
list($trait_id, $trait_name) = explode('_', $trait);

$select = $this->create_select($germplasm_raw_phenotypes['germplasm']['id'], $exp_loc, $germplasm_raw_phenotypes['user']['experiments']);
$table_row[ $id ] = array(sprintf($icon_img, '', $icons['leaf']) . ucfirst($trait_name), $select, sprintf($icon_img, $trait_id, $icons['export']));
$id++;
}

// Create markup.
$summary_table = theme('table', array(
'header' => array('Trait', 'LOCATION/Experiment', sprintf($icon_img, '', $icons['download'])),
'rows' => $table_row,
'sticky' => FALSE,
'attributes' => array('id' => 'rawphenotypes-germplasm-field-table')
));

$response = sprintf($markup,
$germplasm_raw_phenotypes['summary']['traits'],
$germplasm_raw_phenotypes['summary']['experiments'],
$germplasm_raw_phenotypes['summary']['locations'],
$summary_table
);
// Render germplasm raw phenotypes.
$variables = array(
'element_id' => 'rawphenotypes-germplasm-raw-phenotypes-field',
'path_img' => $path_module . '/theme/img/fields/'
);

// Render germplasm raw phenotypes.
$element[0] = array(
'#type' => 'markup',
'#markup' => $response,
);
}
$markup = theme('rawpheno_germplasm_field', $variables);
$element[0] = array(
'#type' => 'markup',
'#markup' => $markup,
);
}

return $element;
Expand Down
9 changes: 8 additions & 1 deletion rawpheno.module
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,13 @@ function rawpheno_theme($existing, $type, $theme, $path) {
),
);

// Raw data field.
$items['rawpheno_germplasm_field'] = array(
'template' => 'rawpheno_germplasm_field',
'path' => $path . '/theme',
'variables' => array('raw_data' => '')
);

return $items;
}

Expand Down Expand Up @@ -1178,4 +1185,4 @@ function rawpheno_preprocess_block(&$vars) {
}

return $vars;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#rawphenotypes-germplasm-field-header {
position: relative;
height: 45px;
border: 10px solid blue;
}

#rawphenotypes-germplasm-field-header div:first-child {
Expand Down
File renamed without changes
47 changes: 47 additions & 0 deletions theme/rawpheno_germplasm_field.tpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* @file
* Master template file of rawpheno germplasm (raw data) field.
*
* * Available variables in $variables array (by array key):
* - element_id - value/id used to in the id attribute of the main container element. All elments
* inside this element can be referenced using this id.
* - $validators: Information about the validators available.
*/
print $variables['raw_data'];
?>

<div id="<?php print $variables['element_id']; ?>">
<div id="rawphenotypes-germplasm-field-header">
<div>
<img src="<?php print $variables['path_img'] . 'icon-raw.jpg'; ?>" align="absmiddle"> &nbsp;&nbsp;<a href="#">What are Raw Phenotypes?</a>
</div>

<div>
<div class="rawphenotypes-germplasm-nav">
<a href="/phenotypes/raw/download">Go To Download Page &#10095;</a>
</div>
</div>
<div>&nbsp;</div>
</div>

<div id="rawphenotypes-define-raw-container" style="display: none;">
Raw Phenotypes are raw data, not computed or averaged values and have not been published. &nbsp;<a href="#">Okay, Got it!</a>
</div>

<div>
<h1>GERMPLASM NAME: <span>5 Traits / 5 Experiments / 5 Locations</span></h1>
</div>

<div id="rawphenotypes-germplasm-warning" class="messages warning">
Please note that <i>some experiments</i> appear disabled. Please contact KnowPulse if you need access.
</div>

<div id="rawphenotypes-germplasm-table-wrapper">
<div id="rawphenotypes-germplasm-export-table">
<div>%s</div>
</div>
</div>

<div><small>*Data export will launch a new window</small></div>
</div>

0 comments on commit 1f872cc

Please sign in to comment.