Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tablefield-3199886
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
tablefield-3199886
Commits
576bd359
Commit
576bd359
authored
15 years ago
by
Kevin Hankens
Browse files
Options
Downloads
Patches
Plain Diff
Fixed default handling bugs and empty fields in display
parent
74014dfc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tablefield.module
+32
-35
32 additions, 35 deletions
tablefield.module
with
32 additions
and
35 deletions
tablefield.module
+
32
−
35
View file @
576bd359
...
...
@@ -4,7 +4,7 @@
/**
* @file
* This module provides a set of fields that can be used to store
* tabular data with a node
* tabular data with a node
. The implementation uses a custom CCK widget.
*/
/**
...
...
@@ -91,11 +91,6 @@ function tablefield_field($op, &$node, $field, &$items, $teaser, $page) {
switch
(
$op
)
{
case
'presave'
:
foreach
(
$items
as
$delta
=>
$table
)
{
// Get rid of configuration data sent in form_state
//unset($table['tablefield']['count_rows']);
//unset($table['tablefield']['count_cols']);
//unset($table['tablefield']['rebuild']);
$tablefield
=
array
();
foreach
(
$table
[
'tablefield'
]
as
$key
=>
$value
)
{
$tablefield
[
$key
]
=
$value
;
...
...
@@ -111,31 +106,35 @@ function tablefield_field($op, &$node, $field, &$items, $teaser, $page) {
case
'sanitize'
:
// We need to make the table data available to display
foreach
(
$items
as
$delta
=>
$table
)
{
if
(
isset
(
$table
[
'tablefield'
]))
{
if
(
!
empty
(
$table
[
'tablefield'
]))
{
$tabledata
=
tablefield_rationalize_table
(
$table
[
'tablefield'
]);
}
elseif
(
isset
(
$table
[
'value'
]))
{
elseif
(
!
empty
(
$table
[
'value'
]))
{
$tabledata
=
tablefield_rationalize_table
(
unserialize
(
$table
[
'value'
]));
}
// Pull the header for theming
$header
=
$tabledata
[
0
];
unset
(
$tabledata
[
0
]);
// Run it through input filters
if
(
!
empty
(
$tabledata
))
{
foreach
(
$tabledata
as
$row_key
=>
$row
)
{
foreach
(
$row
as
$col_key
=>
$cell
)
{
if
(
!
empty
(
$field
[
'cell_processing'
]))
{
$tabledata
[
$row_key
][
$col_key
]
=
check_markup
(
$cell
,
$table
[
'format'
]);
}
else
{
$tabledata
[
$row_key
][
$col_key
]
=
check_plain
(
$cell
);
// Multivalue fields will have one row in the db, so make sure that it isn't empty
if
(
isset
(
$tabledata
))
{
// Pull the header for theming
$header
=
$tabledata
[
0
];
unset
(
$tabledata
[
0
]);
// Run it through input filters
if
(
!
empty
(
$tabledata
))
{
foreach
(
$tabledata
as
$row_key
=>
$row
)
{
foreach
(
$row
as
$col_key
=>
$cell
)
{
if
(
!
empty
(
$field
[
'cell_processing'
]))
{
$tabledata
[
$row_key
][
$col_key
]
=
check_markup
(
$cell
,
$table
[
'format'
]);
}
else
{
$tabledata
[
$row_key
][
$col_key
]
=
check_plain
(
$cell
);
}
}
}
}
}
$items
[
$delta
][
'value'
]
=
theme
(
'tablefield_view'
,
$header
,
$tabledata
,
$node
->
nid
,
$delta
);
$items
[
$delta
][
'value'
]
=
theme
(
'tablefield_view'
,
$header
,
$tabledata
,
$node
->
nid
,
$delta
);
}
}
break
;
...
...
@@ -146,15 +145,10 @@ function tablefield_field($op, &$node, $field, &$items, $teaser, $page) {
* Implementation of hook_content_is_empty().
*/
function
tablefield_content_is_empty
(
$item
,
$field
)
{
// First see if the submitted field matches the default
unset
(
$item
[
'tablefield'
][
'rebuild'
]);
if
(
$item
[
'tablefield'
]
==
$field
[
'widget'
][
'default_value'
][
0
][
'tablefield'
])
{
return
TRUE
;
}
// Remove the preference fields to see if the table cells are all empty
unset
(
$item
[
'tablefield'
][
'count_cols'
]);
unset
(
$item
[
'tablefield'
][
'count_rows'
]);
unset
(
$item
[
'tablefield'
][
'rebuild'
]);
if
(
!
empty
(
$item
[
'tablefield'
]))
{
foreach
(
$item
[
'tablefield'
]
as
$cell
)
{
...
...
@@ -289,7 +283,8 @@ function tablefield_process($element, $edit, $form_state, $form) {
}
else
{
// Get the widget default value
$default_value
=
tablefield_rationalize_table
(
$field
[
'widget'
][
'default_value'
][
0
][
'tablefield'
]);
$default_count_cols
=
$field
[
'widget'
][
'default_value'
][
0
][
'tablefield'
][
'count_cols'
];
$default_count_rows
=
$field
[
'widget'
][
'default_value'
][
0
][
'tablefield'
][
'count_rows'
];
}
$element
[
'tablefield'
]
=
array
(
...
...
@@ -321,8 +316,8 @@ function tablefield_process($element, $edit, $form_state, $form) {
}
}
else
{
$count_cols
=
5
;
$count_rows
=
5
;
$count_cols
=
$default_count_cols
;
$count_rows
=
$default_count_rows
;
}
// Override the number of rows/columns if the user rebuilds the form
...
...
@@ -360,7 +355,7 @@ function tablefield_process($element, $edit, $form_state, $form) {
}
$element
[
'tablefield'
][
'break'
.
$i
]
=
array
(
'#type'
=>
'markup'
,
'#value'
=>
'</table'
,
'#value'
=>
'</table
>
'
,
);
// Allow the user to add more rows/columns
...
...
@@ -370,7 +365,8 @@ function tablefield_process($element, $edit, $form_state, $form) {
'#size'
=>
5
,
'#prefix'
=>
'<div class="clear-block">'
,
'#suffix'
=>
'</div>'
,
'#default_value'
=>
$count_cols
,
//'#default_value' => $count_cols,
'#value'
=>
$count_cols
,
);
$element
[
'tablefield'
][
'count_rows'
]
=
array
(
'#title'
=>
t
(
'How many Rows'
),
...
...
@@ -378,7 +374,8 @@ function tablefield_process($element, $edit, $form_state, $form) {
'#size'
=>
5
,
'#prefix'
=>
'<div class="clear-block">'
,
'#suffix'
=>
'</div>'
,
'#default_value'
=>
$count_rows
,
//'#default_value' => $count_rows,
'#value'
=>
$count_rows
,
);
$element
[
'tablefield'
][
'rebuild'
]
=
array
(
'#type'
=>
'button'
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment