0

I created my first block in drupal. It basically creates a node create link for the places content type. But someone it doesn't work.

Can someone help me with this.

function custom_site_block($op = 'list', $delta = 0, $edit = array()) {  
$blocks = array();
if ($op == "list") {
    // Generate listing of blocks from this module, for the admin/block page

$blocks['create_place'] = array(
    'info' => t('Create a place'),
    'cache' => BLOCK_CACHE_GLOBAL,
);
}
else {

    $form = array();
    $form['#action'] = url('node/add/place');
    $form['create'] = array(
    '#type' => 'submit',
    '#value' => t('Create a place'),
    );

}
 return $blocks;
} 

2 Answers 2

0
function custom_site_block($op = 'list', $delta = 0, $edit = array()) {  
  $blocks = array();

  switch ($op) {

    case 'list':

      $blocks['create_place']['info'] = t('Create a place');
      $blocks['create_place']['cache'] = BLOCK_CACHE_GLOBAL;

      return $blocks;

    case 'view':

      switch ($delta) {

        case 'create_place':

          $blocks['subject'] = t('My First Block');
          $blocks['content'] = l(t('Create a place'),'node/add/place');

          return $blocks;
      }
  }
}
2
  • Thanks for the help. also where I do write a block specific css ? just inside my theme file ?
    – Jayaram
    Commented Feb 13, 2012 at 14:33
  • You can just add it to any of your theme's css files or add it yourself with drupal_add_css().
    – Jimajamma
    Commented Feb 13, 2012 at 18:18
0

You should be using the menu system to do this. Go to 'admin/structure/menu' and add a menu and a menu item with the link above. This will automatically create a block.

4
  • Does it mean I cannot create menu items by writing a block ?
    – Jayaram
    Commented Feb 9, 2012 at 22:30
  • You can create links in custom blocks but it would be a wasted effort. Why write custom code in a custom module when Drupal core already has this functionality?
    – acouch
    Commented Feb 9, 2012 at 22:37
  • Actually I know that but i wanna change the way the link appears. How Can I do this ? Do I need to write a view for this ?
    – Jayaram
    Commented Feb 9, 2012 at 22:41
  • You need to be more precise in what you are asking for. In your description you say, "It basically creates a node create link". Please either revise the question or mark it as answered. Either way please update the title to more precisely reflect what you are trying to do.
    – acouch
    Commented Feb 9, 2012 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.