Hello... I am new to Drupal..
Does anyone have a simple module that extracts some info from a db, and display it in a block?
I tried to do an example from online, and have come across an error as follows:
"Fatal error: Cannot use string offset as an array in {form.inc} on line 680"
Using the following function:
function mymodule_block() {
$block = array ('subject' => t('Title'),
'content' => "This is the content");
return $block;
}
There were other statements in the function, but stripped them off to isolate and fix the error... but even this basic function is causing the error.
This function is being called from a menu as a callback argument
Using Drupal 5.x and PHP 5.2.5
Any help would be appreciated...
Comments
Not sure what you are doing
If you are writing a module that provides a block there is no need for a menu callback, Also I suspect your callback is defined wrong but without seeing your menu hook can not be sure.
But give you want to provide a block, what you need is a block hook and while you have one it is defined incorrectly. See http://api.drupal.org/api/function/hook_block/5 for more information on the hook, At the end of the description is a link to an example of the hook. From your question you only need the cases where $op is 'list' or 'view'.
Thanks nevets..
Thank you for your quick response...
I added the menu call back for quick testing .. by clicking on the menu, rather than modifying the URL.. :)
What I have done is saved a sample module that I found on the net and trying to decipher it, and then modify it to what I need...
The module that i had downloaded was extracting the information for nodes that were created during a specific period, and displaying it.. pretty simple huh? This was not working.. so that is when I started modifying the code to track down the problem..
With the help that you provided, I added the $op... the module works when I have if ($op == 'view') { add stuff to block }.. Because, the $op's value is not 'view'.. it is ''. The module follows:
I added 'My Module's Data' to Primary Links and 'My Module Settings' to Administer
A couple of things
A couple of things.
You can not call a hook_block from a menu callback (at least not easily).
The hook_block function also needs to handle $op == 'list' so it will show in the block admin page (otherwise you can not enable it).
Also regarding this menu entry
You are trying to use 'drupal_get_form' as the callback but it expects a function that produces a form (not general a block) so that is where one of your errors from.
Thank you...
Thank you nevets:
I changed my _block to a function that creates form fields and returns the form, and it is working...
.. now off to control/change the layout (look and feel) of the form... :)
You should be aware you are headed for trouble
You should be aware you are headed for trouble. Functions of the form {module_name}_block() are special, they are used to construct the output for the blocks you see. Though a block can produce a form, it should not do it through s menu callback.
Thanks so much
Thanks once again for that 'eye opening' tip..
I did put back the _block, and within the block, I updated the content with the return value of the function that sets up the form. When the block is enabled, I am able to see the form on my page...
Now I have to add insert/update/reset functionalities for the form.. As a start, I am just getting some data from db, and displaying it..
BTW.. this is my start of a bigger module, which will have google maps enabled, where you can click on the map and have the lat/long etc populated into these form fields ..
Thanks again..
GMap module?
Have you tried looking at the gmap module (http://drupal.org/project/gmap)?
From memory, that already contains a similar feature (setting the lat/lon of a node by clicking on an embedded google map) and integrates with location.module ... you might want to check it out.
t.
Thanks..
Thanks tanoshimi :
I looked at this module.. will need much overhauling to get it do what I want..
Also, I read in one of the threads that someone was suggesting this module be 'removed' because it does not have the proper functionalities..
Not sure if anyone has 'updated' and replaced that module with a better one...