0

I have searched everywhere for an answer to this question, and have found little to no help on the subject.

The closest question to my own would be this, but the answer for it is a bit different than what I'm looking for: How to move block functions into .inc file?

Here is my code for the most part (everything removed that wasn't necessary):

<?php

function custom_giggity_block_info(){
  $block['custom_giggity'] = array(
    'info' => t('Custom giggity'),
    'cache' => DRUPAL_NO_CACHE,
  );
  return $block;
}

function custom_giggity_block_view($delta = ''){
  $block = array();
  if($delta == 'custom_giggity'){
    $block['content'] = custom_giggity_contents($delta);
  }
  return $block;
}

function custom_giggity_contents($delta){
  //Code that generates what goes into $block['content']
  return $output;
}

And I need to use something like this, and don't know how to incorporate it:

function giggity_contents() {
  $items['giggity'] = array(
    'title' => "Giggity",
    'page callback' => "show_giggity", //or custom_giggity_contents ;)
    'access arguments' => array('access content'),
    'file' => 'giggity.inc',
    'type' => MENU_CALLBACK
  );
  return $items;
}

Now I realize that the second block of code there might completely off, but I'm just using it as an example as to what I need to accomplish.

Edit: So this is what I'd like to accomplish, but I'm not sure how the $items callbacks work. I took this piece of code from a hook_menu() and replaced it with giggity_contents.

<?php

function custom_giggity_block_info(){
  $block['custom_giggity'] = array(
    'info' => t('Custom giggity'),
    'cache' => DRUPAL_NO_CACHE,
  );
  return $block;
}

function custom_giggity_block_view($delta = ''){
  $block = array();
  if($delta == 'custom_giggity'){
    $block['content'] = giggity_contents($delta);
  }
  return $block;
}

function giggity_contents() {
  $items['giggity'] = array(
    'title' => "Giggity",
    'page callback' => "custom_giggity_contents",
    'access arguments' => array('access content'),
    'file' => 'giggity.inc',
    'type' => MENU_CALLBACK
  );
 return $items;
}

giggity.inc file:

 function custom_giggity_contents($delta){
  //Code that generates what goes into $block['content']
  return $output;
 }   
  • the page callback can be whatever function callback you want. you just need to be sure to use include once or require once to include your .inc file with custom functions at the top of your module file. – tenken Aug 21 '14 at 20:19
  • @tenken mind to have a look again (above and below)? Not working as expected. – Luke3butler Aug 22 '14 at 18:38
1

Like tenken said, use include_once at the top of the ".module" file like this:

<php
include_once drupal_get_path('module', 'module_name') . '/module_name.functions.inc';
?>
  • Is the answer staring me in the face? I can literally use the code I posted on the second block? – Luke3butler Aug 21 '14 at 21:58
  • You want to replace 3 functions with 1 ? You can't, each hook has it's own purpose. If the question is another I don't understand it. – NeoHQ Aug 22 '14 at 14:28
  • I realize that. I'm sorry, I didn't communicate very well. I added to my OP with what I'd like the result to look like. – Luke3butler Aug 22 '14 at 14:41
  • It will work, you only need to include "giggity.inc" file at the top of "module_name.module" file as I did above, after that you can use those function eveywhere inside ".module" file, doesn't matter if you use them as callbacks or calling the functions directly. – NeoHQ Aug 22 '14 at 15:36
  • Doesn't work. $block['content'] is getting array( 'title' => "Giggity", 'page callback' => "custom_giggity_contents", 'access arguments' => array('access content'), 'file' => 'giggity.inc', 'type' => MENU_CALLBACK ); as it's content. – Luke3butler Aug 22 '14 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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