Skip to content

Instantly share code, notes, and snippets.

@ao5357
Created August 4, 2021 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ao5357/3d514414ed194b82bc656f0b0078d1e1 to your computer and use it in GitHub Desktop.
Save ao5357/3d514414ed194b82bc656f0b0078d1e1 to your computer and use it in GitHub Desktop.
Patch to 8.x-2.x tablefield module to allow cellspan in formatted cells
diff --git a/tablefield_cellspan/tablefield_cellspan.module b/tablefield_cellspan/tablefield_cellspan.module
index 8e343e1..d5b98ec 100644
--- a/tablefield_cellspan/tablefield_cellspan.module
+++ b/tablefield_cellspan/tablefield_cellspan.module
@@ -21,10 +21,6 @@ function tablefield_cellspan_preprocess_table(&$variables) {
foreach ($row['cells'] as $col_key => $cell) {
- if (is_array($cell['content']) || is_object($cell['content'])) {
- break;
- }
-
if (!isset($spancol[$col_key])) {
$spancol[$col_key]['rowspan'] = 2;
$spancol[$col_key]['spancol'] = FALSE;
@@ -36,15 +32,14 @@ function tablefield_cellspan_preprocess_table(&$variables) {
$keys = array_keys($variables['rows'][$row_key]['cells']);
$search = array_search($col_key, $keys);
- $prev = $keys[intval($search) - 1];
-
- $attributes = clone $variables['rows'][$row_key]['cells'][$prev]['attributes'];
- $attributes['colspan'] = $colspan;
+ if (isset($keys[intval($search) - 1])) {
+ $prev = $keys[intval($search) - 1];
- $variables['rows'][$row_key]['cells'][$prev]['attributes'] = $attributes;
- unset($variables['rows'][$row_key]['cells'][$col_key]);
+ $variables['rows'][$row_key]['cells'][$prev]['attributes']['colspan'] = $colspan;
+ unset($variables['rows'][$row_key]['cells'][$col_key]);
- $colspan++;
+ $colspan++;
+ }
}
else {
$colspan = 2;
@@ -64,12 +59,7 @@ function tablefield_cellspan_preprocess_table(&$variables) {
while (TRUE) {
if (isset($variables['rows'][$prev_row]['cells'][$col])) {
-
- $attributes = clone $variables['rows'][$prev_row]['cells'][$col]['attributes'];
- $attributes['rowspan'] = $spancol[$col_key]['rowspan'];
-
- $variables['rows'][$prev_row]['cells'][$col]['attributes'] = $attributes;
-
+ $variables['rows'][$prev_row]['cells'][$col]['attributes']['rowspan'] = $spancol[$col_key]['rowspan'];
$spancol[$col_key]['rowspan']++;
$spancol[$col_key]['spancol'] = $col;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment