I trying to get the twitter_admin_form and twitter_user_settings form in a div.
/**
* Get twitter form for user
* #param $account
* #type user object
*/
function getTwitterForm($account){
//module_load_include('inc', 'twitter');
module_load_all();
$twitter_form = drupal_get_form('twitter_admin_form');
return $twitter_form;
}
I get a get a drupal error.
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'twitter_admin_form' was given in .../includes/form.inc on line 372.
twitter.module
/**
* Implementation of hook_meu()
*/
function twitter_menu() {
$items = array();
$items['admin/settings/twitter'] = array(
'title' => 'Twitter setup',
'description' => 'Twitter module settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('twitter_admin_form'),
'access arguments' => array('administer site configuration'),
'file' => 'twitter.pages.inc'
);
$items['user/%user_category/edit/twitter'] = array(
'title' => 'Twitter accounts',
'page callback' => 'twitter_user_settings',
'page arguments' => array(1),
'access arguments' => array('add twitter accounts'),
'load arguments' => array('%map', '%index'),
'weight' => 10,
'file' => 'twitter.pages.inc',
'type' => MENU_LOCAL_TASK,
);
return $items;
}
I'm not sure what I'm doing wrong. The twitter_admin_form doesn’t have any arguments hence I thought it would be simple to get and display.
I’m new forms/menu so I’m not 100% sure what %user_category, %map and %index are and how to pass them in.
How do you know what the valid forms are?
When you call drupal_get_form you supply a form id, which is the function that Drupal needs to call. The problem you are experiencing is that Drupal cannot find the function: twitter_admin_form.
Either it's located in an include file, and you need to include it, or you have named it something else.
The error you get stems from the line:
$twitter_form = drupal_get_form('twitter_admin_form');
It expects 'twitter_admin_form' to be a valid callback function, but can't find it. This is probably because the related file 'twitter.pages.inc' is not included at the time of your call.
You could fix that via a:
module_load_include('inc', 'twitter', 'twitter.pages');
(Given the commented line in your code sample, you seem to have tried something like this, but forgot to give the name of the file to include).
Related
I have create module for uploading files into database, and only administrator can upload that files. So I have hook_permission for administer to upload files:
function upload_permission() {
return array(
'administer uploader' => array(
'title' => t('Administer Uploader'),
'description' => t('Allow the following roles to upload files files to the server.'),
),
);
}
Also I create several custom nodes with path files/node/% and now I need permission for anonymous users to see page with custom nodes. Below I add this permission:
'access files/node/%' => array(
'title' => t('Access Files'),
'description' => t('Access Files.'),
),
and still don't work. Is there any other solution how anonymous user can view the page with custom nodes ?
As far I know, just check the permission "view published content" in the CMS permission page that should be checked for the anonymous user role. For viewing a Drupal node no specific permission needed until you are using any individual node permission settings. Also, for your custom node path please use the below settings array in your hook_menu to make all path works with the URL 'files/node/%'.
/**
* Implements hook_menu().
*/
function yourmodule_menu() {
$items = array();
$items['files/node/%'] = array(
'title' => 'Files node',
'page callback' => '_yourmodule_page_callback',
'page arguments' => array(2),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
Just notice the below line of code, this say that anyone with the permission 'access content' (View published content) can see these node.
'access arguments' => array('access content'),
Hope this will help you!
I am trying to learn Drupal. What I want to do is create a backend page (that is on main menu) where I can run my own functions and code. I have been doing research and found out that to do this I need to create a module. And if I run the "hook_menu" function - i can get that backend page to be on the menu. I found code for a drupal module that does this, and it loads a form for a "config settings" page. Here is the code:
function add_game_menu() {
$items = array();
$items['admin/add_game'] = array(
'title' => 'Add Gm Pg',
'description' => 'Description of your add game page',
'page callback' => 'drupal_get_form',
'page arguments' => array('add_game_admin'),
'access arguments' => array('administer add_game settings'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function add_game_admin() {
$form = array();
$form['add_game_maxdisp'] = array(
'#type' => 'textfield',
'#title' => t('Maximum number of links'),
'#default_value' => variable_get('add_game_maxdisp', 3),
'#size' => 2,
'#maxlength' => 2,
'#description' => t("The maximum number of links to display in the block."),
'#required' => TRUE,
);
return system_settings_form($form);
}
I modified it a little but it does work. What I want to do is do this but run my own functions and code on here and not the "drupal_get_form" function.
I tried to do this and just created a function to echo text and then put the function name in the "page callback" field of the array. This did work, it did execute my function on the page instead of the drupal form function, but the page was a blank white page with none of the "drupal backend styling or menus or anything"; it was literally just completely blank white webpage with just my text printed on it.
So I am thinking the "drupal_get_form" function not only puts a form on the page, but it also makes it so it is drupal backend page with proper header, footer, menus etc.
So I am thinking that i need a function like "drupal_get_form" but it has a "blank slate" where I can run whatever code or functions that I want.
Would anybody know anything about this or how to approach doing this?
Thanks so much...
Everything you need is to create a template, register it and use theme function in your code. You can take a look at this Quick Introduction to Drupal's hook_menu() and hook_theme()
So your code might look like:
function add_game_menu() {
$items = array();
$items['admin/add_game'] = array(
'title' => 'Add Gm Pg',
'description' => 'Description of your add game page',
'page callback' => 'my_function',
'access arguments' => array('administer add_game settings'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function my_function(){
// Call theme() function, so that Drupal includes the custom-page.tpl.php template
return theme('my_custom_template');
}
/*
* Implementation of hook_theme().
*/
function add_game_theme(){
return array(
'my_custom_template' => array(
// template file name will be custom-page.tpl.php
'template' => 'custom-page',
),
);
}
We use a module in our projekt named "certificate". There is one Function in the *.module file which contains this:
function certificate_menu() {
$items['node/%node/certificate'] = array(
'title' => 'Certificate',
'description' => 'Display earned certificate for this node',
'page callback' => 'certificate_node_certificate',
'page arguments' => array(1),
'access callback' => 'certificate_can_access_certificate',
'access arguments' => array(1),
'file' => 'certificate.pages.inc',
'type' => MENU_LOCAL_TASK,
);
}
There is a "certificate_can_access_certificate" callback to check if the User has Access to download a certificate.
Whan I now try is to make a redirect to page "/my/another/access/denied/page/for/certificate" when this callback returns false.
What is now the recommended way to solve this ?
1) Manipulate the callback function and everytime when its returned "False" I just write an exit; there and redirect before with location() ?
2) Is there a way to create a function in my own custom module to make this redirect possible ?
3) Do I have to manipulate the function certificate_menu() in a special way ?
I do not know much about Drupal so I dont know whats the best way to do and how I have to do this ...
You can use "drupal_goto" function within your access callback to redirect.
Here's an example, where if you add ?doredirect=true it will redirect from the access function.
function certificate_menu() {
$items['mytestpage'] = array(
'title' => 'Certificate',
'description' => 'Display earned certificate for this node',
'page callback' => 'certificate_testpage',
'access callback' => 'certificate_access',
);
return $items;
}
function certificate_testpage() {
return 'testing!';
}
function certificate_access() {
if(isset($_GET['doredirect'])) {
drupal_goto('', array(), 301);
}
return 1;
}
Also, please note, you need to return $items within your hook_menu, otherwise your page callback won't register.
I want to send a parameter to my function with drupal_get_form() in the menu item, but not works and wrong values send i don't have any idea about this error.
First i call the menu item from this line in onther file:
drupal_goto( 'a/b/c/d/'.$form_state['values']['number']);
here is my menu item code in a different file:
$items['a/b/c/d/%'] = array(
'title' =>t('report'),
'description' => 'my report',
'page callback' => 'drupal_get_form',
'page arguments' => array('make_report',1),
'access callback' => 'user_access',
'access arguments' => array('admin'),
'file' => 'report_file.inc',
);
and this is my function header in report_file.inc:
function make_report(&$form_state,$back=0){
.
.
this is the variable dump of $form_state:
storage (NULL)
submitted (Boolean) FALSE
post (Array, 0 elements)
this is the variable dump of $back:
b
i want the $back pass '1' but it get the second level of my url.
I have a page that is definitely not a form but I need to use some callback functions to load data from an external source and display (e.g. a list of buildings on campus and their accessibility information).
What I have a need for is a landing listing page (lists all the buildings) and a 'view individual building' page. Also, I have a page where you punch in your student ID and view information on testing procedures. And finally I have a page that is basically a form (which I have done before successfully in the past).
Now, I HAD the building list working, however I made a small change and it stopped working!
Currently my hook_menu() function looks as below:
<?php
/**
* Implementation of hook_menu()
*/
function disability_menu()
{
$items = array();
// Ignore me, shell
$items['quickreg'] = array(
'title' => 'Quick Registration',
'description' => t(''),
'page callback' => 'drupal_get_form',
'page arguments' => array(),
'file' => 'disability.quickreg.view.inc',
'access arguments' => array('access quick registration system'),
'type' => MENU_SUGGESTED_ITEM,
);
$items['tests/status'] = array(
'title' => 'Test Status Results',
'description' => t('Check on the status of your tests'),
'page callback' => 'disability_view_testing_status',
'page arguments' => array(),
'file' => 'disability.tests.view.inc',
'access arguments' => array('access test check information'),
'type' => MENU_CALLBACK,
);
$items['tests'] = array(
'title' => 'Testing Services',
'description' => t('Check on the status of your tests'),
'page callback' => 'disability_view_testing',
'page arguments' => array(),
'file' => 'disability.tests.view.inc',
'access arguments' => array('access test check information'),
'type' => MENU_SUGGESTED_ITEM,
);
$items['access/%building'] = array(
'title' => 'Campus Accessibility Guide',
'description' => t('A summary list of detailed accessibliity information about each building on the A&M campus'),
'page callback' => 'disability_view_access',
'page arguments' => array(1),
'file' => 'disability.access.view.inc',
'access arguments' => array('access building access information'),
'type' => MENU_SUGGESTED_ITEM,
);
return $items;
}
Before some change I must have made the menu item for "Campus Accessibility Guide" would show up properly (after being enabled of course). The /access url would work correctly displaying a list of all building and the /access/12345 would correctly display the single record of ID# 12345.
Now the access/%building menu entry is not even showing up and even sending the url /access into a redirect loop (making me think it's passing in something for the ID which sends it into the view specific function that redirects to /access when the ID doesn't exist).
Can anyone tell me what I'm doing wrong or what I need to do to support 2 themed pages: a /access and /access/%building url pattern?
You should only use %name instead of % in urls when you have a function that you want to act on the url. Drupal does this all over the place with user and node, and this is very smart, as you only one place need to have the code to load an user or a node, but it get used in a lot of places. In this case I bet it's a bit overkill to make a function to load the building. On the other hand the advantage is that doing it that way, you get the 404 handling, if no object can be found. The best solution really comes down to how you want to handle buildings that does not exist. You could even make your 'Campus Accessibility Guide' function handle the 404 which would make the two options more or less equal. I would go for whatever is easiest for you to make.