I know I am able to hide the filefield from the form using Content Access. But what about if I just want to dissallow them to Edit filefield?

I want my user to be able to Create and Upload a file. But when editing, I want to hide the Filefield (upload form), and only allow them to change Title, descriptions and other text field.

Is there already a plugins, patch or even module available out there?

Thanks.

Comments

quicksketch’s picture

I do not think there are any plugins/patches/modules that do what you want. I'd suggest you write a custom module and use hook_form_alter() to hide the FileField when the node is being edited.

function mymodule_form_alter(&$form_state, &$form, $form_id) {
  if ($form_id == 'blog_node_form') {
    $node = $form['#node'];
    if ($node->nid) {
      $form['field_file']['#access'] = FALSE;
    }
  }
}
sadist’s picture

Hi quicksketch, thanks for your reply. Sorry for not responding earlier as I was busy with other projects.

I'd tried your method but it doesn't work. Let's say, I create my own custom 'video' module. This module will create a content-type, and I create the video filefield manually.
So I place this in my video.module:

function video_form_alter(&$form_state, &$form, $form_id) {
  if ($form_id == 'video_node_form') {
    $node = $form['#node'];
    if ($node->nid) {
      $form['field_file']['#access'] = FALSE;
    }
  }
}

But it doesn't work, I or other normal user will still be able to see the filefield when editing their video node.

sadist’s picture

Just to share with the rest who might need this. I managed to hide it when editing node using the function below in my custom video module:

function video_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'video_node_form') {
    $node = $form['#node'];
    if ($node->nid) {
    $form['field_video'][0]['#access'] = FALSE;
    $form['field_video'][ffmpeg_converter_delete]['#access'] = FALSE;
    }
  }
}

However, I'd tried alot of methods for me to disable the fieldset collapsible. Right now, it is at expand state, but i don't want it to be collapsible at all. I even want to remove the fieldset title.

Anyone can help me with this? Thanks.

quicksketch’s picture

Status: Active » Closed (fixed)

I'm glad you got the basics working, however support for writing custom code is generally not provided in the FileField queue. As such I'm closing this issue.