By jeff00seattle on
I am just starting out looking a Drupal code and I want to understand Defined Global Variables using variable_get().
Here is a snippet of code I wish someone could help me understand:
$items = array();
if (variable_get('user_register', 1)) {
$items[] = l(t('Register'), 'user/register', array('title' => t('Create a new user account.'))) .' | ';
}
$items[] = l(t('Forgot Password?'), 'user/password', array('title' => t('Request new password via e-mail.')));
- How can I determine where the persistent variable 'user_register' is set?
For example, is it possible to determine if it is set by:
- another module that needs to be added?
- an administer setting?
- What is the proper Drupal way of setting persistent variables?
- What is happening within this snippet?:
l(t('Register'), 'user/register', array('title' => t('Create a new user account.')))
- Explain:
t('Register') - Explain:
'user/register'
- Explain:
Thanks for tutoring
Comments
Confusing eh?
Hi Jeff,
I was just as confused when I started. I kept looking for the php function |.
The confusion comes here because of 2 Drupal functions that can be very cryptic if you don't know about them - the lowercase "L" and the t function.
Whenever you need to decipher a Drupal function look it up in the Drupal API database
http://api.drupal.org/
3.a. t('register') is a just a string that Drupal can translate into a different language
http://api.drupal.org/api/function/t/6
3.b. 'user/register' is the Drupal path to the New User Registration Page
3. This the link function
http://api.drupal.org/api/function/l/6
http://api.drupal.org/api/function/variable_get/6
Variables can be set via the following function or via the form API
http://api.drupal.org/api/function/variable_set/6
These variables are usually stored in the "variable" table in the database
They usually start with the module name that they are used by
eg user module owns user_register
I am not sure where user_register is stored. It could be a temporary variable related to the session for that user. maybe someone else can shed some light on that.
This snippet works like this (I think. - it is a bit hard with it out of context)
If the user is not registered display the "Register" link and the "Forgot Password?" link
or if user is registered just display the "Forgot Password?" link
Regards
Geoff
Regards
Geoff
How can a Module modify or remove Form attributes?
Thanks Geoff for the reply
My coding question comes from the source of UserLoginBar module, which is defined by Drupal Form user_login_block.
I want to modify UserLoginBar by altering these user_login_block's attributes:
I want only a e-mail/username + password login.
How should I approach this?
Oh, another question, where does the CSS for user_login_block reside, and can I override a base style (of Drupal form) with a created style for a Drupal module?
Thanks
Jeff in Seattle
Various options
Normally the way to alter things is to create a module that uses hook_form_alter to make the required changes to the specific form but that is what this module is already doing. You can add another module to make the changes you want but it can get a bit tricky if the hook_form_alter functions are called in the wrong order.
The main thing is to make changes that are easily maintained in the future when you upgrade. So I would probably rename the whole module and make the changes you want then the next time you need to upgrade you won't overwrite your changes.
Fo now try this.
Sometimes you can hide specific elements with css - visibilty: hidden;
CSS lives in the same folder as the module.
You can over ride any css or do you mean over ride a theme
The book you need is called "Pro Drupal Development" Second Edition by John K. VanDyk. It is excellent. It has everything you need to know.
Regards
Geoff
Regards
Geoff