I can switch the visibility for certain user roles, but what is the php code to show the block only for a specific nodetype?
Thank you for help!

CommentFileSizeAuthor
#4 authorcontact.module.txt6.35 KBelarifr

Comments

xqbzzr’s picture

Status: Active » Fixed

Found it on some other issue:

$match = FALSE;
$types = array('story' => 1, 'page' => 1);
if (arg(0) == 'node' && is_numeric(arg(1))) {
  $nid = arg(1);
  $node = node_load(array('nid' => $nid));
  $type = $node->type;
  if (isset($types[$type])) {
    $match = TRUE;
  }
}
return $match;

Just replace "story" and "page" with your nodetypes.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

elarifr’s picture

Hello
Instead of adding some code, should it be a feature added like in the author_pane block to display a check list of allowed content type to display the form ?
thanks

elarifr’s picture

Title: How to restrict to a certain nodetype? » Restrict the contact form only on desired content type, set width and height inside block
Status: Closed (fixed) » Needs review
StatusFileSize
new6.35 KB

finally i just made it :)
thanks to michelle works in author_pane

i've also added to select in the block the width form name/email and the height for the message

could see result here http://immo-g-meyer.fr and look at an house to have the form displayed

here's the code i change in authorcontact.module

 function authorcontact_block($op = 'list', $delta = 0, $edit = array()) {
    switch ($op) {
        case 'list':
            $blocks[0]['info'] = t('Author Contact');
            return $blocks;
        
        case 'configure':
            $form['authorcontact_desc'] = array(
                '#type' => 'textfield',
                '#title' => t('Contact description'),
                '#description' => t('This text will show at the top of the Author Contact block, can be used for instructions etc.'),
                '#default_value' => variable_get('authorcontact_desc', '')
            );

            $form['authorcontact_form_width'] = array(
                '#type' => 'textfield',
                '#title' => t('Form width for name & email'),
                '#description' => t('You can set here the size of the form width without change in the css #edit-sendername, #edit-senderemail, #edit-sendercomment {width:94%;} '),
                '#default_value' => variable_get('authorcontact_form_width', 15)
            );
            $form['authorcontact_form_height'] = array(
                '#type' => 'textfield',
                '#title' => t('Form height for message'),
                '#description' => t('You can set here thenumber of line to dislay in the message form. Standard is 4.'),
                '#default_value' => variable_get('authorcontact_form_height', 4)
            );
            
            //elari from author_pane
            $types = node_get_types();
            $options = array();
            foreach ($types as $type) {
              $options[$type->type] = $type->name;
            }
            
            $form['authorcontact_block_display_types'] = array(
              '#type' => 'checkboxes',
              '#title' => t('Node types to display on'),
              '#options' => $options,
              '#default_value' => variable_get('authorcontact_block_display_types', array()),
             );
            //elari

            
            return $form;
        
        case 'save':
            variable_set('authorcontact_desc', $edit['authorcontact_desc']);
            variable_set('authorcontact_form_width', $edit['authorcontact_form_width']);
            variable_set('authorcontact_form_height', $edit['authorcontact_form_height']);            
            variable_set('authorcontact_block_display_types', $edit['authorcontact_block_display_types']);
            break;
        
        case 'view':
                if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '') {
                //elari from authorpane        
                // We're on a node page so load the node.
                $node = $node = menu_get_object();
                $allowed_types = variable_get('authorcontact_block_display_types', array());
                if (empty($allowed_types[$node->type])) {
                  // Not a type we want to show on.
                  return;
                }            
                //elari end from authorpane            
                $block['subject'] = t('Contact Author');
                $block['content'] = t('<div class="authorcontact-desc">') . variable_get('authorcontact_desc', '') . t('</div>');
                $block['content'] .= drupal_get_form('authorcontact_form');
                return $block;
            }
            break;
        
    }
 }

/**
 * Define the form for the block
 */
 function authorcontact_form() {
    $node = node_load(arg(1));
    $form['sendername'] = array(
        '#title' => t('Your name'),
        '#type' => 'textfield',
        '#size' => variable_get('authorcontact_form_width', 15),
        '#required' => true
    );
    $form['senderemail'] = array(
        '#title' => t('Email'),
        '#type' => 'textfield',
        '#size' => variable_get('authorcontact_form_width', 15),
        '#required' => true,
		'#element_validate' => array('authorcontact_form_validate')
    );
    $form['sendercomment'] = array(
        '#title' => t('Comment'),
        '#type' => 'textarea',
        '#rows' => variable_get('authorcontact_form_height', 4),
        '#required' => true
    );
    $form['nodetitle'] = array(
        '#type' => 'hidden',
        '#value' => $node->title
    );
    $form['send'] = array(
        '#type' => 'submit',
        '#value' => t('Send')
    );
    return $form;
} 
JmsCrk’s picture

Thanks for the code elarifr, I'll review this and add it into the dev of the module.

El Bandito’s picture

+1 for this in DEV.

Thanks.

Dave

JmsCrk’s picture

Component: Documentation » Code
Assigned: Unassigned » JmsCrk
Status: Needs review » Fixed

Now committed to 6.x dev version - thanks for the code Elari

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.