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
dc7ab15b
Commit
dc7ab15b
authored
15 years ago
by
Kevin Hankens
Browse files
Options
Downloads
Patches
Plain Diff
added handling for input formats, fixed a bug with table names, added help text to settings page
parent
98e5db06
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
+47
-22
47 additions, 22 deletions
tablefield.module
with
47 additions
and
22 deletions
tablefield.module
+
47
−
22
View file @
dc7ab15b
...
...
@@ -45,40 +45,42 @@ function tablefield_field_info() {
/**
* Implementation of hook_field_settings().
*
* @todo build a case for 'views data'
*/
function
tablefield_field_settings
(
$op
,
$field
)
{
switch
(
$op
)
{
case
'form'
:
$form
=
array
();
$form
[
'count_cols'
]
=
array
(
'#type'
=>
'textfield'
,
'#title'
=>
t
(
'Default number of columns. This can be overridden in each node.'
),
'#element_validate'
=>
array
(
'_element_validate_number'
),
'#default_value'
=>
$field
[
'count_cols'
],
$options
=
array
(
0
=>
t
(
'Plain text'
),
1
=>
t
(
'Filtered text (user selects input format)'
));
$form
[
'cell_processing'
]
=
array
(
'#type'
=>
'radios'
,
'#title'
=>
t
(
'Table cell processing'
),
'#default_value'
=>
is_numeric
(
$field
[
'cell_processing'
])
?
$field
[
'cell_processing'
]
:
0
,
'#options'
=>
$options
,
);
$form
[
'count_rows'
]
=
array
(
'#type'
=>
'textfield'
,
'#title'
=>
t
(
'Default number of rows. This can be overridden in each node.'
),
'#element_validate'
=>
array
(
'_element_validate_number'
),
'#default_value'
=>
$field
[
'count_rows'
],
$form
[
'default_message'
]
=
array
(
'#type'
=>
'markup'
,
'#value'
=>
t
(
'To specify a default table, use the "Default Value" above. There you can specify a default number of rows/columns and values.'
),
);
break
;
return
$form
;
case
'save'
:
$values
=
array
(
'count_cols'
,
'count_rows'
);
$values
=
array
(
'cell_processing'
,
'count_cols'
,
'count_rows'
);
return
$values
;
break
;
case
'database columns'
:
return
array
(
'value'
=>
array
(
'type'
=>
'text'
,
'default'
=>
''
),
);
break
;
$columns
=
array
();
// Input format
if
(
!
empty
(
$field
[
'cell_processing'
]))
{
$columns
[
'format'
]
=
array
(
'type'
=>
'int'
,
'unsigned'
=>
TRUE
,
'not null'
=>
FALSE
,
'views'
=>
FALSE
);
}
$columns
[
'value'
]
=
array
(
'type'
=>
'text'
,
'default'
=>
''
);
return
$columns
;
case
'views data'
:
$data
=
content_views_field_views_data
(
$field
);
return
$data
;
break
;
}
}
...
...
@@ -118,6 +120,21 @@ function tablefield_field($op, &$node, $field, &$items, $teaser, $page) {
// 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
);
}
...
...
@@ -260,6 +277,7 @@ function tablefield_widget(&$form, &$form_state, $field, $items, $delta = 0) {
*/
function
tablefield_process
(
$element
,
$edit
,
$form_state
,
$form
)
{
$delta
=
$element
[
'#delta'
];
$field
=
$form
[
'#field_info'
][
$element
[
'#field_name'
]];
if
(
isset
(
$element
[
'#value'
][
'tablefield'
]))
{
// A form was submitted
...
...
@@ -271,11 +289,11 @@ function tablefield_process($element, $edit, $form_state, $form) {
}
else
{
// Get the widget default value
$default_value
=
tablefield_rationalize_table
(
$f
orm
[
'#field_info'
][
$element
[
'#field_name'
]]
[
'widget'
][
'default_value'
][
0
][
'tablefield'
]);
$default_value
=
tablefield_rationalize_table
(
$f
ield
[
'widget'
][
'default_value'
][
0
][
'tablefield'
]);
}
$element
[
'tablefield'
]
=
array
(
'#title'
=>
t
(
'Data Table'
)
,
'#title'
=>
$field
[
'widget'
][
'label'
]
,
'#description'
=>
t
(
'The first row will appear as the table header.'
),
'#attributes'
=>
array
(
'id'
=>
'node-tablefield-'
.
$delta
,
'class'
=>
'node-tablefield'
),
'#type'
=>
'fieldset'
,
...
...
@@ -368,6 +386,13 @@ function tablefield_process($element, $edit, $form_state, $form) {
'#attributes'
=>
array
(
'class'
=>
'tablefield-rebuild'
),
);
if
(
!
empty
(
$field
[
'cell_processing'
]))
{
$filter_key
=
$element
[
'#columns'
][
0
];
$format
=
isset
(
$element
[
'#value'
][
$filter_key
])
?
$element
[
'#value'
][
$filter_key
]
:
FILTER_FORMAT_DEFAULT
;
$parents
=
array_merge
(
$element
[
'#parents'
]
,
array
(
$filter_key
));
$element
[
$filter_key
]
=
filter_form
(
$format
,
1
,
$parents
);
}
return
$element
;
}
...
...
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