Currently, the "Header orientation" (meaning whether the first row, first column or both are headers) is a setting in the field formatter.

However, this isn't so much a display setting, as a setting about the semantics of the table data.

For example, technically, you could have the "Header orientation" be "First row" on the "Default" view mode, but "First column" on the "Teaser" view mode on the same content type. But for the same table data, that doesn't really make sense: the first row or first column are headers or values semantically, ie. it's just part of that specific table data.

Also, it'd be nice to have a tables of different "Header orientations" on different nodes of the same content type, as opposed to having to have a separate content type or field for tables with horizontal vs vertical headers.

Is this something that this project's maintainers would be open to?

I saw reference to doing this on the Drupal 8 version here:

#3019613-24: Move display related settings from manage fields to manage display and add options

What about on the Drupal 7 version?

The challenge for Drupal 7, of course, is the upgrade path, because there are lots of existing sites out there where this is only a field formatter setting, and maybe some of them don't want this configurable per entity. I'm not sure the best way to handle that, so just starting the discussion here first.

Thanks! :-)

Issue fork tablefield-3128030

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dsnopek created an issue. See original summary.

lolandese’s picture

Thanks for your interest still in the D7 version of this module. As you might have noticed there is no feature parity yet between the 7.3 and 8.2 version of the module. Oddly the D8 version lacks behind as it does not offer many new features that were introduced in the 7.x-3.x branch

Like you said, to be able to define the header orientation per individual table (just like the caption) does make more sense than currently being a field setting in a view mode. So, yes, a patch would be definitely welcomed. The upgrade path could iterate through all existing fields on all entities and set those to replicate the same current behaviour set in the default view mode for the bundle. We might as well mention that in the UPGRADE.txt and the in the release notes of a new stable version.

Ideally, we should pursue feature parity, so later that should be ported to D8 as well.

Also, as a more generic alternative solution consider #3019613-26: Move display related settings from manage fields to manage display and add options. It looks that the sandbox mentioned there for D7 lets you accomplish this differently. Look at the screenshot from the imaginary "About us" node page that offers a tab that makes you change the display settings for that node alone per field. You might want to test that first and report your findings.

dsnopek’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new44.32 KB
new11.51 KB

Alright, thanks!

Here's a patch that implements this.

It puts the "Header orientation" under "Change number of rows/columns" because that seemed like the most natural place for this:

And, if the user changes it and clicks "Rebuild Table" it'll update the styling on the form for the type of header. I had to switch this styling to use CSS classes on the field item, rather than conditionally loading certain CSS files. Whether or not the user can change this follows the same logic as if the user can change the number of rows or columns.

The default "Header orientation" for a field comes from the field's default value, which is also where the default row and column count come from.

So, for the update hook, it's moving the "Header orientation" from the field formatter on the default view mode, over to the default value on the field. Since this is used for the default of an field value that doesn't have a "Header orientation" set, this should be sufficient, we don't need to copy it on to every entity.

Please let me know what you think! Thanks :-)

lolandese’s picture

Status: Needs review » Needs work

Patch applies cleanly:

martin@martin-XPS-13-9370 /var/www/html/yellow.localhost/web/sites/all/modules/contrib/tablefield (7.x-3.x=) $ git apply -v tablefield-header-orientation-3128030-3.patch
Checking patch css/tablefield.css...
Checking patch css/tablefield_header_hor.css...
Checking patch css/tablefield_header_vert.css...
Checking patch tablefield.install...
Checking patch tablefield.module...
Applied patch css/tablefield.css cleanly.
Applied patch css/tablefield_header_hor.css cleanly.
Applied patch css/tablefield_header_vert.css cleanly.
Applied patch tablefield.install cleanly.
Applied patch tablefield.module cleanly.

Update executes smoothly:

martin@martin-XPS-13-9370 /var/www/html/yellow.localhost/web/sites/all/modules/contrib/tablefield (7.x-3.x *=) $ drush updb -y
 Tablefield  7008  Move 'Header orientation' from formatter settings to default field value.
Do you wish to run all pending updates? (y/n): y
Performed update: tablefield_update_7008                                                                                                                    [ok]
'all' cache was cleared.                                                                                                                                    [success]
Finished performing updates.                                                                                                                                [ok]
martin@martin-XPS-13-9370 /var/www/html/yellow.localhost/web/sites/all/modules/contrib/tablefield (7.x-3.x *=) $ drush cc all
'all' cache was cleared.

On existing content (Edit):

Notice: Undefined index: header_orientation in tablefield_field_widget_form() (line 1338 of /var/www/html/yellow.localhost/web/sites/all/modules/contrib/tablefield/tablefield.module).
Notice: Undefined index: header_orientation in tablefield_field_widget_form() (line 1338 of /var/www/html/yellow.localhost/web/sites/all/modules/contrib/tablefield/tablefield.module).
Notice: Undefined index: header_orientation in tablefield_field_widget_form() (line 1338 of /var/www/html/yellow.localhost/web/sites/all/modules/contrib/tablefield/tablefield.module).

Furthermore, the table display was originally set to both first to and column but was converted to first row only.

On edit save and adding new content all was working flawlessly as expected. Tested if a single multi-value table field could be displayed with the first table having both row and column as a header, the second only the first row and the third only the first column. It was all fine.

An awesome new feature. Looking forward to seeing this committed. BTW, I hope you don't mind I added you as a co-maintainer as you made commits to the TableField module also in the past and your D.O. profile shows an incredible +7K number of commits.

dsnopek’s picture

Status: Needs work » Needs review
StatusFileSize
new1.42 KB
new12.11 KB

Thanks for the feedback!

On existing content (Edit):

Notice: Undefined index: header_orientation in tablefield_field_widget_form() (line 1338 of /var/www/html/yellow.localhost/web/sites/all/modules/contrib/tablefield/tablefield.module).
Notice: Undefined index: header_orientation in tablefield_field_widget_form() (line 1338 of /var/www/html/yellow.localhost/web/sites/all/modules/contrib/tablefield/tablefield.module).
Notice: Undefined index: header_orientation in tablefield_field_widget_form() (line 1338 of /var/www/html/yellow.localhost/web/sites/all/modules/contrib/tablefield/tablefield.module).

Furthermore, the table display was originally set to both first to and column but was converted to first row only.

Attached is a new patch that fixes these two problems.

BTW, I hope you don't mind I added you as a co-maintainer as you made commits to the TableField module also in the past and your D.O. profile shows an incredible +7K number of commits.

Thanks, however, I don't really have much time to devote to maintaining yet another module, but I'll help out as I'm able. :-)

cboyden’s picture

Overall this is looking pretty good. The help text (if you're not hiding the first row) says "The first row will appear as the table header. Leave the first row blank if you do not need a header." Does this need to be adjusted now that there are multiple options for header orientation?

lolandese’s picture

Status: Needs review » Reviewed & tested by the community

Patch applies cleanly:

martin@martin-XPS-13-9370 /var/www/html/yellow.localhost/web/sites/all/modules/contrib/tablefield (7.x-3.x=) $ git apply -v tablefield-header-orientation-3128030-5.patch
Checking patch css/tablefield.css...
Checking patch css/tablefield_header_hor.css...
Checking patch css/tablefield_header_vert.css...
Checking patch tablefield.install...
Checking patch tablefield.module...
Applied patch css/tablefield.css cleanly.
Applied patch css/tablefield_header_hor.css cleanly.
Applied patch css/tablefield_header_vert.css cleanly.
Applied patch tablefield.install cleanly.
Applied patch tablefield.module cleanly.

Update runs flawless:

martin@martin-XPS-13-9370 /var/www/html/yellow.localhost/web/sites/all/modules/contrib/tablefield (7.x-3.x *=) $ drush updb -y
 Tablefield  7008  Move 'Header orientation' from formatter settings to default field value.
Do you wish to run all pending updates? (y/n): y
Performed update: tablefield_update_7008                                                                                                                    [ok]
'all' cache was cleared.                                                                                                                                    [success]
Finished performing updates.

[ok]

Both of the issues mentioned previously in comment #4 are now solved. That means there are no undefined errors on existing content and the settings as they were are ported correctly to both the field settings and on the content. I also checked if the old display option for the field was removed.

All fine.

About what to do if the first row is hidden, I checked the functionality. That is still there and works as expected. What becomes then the first row is then not displayed as a header anymore. That is identical to the previous behavior, so fine with me. But honestly, I forgot the exact use case of that option. I believe it is used in case one wants to see in the form edit what data to fill in, without making it visible in the node. A sort of column enabled field help description I guess. It would make sense to think it over but a new issue should be opened for that.

I suggest a small change to the name of the field group from:
Change number of rows/columns.
to simply:
Number of rows/columns and header orientation

  • lolandese committed e176680 on 7.x-3.x authored by dsnopek
    Issue #3128030 by dsnopek: Make "Header orientation" a per entity...
lolandese’s picture

Status: Reviewed & tested by the community » Fixed

About the co-maintainership, just pick up things where you see fit. No obligations of any sort.

Many thanks for your awesome contribution.

lolandese’s picture

Version: 7.x-3.x-dev » 8.x-2.x-dev
Status: Fixed » Patch (to be ported)
alpe89’s picture

This is just what I was looking for :)
Will this be in the next 7.x release? Any idea of when this will be?

lolandese’s picture

Will this be in the next 7.x release?

Yes, it will. I or any other maintainer will release a new stable release soon. Feel free to use the dev version meanwhile. Just in case, make a backup to be able to roll back, but it should be okay.

gresko8’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new5.88 KB

Here's a patch for 8.x-2.x version. Columns for 'row_header' and 'column_header' are added to field schema and rendered as checkboxes according to the tablefield formatter settings).

nicholass’s picture

Patch #13 worked great for me. - Thanks!

Drupal core 8.9.13
TableField: 8.x-2.2

lolandese’s picture

Thanks for this D8 port.

When reviewing it, try to explain what you tested more extensively as described in https://www.drupal.org/patch/review. Make sure to cover all scenarios, like using the vertical header, drag of rows, and import of a CSV. Ideally, we should extend the automated tests. It would be the only way to add new features to this module in a reliable way.

After thorough testing, feel free to also change the issue status to RTBC.

chri5tia’s picture

Hello Team,
Upon testing the patch supplied in Comment 13, we see an integrity constraint violation (as well as mismatched entity definitions for the paragraph tablefield entity).

The integrity constraint violation happens after attempting to save any node which uses a tablefield paragraph entity, after applying the patch.

The patch updates the install file to include:

/**
 * Add columns for setting row and column header per field value to the database.
 */
function tablefield_update_8002() {
  tablefield_add_new_column('row_header', [
    'type' => 'int',
    'size' => 'tiny',
    'default' => 0,
    'not null' => TRUE,
  ]);
  tablefield_add_new_column('column_header', [
    'type' => 'int',
    'size' => 'tiny',
    'default' => 0,
    'not null' => TRUE,
  ]);

Something is problematic with default 0 and not null = true not applying correctly I think, not sure.

chri5tia’s picture

Here is a new patch that resolves the integrity constraint violation, moves the checkboxes and adds some unit tests, among a few other things.

chri5tia’s picture

StatusFileSize
new6.43 KB

Renamed.

coderdan’s picture

Re-rolled patch from #18 for version 2.3.

avpaderno’s picture

Title: Make "Header orientation" a per entity setting? » Make "Header orientation" a per entity setting
Status: Needs review » Needs work
solantoast’s picture

Re-rolled patch from #19.

avpaderno’s picture

Status: Needs work » Needs review
gresko8’s picture

I tested the patch in #21 and it works well. Thanks!

The only thing that probably needs to be fixed is that we still have the checkboxes in field formatter settings. Since they are ignored because the actual settings stored on the entity are used, we should probably get rid of them.

lolandese’s picture

Status: Needs review » Needs work

See comment #23:

We still have the checkboxes in field formatter settings but these are now ignored.

antonio_zoocha’s picture

I applied suggestion from #23 over patch from #21

antonio_zoocha’s picture

Status: Needs work » Needs review
liam morland’s picture

Version: 8.x-2.x-dev » 3.0.x-dev
Status: Needs review » Needs work
Issue tags: +Needs reroll

Please use an issue fork and merge request.

agentrickard made their first commit to this issue’s fork.

agentrickard’s picture

Patch no longer applies cleanly.

agentrickard’s picture

This is working fine on a clean install, but when applied to an existing Drupal 11 site, the `Use header` option still appears.

Investigating.

*UPDATE*

The use header option is a custom field that we were using.

agentrickard’s picture

Status: Needs work » Needs review

MR is ready for review.

liam morland’s picture

There is one coding standards issue to fix.

agentrickard’s picture

Odd, I would have expected the MR to not have a green check in that case.

Anyway, fixed.

liam morland’s picture

Coding standards issues do not prevent tests from being counted as passed.

agentrickard’s picture

Yeah,. I thought we could set that to strict. I suppose we can only skip them.

liam morland’s picture

It can be configured so that coding standards issues create failures instead of warnings and then the overall will report a failure.

agentrickard’s picture

Issue tags: -Needs reroll

All that aside, this seems to be working as expected.

nicholass’s picture

Just reporting been running the 41.diff for 11 months on prod and no issues, so going to mark as Reviewed.

nicholass’s picture

Status: Needs review » Reviewed & tested by the community