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
aa5c05b2
Commit
aa5c05b2
authored
14 years ago
by
Kevin Hankens
Browse files
Options
Downloads
Patches
Plain Diff
#1051568
by bojanz css improvements and locked cells; bug in default settings form
parent
911aba7d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tablefield.css
+3
-11
3 additions, 11 deletions
tablefield.css
tablefield.module
+77
-50
77 additions, 50 deletions
tablefield.module
with
80 additions
and
61 deletions
tablefield.css
+
3
−
11
View file @
aa5c05b2
...
...
@@ -6,12 +6,6 @@
margin
:
1px
1px
1px
1px
;
padding
:
1px
1px
1px
1px
;
}
.field-widget-tablefield
.form-tablefield
.form-item
,
.form-tablefield
.form-item
{
float
:
left
;
margin
:
0
0
0
0
;
padding
:
0
0
0
0
;
}
.field-widget-tablefield
.form-tablefield
table
,
.form-tablefield
table
{
width
:
100%
;
...
...
@@ -23,15 +17,13 @@
.form-tablefield
table
tr
td
{
margin
:
0
0
0
0
;
padding
:
0
0
0
0
;
}
.form-tablefield
table
tr
.tablefield-row-0
{
border-bottom
:
2px
solid
#555
;
text-align
:
center
;
}
.form-tablefield
input
.tablefield-row-0
{
font-weight
:
bold
;
}
.form-tablefield
tr
.tablefield-even
input
{
background-color
:
#e4f4f4
;
.form-tablefield
input
{
background-color
:
transparent
!important
;
}
.form-tablefield
table
,
.form-tablefield
fieldset
{
...
...
This diff is collapsed.
Click to expand it.
tablefield.module
+
77
−
50
View file @
aa5c05b2
...
...
@@ -31,12 +31,17 @@ function tablefield_field_info() {
*/
function
tablefield_field_settings_form
(
$field
,
$instance
,
$has_data
)
{
$form
=
array
();
$form
[
'lock_values'
]
=
array
(
'#type'
=>
'checkbox'
,
'#title'
=>
'Lock table field defaults from further edits during node add/edit.'
,
'#default_value'
=>
isset
(
$field
[
'settings'
][
'lock_values'
])
?
$field
[
'settings'
][
'lock_values'
]
:
FALSE
,
);
$form
[
'cell_processing'
]
=
array
(
'#type'
=>
'radios'
,
'#title'
=>
t
(
'Table cell processing'
),
'#default_value'
=>
isset
(
$field
[
'settings'
][
'cell_processing'
])
?
$field
[
'settings'
][
'cell_processing'
]
:
0
,
'#options'
=>
array
(
t
(
'Plain text'
),
t
(
'Plain text'
),
t
(
'Filtered text (user selects input format)'
)
),
);
...
...
@@ -103,7 +108,7 @@ function tablefield_field_validate($entity_type, $entity, $field, $instance, $la
/**
* Implements hook_field_widget_error().
*/
*/
function
tablefield_field_widget_error
(
$element
,
$error
,
$form
,
&
$form_state
)
{
form_error
(
$element
[
'tablefield'
],
$error
[
0
][
'message'
]);
}
...
...
@@ -152,10 +157,10 @@ function tablefield_field_is_empty($item, $field) {
function
tablefield_field_formatter_info
()
{
return
array
(
'default'
=>
array
(
'label'
=>
t
(
'Tabular View'
),
'label'
=>
t
(
'Tabular View'
),
'field types'
=>
array
(
'tablefield'
),
),
);
);
}
/**
...
...
@@ -286,10 +291,10 @@ function tablefield_field_widget_form(&$form, &$form_state, $field, $instance, $
foreach
(
$default_value
as
$row
)
{
$temp_count
=
count
(
$row
);
if
(
$temp_count
>
$count_cols
)
{
$count_cols
=
$temp_count
;
$count_cols
=
$temp_count
;
}
}
}
}
}
else
{
$count_rows
=
count
(
$default_value
);
$count_cols
=
isset
(
$default_count_cols
)
?
$default_count_cols
:
0
;
...
...
@@ -311,23 +316,41 @@ function tablefield_field_widget_form(&$form, &$form_state, $field, $instance, $
for
(
$i
=
0
;
$i
<
$count_rows
;
$i
++
)
{
$zebra
=
$i
%
2
==
0
?
'even'
:
'odd'
;
$element
[
'tablefield'
][
'b_break'
.
$i
]
=
array
(
'#markup'
=>
'<tr class="tablefield-row-'
.
$i
.
'
tablefield-
'
.
$zebra
.
'">'
,
'#markup'
=>
'<tr class="tablefield-row-'
.
$i
.
' '
.
$zebra
.
'">'
,
);
for
(
$ii
=
0
;
$ii
<
$count_cols
;
$ii
++
)
{
$cell_default
=
isset
(
$default_value
[
$i
][
$ii
])
?
$default_value
[
$i
][
$ii
]
:
''
;
$element
[
'tablefield'
][
'cell_'
.
$i
.
'_'
.
$ii
]
=
array
(
'#type'
=>
'textfield'
,
'#maxlength'
=>
2048
,
'#size'
=>
0
,
'#attributes'
=>
array
(
'id'
=>
'tablefield_'
.
$delta
.
'_cell_'
.
$i
.
'_'
.
$ii
,
'class'
=>
array
(
'tablefield-row-'
.
$i
,
'tablefield-col-'
.
$ii
),
'style'
=>
'width:100%'
),
'#default_value'
=>
(
empty
(
$field_value
))
?
$cell_default
:
$field_value
,
'#prefix'
=>
'<td style="width:'
.
floor
(
100
/
$count_cols
)
.
'%">'
,
'#suffix'
=>
'</td>'
,
);
$instance_default
=
$instance
[
'default_value'
][
$delta
][
'tablefield'
][
"cell_
{
$i
}
_
{
$ii
}
"
];
if
(
!
empty
(
$instance_default
)
&&
!
empty
(
$field
[
'settings'
][
'lock_values'
])
&&
$arg0
!=
'admin'
)
{
// The value still needs to be send on every load in order for the
// table to be saved correctly.
$element
[
'tablefield'
][
'cell_'
.
$i
.
'_'
.
$ii
]
=
array
(
'#type'
=>
'value'
,
'#value'
=>
$instance_default
,
);
// Display the default value, since it's not editable.
$element
[
'tablefield'
][
'cell_'
.
$i
.
'_'
.
$ii
.
'_display'
]
=
array
(
'#type'
=>
'item'
,
'#title'
=>
$instance_default
,
'#prefix'
=>
'<td style="width:'
.
floor
(
100
/
$count_cols
)
.
'%">'
,
'#suffix'
=>
'</td>'
,
);
}
else
{
$cell_default
=
isset
(
$default_value
[
$i
][
$ii
])
?
$default_value
[
$i
][
$ii
]
:
''
;
$element
[
'tablefield'
][
'cell_'
.
$i
.
'_'
.
$ii
]
=
array
(
'#type'
=>
'textfield'
,
'#maxlength'
=>
2048
,
'#size'
=>
0
,
'#attributes'
=>
array
(
'id'
=>
'tablefield_'
.
$delta
.
'_cell_'
.
$i
.
'_'
.
$ii
,
'class'
=>
array
(
'tablefield-row-'
.
$i
,
'tablefield-col-'
.
$ii
),
'style'
=>
'width:100%'
),
'#default_value'
=>
(
empty
(
$field_value
))
?
$cell_default
:
$field_value
,
'#prefix'
=>
'<td style="width:'
.
floor
(
100
/
$count_cols
)
.
'%">'
,
'#suffix'
=>
'</td>'
,
);
}
}
$element
[
'tablefield'
][
'c_break'
.
$i
]
=
array
(
'#markup'
=>
'</tr>'
,
...
...
@@ -459,7 +482,7 @@ function tablefield_import_csv($form, &$form_state) {
}
fclose
(
$handle
);
$form_state
[
'input'
][
$field_name
][
$language
][
$delta
][
'tablefield'
][
'rebuild'
][
'count_cols'
]
=
$form_state
[
'values'
][
$field_name
][
$language
][
$delta
][
'tablefield'
][
'rebuild'
][
'count_cols'
]
=
$max_col_count
;
$form_state
[
'input'
][
$field_name
][
$language
][
$delta
][
'tablefield'
][
'rebuild'
][
'count_rows'
]
=
...
...
@@ -489,30 +512,36 @@ function tablefield_delete_table_values(&$tablefield) {
/**
* AJAX callback to rebuild the number of rows/columns.
* The basic idea is to descend down the list of #parent elements of the
* clicked_button in order to locate the tablefield inside of the $form
* The basic idea is to descend down the list of #parent elements of the
* clicked_button in order to locate the tablefield inside of the $form
* array. That is the element that we need to return.
* @param array $form
* @param array $form_state
*/
function
tablefield_rebuild_form_ajax
(
$form
,
$form_state
)
{
$rebuild
=
$form
;
$parents
=
$form_state
[
'clicked_button'
][
'#parents'
];
foreach
(
$form_state
[
'clicked_button'
][
'#parents'
]
as
$parent
)
{
// Locate the delta of the field - 0 deltas need to break after
// descending to the 'rebuild' element, but deltas greater than
// 0 need to break /before/ adding the 'rebuild' element.
if
(
is_int
(
$parent
))
{
$delta
=
$parent
;
}
$tmp
=
$rebuild
;
if
(
$parent
==
'rebuild'
||
$parent
==
'import'
)
{
$rebuild
=
$delta
==
0
?
$tmp
[
$parent
]
:
$tmp
;
//$rebuild = $tmp[$parent];
break
;
if
(
$form
[
'#id'
]
==
'field-ui-field-edit-form'
)
{
$rebuild
=
$form
[
'instance'
][
'default_value_widget'
][
$parents
[
0
]];
}
else
{
foreach
(
$parents
as
$parent
)
{
// Locate the delta of the field - 0 deltas need to break after
// descending to the 'rebuild' element, but deltas greater than
// 0 need to break /before/ adding the 'rebuild' element.
if
(
is_int
(
$parent
))
{
$delta
=
$parent
;
}
$tmp
=
$rebuild
;
if
(
$parent
==
'rebuild'
||
$parent
==
'import'
)
{
$rebuild
=
$delta
==
0
?
$tmp
[
$parent
]
:
$tmp
;
//$rebuild = $tmp[$parent];
break
;
}
$rebuild
=
$tmp
[
$parent
];
}
$rebuild
=
$tmp
[
$parent
];
}
// We don't want to re-send the format/_weight options.
...
...
@@ -520,7 +549,7 @@ function tablefield_rebuild_form_ajax($form, $form_state) {
unset
(
$rebuild
[
'_weight'
]);
// We need to avoid sending headers or the multipart form
// will make it fail. So, we need to explicitly define the
// will make it fail. So, we need to explicitly define the
// whole response to ajax_deliver().
return
array
(
'#type'
=>
'ajax'
,
...
...
@@ -555,7 +584,7 @@ function tablefield_rebuild_form($form, &$form_state) {
/**
* Helper function to turn form elements into a structured array.
*
*
* @param array $tablefield
* The table as it appears in FAPI.
*/
...
...
@@ -596,25 +625,23 @@ function tablefield_theme() {
}
/**
* Theme function for table view
* Theme function for table view
*/
function
theme_tablefield_view
(
$variables
)
{
$attributes
=
array
(
'id'
=>
'tablefield-'
.
$variables
[
'delta'
],
'id'
=>
'tablefield-'
.
$variables
[
'delta'
],
'class'
=>
array
(
'tablefield'
),
);
return
'<div id="tablefield-wrapper-'
.
$variables
[
'delta'
]
.
'" class="tablefield-wrapper">'
.
theme
(
'table'
,
return
'<div id="tablefield-wrapper-'
.
$variables
[
'delta'
]
.
'" class="tablefield-wrapper">'
.
theme
(
'table'
,
array
(
'header'
=>
$variables
[
'header'
],
'rows'
=>
$variables
[
'rows'
],
'header'
=>
$variables
[
'header'
],
'rows'
=>
$variables
[
'rows'
],
'attributes'
=>
$attributes
,
)
)
)
.
'</div>'
;
}
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