I am trying to find a way, if there is one, to prevent a user from rebuilding the table when they are creating content. I have a table that is X columns by Y rows and it doesn't need to be changed for the content type I've created. I'd like to remove the "How many Columns:" and "How many rows:" fields, and remove the "Rebuild Table" button, or at least disable them.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Kevin Hankens’s picture

Yeah, that's a great idea. What we should do is add a hook_perm entry and use user_access() when it builds the form. Feel free to submit a patch. Otherwise, I can probably do one later this afternoon...

giorgio79’s picture

+1

giorgio79’s picture

FileSize
2.59 KB

Hello,

Here is a patch.

It adds two checkboxes on the edit field page:
1. Enable Users changing the number of rows
2. Enable Users changing the number of columns

Default is enabled.

If both are disabled no buttons show, if one of them is enabled the field plus the rebuild button shows.

Check it out :)

giorgio79’s picture

Status: Active » Needs review
giorgio79’s picture

FileSize
2.95 KB

Found a bug, here is a new version

giorgio79’s picture

FileSize
3 KB

Even more improvements. Now the default table rebuild options appear regardless of these switches.

jonathan_hunt’s picture

This patch improves on #6 by making the CSV upload an option on a per-field instance (and improves code style also).

bojanz’s picture

Status: Needs review » Reviewed & tested by the community

I agree with #7, it's better to have it as a per-field setting (my use case requires the rebuild option to be gone for all roles).
I think the option between "have it"/"don't have it" is much common than "let this role have it"/"but don't let those two have it".
Plus, if it's this way then I can turn off rebuilding when creating a field. If it's a permission then I can't do anything from code.

Checked, still applies against the D6 version.
Marking as RTBC.

If you agree, I can provide the reroll for 7.x.

tectokronos’s picture

Hi,

There is a little error in the patch posted by jonathan_hunt:

Double periods (wrong):

+
+  if ($field['enable_row_change'] || $form['#id'] == 'content-field-edit-form') {
+    $type = "textfield";
+  }
+  else {
+    $type = 'value';
+  }
+

Correction:

+
+  if ($field['enable_row_change'] || $form['#id'] == 'content-field-edit-form') {
+    $type = 'textfield';
+  }
+  else {
+    $type = 'value';
+  }
+

This patch is awesome. Thank you very much!! :D

qayoub’s picture

Help!!
how can i fix the header of a table field for a specific content type !?

bassem’s picture

Version: 6.x-1.0 » 7.x-2.0-beta4

Hello all,

ANy news for the same feature being available for D7? it is quite essential if you are using cck forms for online applications that handle quite a large number of submissions and allowing csv uploads could be a high security risk.

regards,
bas

jaskegreen’s picture

Still need this to work in version 7.

Cheers,
Jason

sam@sasiaccc.org’s picture

Hi ,

I am very new to drupal. Can some say how to install the patch so that I could disable the "rebuild table" option
Thanks in advance

drifter’s picture

Here's a form_alter hook that will disable the rebuild table and import options on Drupal 7. You can use them in a custom module. The important thing is that count_cols and count_rows still need to be passed.


function mymodule_form_alter(&$form, $form_state, $form_id) {
  if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
    $fields = field_info_fields(NULL, $form['type']['#value']);
    foreach ($fields as $field_name => $field) {
      if (isset($form[$field_name]['und']['0']['tablefield'])) {
          $cols = $form[$field_name]['und']['0']['tablefield']['rebuild']['count_cols']['#value'];
          $rows = $form[$field_name]['und']['0']['tablefield']['rebuild']['count_rows']['#value'];
          unset($form[$field_name]['und']['0']['tablefield']['rebuild']);
          unset($form[$field_name]['und']['0']['tablefield']['import']);
          $form[$field_name]['und']['0']['tablefield']['rebuild'] = array(
            'count_cols' => array(
              '#type'  => 'hidden',
              '#value' => $cols,
            ),
            'count_rows' => array(
              '#type'  => 'hidden',
              '#value' => $rows,
            )
          );
      }
    }
  }
}
h.arefmanesh’s picture

Version: 7.x-2.0-beta4 » 7.x-2.1
FileSize
1.16 KB

I write a new patch ,
This patch create a permission for displaying "rebuild table" button.

Kevin Hankens’s picture

Status: Reviewed & tested by the community » Closed (fixed)

So sorry that this has languished for so long. I'm trying desperately to play catch up here.

Here's a commit to 7.x-2.x that provides role-based access permissions to rebuild the tables. There's an edge case where csv imports can redefine the structure, but it's probably debatable as to how to handle that.

Thanks to everyone who contributed!!

http://drupalcode.org/project/tablefield.git/commit/6cbec457d80100b578c1...