Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #3: Tablefields should not print empty tables when there is no …
…data.
- Loading branch information
Jen Lampton
committed
Feb 8, 2018
1 parent
64a41a6
commit 50c70f3
Showing
2 changed files
with
74 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* @file | ||
* Theme fuunctions for table field. | ||
*/ | ||
|
||
/** | ||
* Theme function for table view. | ||
*/ | ||
function theme_tablefield_view($variables) { | ||
// Apply scope property to headers for accessibility. | ||
if (is_array($variables['header'])) { | ||
foreach ($variables['header'] as &$header) { | ||
$header['scope'] = 'col'; | ||
} | ||
} | ||
|
||
// If the user has access to the csv export option, display it now. | ||
$export = ''; | ||
if ($variables['export'] && user_access('export tablefield')) { | ||
$url = sprintf('tablefield/export/%s/%s/%s/%s/%s', $variables['entity_type'], $variables['entity_id'], $variables['field_name'], $variables['langcode'], $variables['delta']); | ||
$export = '<div id="tablefield-export-link-' . $variables['delta'] . '" class="tablefield-export-link">' . l(t('Export Table Data'), $url) . '</div>'; | ||
} | ||
|
||
$table = array( | ||
'header' => $variables['header'], | ||
'rows' => $variables['rows'], | ||
'attributes' => $variables['attributes'], | ||
); | ||
if(isset($variables['caption']) && !empty($variables['caption'])) { | ||
$table['caption'] = $variables['caption']; | ||
} | ||
|
||
$output = '<div id="tablefield-wrapper-' . $variables['delta'] . '" class="tablefield-wrapper">'; | ||
$output .= theme('table__tablefield', $table); | ||
$output .= $export; | ||
$output .= '</div>'; | ||
|
||
return $output; | ||
} |