Hi,

I don't know how to enable attachements for certain node types only. I don't want to allow users to attach a file to an image node.

Thanks,

Charly

CommentFileSizeAuthor
#5 attach-by-title.patch1.41 KBcharly

Comments

robmilne’s picture

There is currently no way to conditionalize webfm attachment by node type. Does this functionality exist for the upload module?

charly’s picture

I got my hand on this.

To add radios on admin/content/type/x:
in function webfm_form_alter, add

  if ($form_id == 'node_type_form') {
    $form['workflow']['webfm_attach'] = array(
      '#type' => 'radios',
      '#title' => t('Attach files'),
      '#default_value' => variable_get('webfm_attach_'. $form['#node_type']->type, 0),
      '#options' => array(0 => t('Disabled'), 1 => t('Enabled')),
      '#description' => t('Should this node allows users to upload and attach files ?'),
      );
  }

To show the form on allowed node types only, replace the line
if (user_access('attach WebFM files') && $form['type']['#value'] .'_node_form' == $form_id && variable_get("wfm_attach_$node->type", TRUE)) {
by

 _get("wfm_attach_$node->type", TRUE)) {
    if (user_access('attach WebFM files') && $form['type']['#value'] .'_node_form' == $form_id && variable_get("webfm_attach_$node->type", 0)) { 

in the same function.

It seems the wfm_attach_$node->type veriable is some junk of previous version, or whetever. I didn't look at all the code.

I don't post a patch because my local version has some other changes (it only shows one collapsible form showing attached files & file browser).

Thanks,

Charly

charly’s picture

Assigned: Unassigned » charly
Category: support » feature
Status: Active » Needs review
robmilne’s picture

Thanks a lot for the input. I really appreciate it.
I tried your fix and made some minor changes:

/**
 * Implementation of hook_form_alter().
 */
function webfm_form_alter($form_id, &$form) {
  global $base_url;

  if ($form_id == 'node_type_form') {
    $form['workflow']['webfm_attach'] = array(
      '#type' => 'radios',
      '#title' => t('WebFM Attachments'),
      '#default_value' => variable_get('webfm_attach_'.$form['#node_type']->type, 0),
      '#options' => array(0 => t('Disabled'), 1 => t('Enabled')),
      '#description' => t('Should this node allow users to upload and attach files via WebFM?'),
      );
  }

  if (isset($form['type'])) {
    $node = $form['#node'];
    if (user_access('attach WebFM files') &&
        $form['type']['#value'] .'_node_form' == $form_id &&
        variable_get('webfm_attach_'.$node->type, 0)) {
charly’s picture

StatusFileSize
new1.41 KB

hi,

sorry for delay,

this patch can be applied on developement version. it just keeps wfm_attach_ variable (cause used elsewhere).

  function webfm_form_alter($form_id, &$form) {
   global $base_url;
 
+  if ($form_id == 'node_type_form') {
+    $form['workflow']['wfm_attach'] = array(
+      '#type' => 'radios',
+      '#title' => t('WebFM Attachments'),
+      '#default_value' => variable_get('wfm_attach_'. $form['#node_type']->type, 1),
+      '#options' => array(0 => t('Disabled'), 1 => t('Enabled')),
+      '#description' => t('Should this node allow users to upload and attach files via WebFM?'),
+    );
+  }
   if (isset($form['type'])) {
-    if ($form['type']['#value'] .'_node_settings' == $form_id) {
-      $form['workflow']['wfm_attach_'. $form['type']['#value']] = array(
-        '#type' => 'radios', '#title' => t('Webfm Attachments'), '#default_value' => variable_get('wfm_attach_'. $form['type']['#value'], 1),
-        '#options' => array(t('Disabled'), t('Enabled')),
-      );
-    }
-
     $node = $form['#node'];
-    if (user_access('attach WebFM files') && $form['type']['#value'] .'_node_form' == $form_id && variable_get("wfm_attach_$node->type", TRUE)) {
+    if (user_access('attach WebFM files') && $form['type']['#value'] .'_node_form' == $form_id && variable_get("wfm_attach_$node->type", 1)) {
 
       $modulepath = drupal_get_path('module', 'webfm');
       drupal_add_js($modulepath.'/js/webfm.js');

robmilne’s picture

I don't think the following line will work:

variable_get("wfm_attach_$node->type", 1)) {

The code I sent below was:

variable_get('webfm_attach_'.$node->type, 0)) {

Test it out.

charly’s picture

I don't see difference, but it's right it's better to always use same syntax

Regards,

robmilne’s picture

Status: Needs review » Fixed

Version 1.6 has this feature.

Anonymous’s picture

Status: Fixed » Closed (fixed)