Hi,
nifty module! I needed to disable the rebuilding/resizing as well as the importing functionality on a per field basis; i've attached a small patch that does that.

But the way tablefield_rationalize_table() works it's not so easy, because it ultimately relies on user-submitted values for rows/columns; if the function signature of tablefield_rationalize_table() was to include the usual field-api "fluff" ($field, $instance, maybe $entity, $entity_type, $bundle_name), i could change that, but i didnt want to muck around to much :) If you like the direction, I am happy to reroll the patch accordingly.

Patch is against HEAD.

Best, Fredrik

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

morbiD’s picture

The patch applied ok, but when I save a node containing a table field, the last row and column get removed.

For example, if the field defaults are set to 5 rows and 4 columns, when I save the node, the field changes to have 4 rows and 3 columns.

frega’s picture

Does this only happen after applying this patch? Or is that a general tablefield problem?

morbiD’s picture

I just retested on a fresh Drupal install.

No problem with unpatched tablefield.

No problem with patched tablefield and rebuilding/importing enabled.

Problem occurred with patched tabledfield and rebuilding/importing disabled with the new checkboxes. Columns reduced by 1, but rows actually reduced by 2.

I have now also noticed that this only happens when both rebuilding and importing are disabled AND default cells are locked for editing. It's like having 3 checkboxes checked triggers it, but only having 2 checkboxes checked doesn't.

Edit: Actually, the rows and columns get reduced down to the number of editable cells. For example, if you create a 10x10 table and fill 98 cells with default values, only 2 cells will remain when you save a node.

What seems to be happening is that when all 3 checkboxes are checked, tablefield_field_widget_form() gets called during the node save and messes up the row/column counts. If any of the checkboxes are unchecked tablefield_field_widget_form() doesn't get called so the table saves properly.

Unfortunately, I'm having trouble tracing what triggers that hook.

morbiD’s picture

Ok, so I found that the cause of the problem is the missing "Rebuild Table" button. If you add the following to replace it, the problem disappears:

$element['tablefield']['rebuild']['rebuild'] = array(
  '#type' => 'hidden',
  '#ajax' => array(
    'callback' => '',
    'event' => '',
  ),
);

I don't really understand why that stops the problem though, and it seems like a terrible way of fixing it. Any ideas?

liquidcms’s picture

there are a lot of button fields in this code; any chance you could re-roll your patch with the change in #4?

also, quick glance and i saw this:

} else {

which is not valid drupal coding format; so might be hard to have your change committed with things like that.

but.. this is a very obviously needed feature of this very cool module.. i would think in most use cases you don't want your user changing the number of columns/rows.

liquidcms’s picture

disregard my dumb comment; the rebuild function to replace with code in #4 is obvious. tested and this seems to work well.

stevecory’s picture

Issue summary: View changes

I need to disable the importing functionality on a per field basis.

vitalie’s picture

Version: 7.x-2.0-alpha5 » 7.x-2.x-dev

@stevecory, currently one could 'disable' the Rebuild functionality by using Restrict rebuilding to users with the permission "rebuild tablefield". If that works for you, perhaps we could implement something similar for the Import functionality?

stevecory’s picture

FileSize
63.46 KB

I agree with you vitalie. Has there been any progress on getting a permission added to disable the "Import from CSV"?

jenlampton’s picture

Status: Needs review » Needs work

Looks like there are still some @todos in this code. Marking as NW. FWIW I love this idea and would love to see a per-field setting as to whether the grid is resizable. Nice work so far :)

stevecory’s picture

How can I disable the "Table description", "UPLOAD CSV FILE" and the "COPY & PASTE" options on a per field basis.

lolandese’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev