# Question
Title: URL alias not working in Contextual filters using node reference field
I have a node reference field in views contextual filter and need to filter the list of contents. Url path in views like "node/%/foo " working for me, but the node alias like "/alias/foo" not returning any results . Anyone please suggest for this.

# Answer
> 0 votes
"node/%" is a system path, not an alias. When you use the path "node/%/foo", Drupal looks for an alias of "node/%/foo", and doesn't find one. Next, Drupal will "bubble" your request up to the system menu handler at "node/%" with the path argument of "foo".

When you use the path "alias/foo", Drupal looks for an alias of "alias/foo" but doesn't find one. Drupal *does not* bubble up your request to "alias".

This is a long-winded way of saying that if you want an alias like "alias/foo", you need to add it yourself. There are many ways to do this, e.g. use rules.

---
Tags: views
---


# Question
Title: How to get "Add another item" option for fields based on taxonomy terms
The goal is to allow an autocomplete field that uses taxonomy terms, and which allows multiple entries from the same taxonomy list – for example a list of names & contact info for a field that allows "add all that apply." This works for a text field configured for autocomplete and "unlimited" values. It also works when the source is the User list. However with taxonomy term lists, the "unlimited values" choice does not produce the usual "add another item" option. **Is there a way to resolve this?** *(We want to be able to draw from a taxonomy list, to avoid inconsistencies in how a user might enter names and contact info.)*

# Answer
> 1 votes
Problem solved by installation of the Taxonomy Single Tag module and the patch from #6 of this thread. Answer provided by "Poieo" on drupal.org. I have applied this and it is working as desired. However I noticed that without the patch, I was getting errors not only with the new field where the "Single tag autocomplete text field" widget was applied, but also with other fields allowing multiple-item adding – even though they were neither autocomplete nor based on taxonomy terms.

---
Tags: entities
---


# Question
Title: How do I create a redirect after using pathauto_node_update_alias()
I am using the Redirect module. I have a feature, where I have an update hook, that updates (and fixes) the path alias of the nodes on the site (after I made a change to the pathauto pattern). I need to create a redirect, as updating the path alias does not do this for you when you use `pathauto_node_update_alias()`. How do I go about this. Below is the code I have:

```
function uw_cfg_redirect_update_7010(&$sandbox) {
  $query = "SELECT nid FROM {node} where status = 1";

  // If this is the first pass through this update function then set some variables.
  if (!isset($sandbox['total'])) {
    $result = db_query($query);
    $sandbox['total'] = $result->rowCount();
    $sandbox['current'] = 0;
  }

  // How many nodes should be processed per pass. The higher this number is, the faster your update will
  // complete, but the more likely your server will run out of memory or timeout.
  $nodes_per_pass = 50;

  // Get the nodes to process during this pass.
  $result = db_query_range($query, $sandbox['current'], $nodes_per_pass);
  while ($row = $result->fetchAssoc()) {
    $node = node_load($row['nid']);
    pathauto_node_update_alias($node);

    // TODO: [need to add redirect code here]

    // Increment "current" by 1.
    $sandbox['current']++;
  }

  // Set the value for finished. If current == total then finished will be 1, signifying we are done.
  // If not then this function will be trigger again.  See Drupal Batch API for more details.
  $sandbox['#finished'] = ($sandbox['current'] / $sandbox['total']);

  if ($sandbox['#finished'] === 1) {
    drupal_set_message(t('We processed @nodes nodes. DONE!!!', array('@nodes' => $sandbox['total'])));
    return t('Finish rewrite the path of all the nodes.');
  }

  return $sandbox;
}

```

Note: This is not a problem if you use Global Redirect module. This is not a problem when you resave a node, as redirect gets added.

# Answer
I'd have a look at redirect\_path\_update and hook\_path\_update and maybe consider using node\_save() instead of writing the paths directly.

If you're going to write them directly with pathauto\_node\_update\_alias(), you may as well just write paths aliases and redirects directly to the database instead of wasting time node\_load()ing all the nodes.
> 0 votes

---
Tags: redirection, path-aliases, batch-operations
---


# Question
Title: Multi-sites local dev alias question for Drupal 6 / OS X
With Drupal 7, it's fairly trivial to set up a local alias for a multi-site using the `sites.php` file. With Drupal 7, I can have a multi-site folder on my local dev be named:

```
subsite.com

```

... located in the `/sites/` folder

so that it's: `/sites/subsite.com/`

Then in my sites.php file, I do something like this:

```
$sites['subsite.dev'] = 'subsite.com';

```

... but I can still view this local site in my browser as:

```
http://subsite.dev

```

This is good on many levels, it allows me to have a custom subsite (of a multi-site) as the actual name it will be on the remote server. Thus I can have custom modules and themes for the subsite in my Git repo. In addtion, if I clone the remote db back to local at any given point, any given site specific references do not need to be changed in the local DB.

The question then, is there any way to have similar local aliasing with Drupal 6. I know Drupal 6 does not have the sites.php file so I am not sure how else to do this. Becuase of this, right now I am stuck with rendering my local Drupal 6 multi-site folder as `subsite.dev`. I know I could chnage my "hosts" file in OS X but then I am stuck having to change it all the time to view the actual ".com" remote domain.

# Answer
> 2 votes
Seems like what you want could be accomplished by creating a symbolic link in the sites directory. Linking to subsite.com by the name subsite.dev would do it:

```
$ cd [sites-directory]
$ ln -s subsite.com subsite.dev

```

Mind you, you might need to change the `$conf['cookie_domain']` and `$conf['base_url']` values in the `settings.php` file if you want to be able to log in to your local dev site.

# Answer
> 0 votes
Hi you can look at the "Aliased multi-site support" There are some patches.

---
Tags: 6, multi-sites
---


# Question
Title: Create Node and related Node at the same time?
I have a content-type (Recipe) that is created by anonymous users and can be rated/reviewed with another content-type (Review).

Users should be able to write a Recipe and a Review related to that Recipe at the same time on the same Page. I think I'm searching for the wrong things but I can't find a solution for this Problem without the need to write a new module.

Thanks in advance.

# Answer
> 0 votes
The Inline Entity Form module will get you that functionality (assuming your reference field is provided by the Entity Reference module).

> Provides a widget for inline management (creation, modification, removal) of referenced entities.
>
> The primary use case is the parent -\> children one (product display -\> products, order -\> line items, etc.), where the child entities are never managed outside the parent form.
>
> Existing entities can also be referenced.

# Answer
> 0 votes
See also references\_dialog:

> This module extends reference fields like the user and node reference fields by adding links to add, edit and search for references through a dialog.

---
Tags: 7, forms, nodes
---


# Question
Title: Drupal 7 Fields, when adding an existing field during content type creation, how to tell where else its used?
I just realized that if you use an existing field that is used in another content type and you change the field settings, you end up changing it on the other content types that share the same field. Is there a way to tell where else an existing field is being used?

Example: I have a field called "field\_image" and using it in my basic page content type. Now I use it for my blog content type. How can I tell my basic page content type was using that same field?

# Answer
Yes that information is easily accessible on the `/admin/reports/fields` page. It looks like this:

The first column is the field name, second is the field type, and the third is a list of bundles the field is currently attached to (with links to manage the fields).
> 1 votes

# Answer
~~There's no UI for this anymore.~~ The UI is in admin/reports/fields (h/t Clive)

Here's a good stack about how to find this info with drush: Is there a listing of Drupal fields?

Or you can grab it from the database:

```
SELECT entity_type, bundle FROM field_config_instance WHERE field_name = '$MY_FIELDNAME'

```
> 1 votes

---
Tags: 7, entities
---


# Question
Title: Formatting looks OK in input field using CKEditor but does not appear on page when published
Formatting looks OK in input field using CKEditor but does not appear on page when published?

CKEditor is installed and working OK but the formatting is not applied to the published text

anything obvious I might be missing ?

# Answer
If CKEditor is applying the styles correctly but the *display* of these styles is not showing up after a save, I think you may need to check out the '**Text format**' you're using for that CKEditor profile. It should appear directly under the CKEditor in a drop-down.

After you see which text format you're using, check the configurations of that particular text format here: `<your site>/admin/config/content/formats`.

Make sure, when you check the settings, that the '**Limit allowed HTML tags**' checkbox isn't checked, which may not allow certain html tags to be displayed. Look through all the options there and make sure there isn't something else that could be messing up your display.

Let us know if text formats end up being the issue.
> 2 votes

---
Tags: wysiwyg
---


# Question
Title: How to display a list of products in same taxonomy as current product?
I want to display a list of other products from the currently-viewed product's taxonomy/taxonomies on the product page. It would ideally be a text-only list, and would be limited to five or ten products. I'd rather not go the route of node/entity reference fields, as I have hundreds of products. Yes, it would be more accurate to do it that way, but displaying products based on their taxonomy would be accurate enough for my purposes.

Can anyone tell me how to set up something like this? Perhaps with Views?

Thanks!

# Answer
> 1 votes
After a bit more digging, I came across a wonderful solution: http://scito.ch/content/show-related-nodes-block-based-taxonomy-terms-views-3-and-drupal-7

1. Create view (block)
2. Add fields (title, a small image, date, whatever you like). Or teasers, what works as well.
3. “Arguments” is from now on called “Contextual filters”, so go there.
4. Add the filters: “Content: Has taxonomy term ID (with depth)” and “Content: Has taxonomy term ID depth modifier”
5. Configuration on this filter: → When the filter value is NOT in the URL: → Provide default value → Type: Taxonomy Term ID from URL → under that, check the box “Load default filter from node page, that’s good for related taxonomy blocks.” → now check the boxes of the taxonomies you want involved here
6. Now you need to add the second filter in order to exclude the current node from the list. Click \[+\] button of the contextual filters section.
7. Select Content: Nid
8. Set the ‘when argument is not present’ to ‘Provide default argument’
9. Set the ‘Default argument type’ to ‘Content ID from URL’
10. Go to “MORE” , and check the “Exclude” box.
11. Move the filter “Content: Nid” to the top position.
12. Add a block to your view and embed the block on your node pages
13. Save your view

# Answer
> 0 votes
I think Views will work good for the task.

The setup could be: Content type \- product content type \- field for taxonomy term information /single, multiple, etc./

Views \- filtering content /not taxonomies/ \- contextual filter by taxonomy term of node id from url \- there is a checkbox to take information from the node, useful option \- add the filter one more time, select current node id from url, and exclude, this would exclude the currently viewed product from the list of relevant products

I think this would be good enough, but if not, check this comparison https://drupal.org/node/323329 for ready to use solutions

---
Tags: 7, views, taxonomy-terms, ubercart
---


# Question
Title: Where to save larger module content/settings?
I'm creating blocks in modules and wish to have the block body (content) editable by admins. I'm using `hook_block_configure` and `hook_block_save` to accomplish this. Where is a good place to store the block body when edited by the admin (`variable` is apparently not suitable for larger values like this)?

I was thinking of just creating a custom table in `hook_schema` but that seems a lot for just one or two rows of data. Plus I would be doing this for several modules that need to provide blocks but also have their content editable by the admin. That's why it would be nice if there was a general storage table like `variable` but for larger values.

What would be a better way to accomplish this?

# Answer
Have you looked at Nodeblock?

There is not a general storage table like `variable` for larger values.

I would consider creating a content type; using the nodes from that content type to programmatically create the blocks, using taxonomy to get finer control if necessary; then admins can just edit the block content like they would a node.
> 0 votes

---
Tags: 7, blocks
---


# Question
Title: Printing out path from views - /drupal/ appears twice
I'm using this to print out a custom link format in views. I'm using it in the unformatted views tpl.php file.

```
<?php print l('<span class="link-spanner"> a</span>',
              $view->style_plugin->row_tokens[$id]['[path]'],
              array ('html' => TRUE)); ?>

```

This line calls the relevant HTML path:

```
$view->style_plugin->row_tokens[$id]['[path]']

```

For example it might contain the value: localhost/drupal/node/31.

But when I put it in the l() function I get localhost/drupal//drupal/node/31.

Anyone know how I can stop the double print out? This is driving me mad.

# Answer
```
<?php print l('<span class="link-spanner"></span>',
'node/' . $view->result[$id]->_field_data['nid']['entity']->vid,
array ('html' => TRUE)); ?>

```

Here is the final solution.

It will add the NID on the end of node/ and create the internal path "node/x". If you're using Pathauto this will still work.
> 1 votes

---
Tags: 7, views, uri
---


# Question
Title: Unable to Install/Uninstall a custom module
I am new to Drupal development and was working on a module. It has since gotten entirely screwed up. This is in Drupal 7. The module was adding a field type with a widget and some theming. It also created several new tables.

My module does not show up in the module list, and it does not show up in the uninstall list either. I see that it is still listed in the system table, and I had manually disabled it there (and did the clearing in the cache\_bootstrap table). I removed the entire module folder at one point and have tried with it there and not there, clearing cache at each step.

Though I could live with the module still being "in the system", I would greatly prefer not to. I also have the major problem of I can not create a module with that name anymore as adding in a folder (even with a new, much simpler codebase for the module) does not make it show up in the list. To make matters worse this is a group project so it is not as if I could just start with a clean install of Drupal and start over.

So I am curious how I could remove the existing module so that I am able to "start over" with my own module?

Thanks!

# Answer
> 2 votes
You should pay close attention to the Module developer's guide on Drupal.org.

To appear in the lists, the module should be placed in its own sub-directory like `modules/modulename`, and it must have a properly configured `modulename.info` file in addition to a file named `modulename.module`.

If you have properly segregated the functions into the proper files, there should be no problem. Drupal will detect them automatically and will maintain an entry in the *system* table for the module. You should be able to activate or deactivate the module normally.

The installation routines (which are used to create or to remove the tables should be handled by functions in a `modulename.install` file. Drupal will look for the modulename.install file to see what tasks are required for installation or removal of the module.

My first advice would be to make sure that the module is correctly structured, and let Drupal handle the deactivation and uninstall, but you can do it manually if all else fails.

Deactivate the module and drop the tables using queries directly on the database. Start by looking for the definition in the *system* table.

```
UPDATE system SET status=0 WHERE type='module' AND name = 'modulename';

```

Then manually DROP any tables your module created and remove any variables it created.

---
Tags: 7
---


title: Embed Google Map

text:
# Question
Title: Embed Google Map
When I generate the map and paste it on the site, it shows me only the "View Larger Map" link.

How can I embed Google Map into my Drupal 7 site?

# Answer
Seems that your text gets filtered. Are you trying to embed the given by the google maps web? If that it's the case, check that the text-format of your node is 'full html'.

You can also take a look into the OpenLayers module to add maps into nodes:

> http://drupal.org/project/openlayers
> 4 votes

# Answer
if you want google maps you can use this module: http://drupal.org/project/gmap. There is also a great screen cast that shows how to use it: http://www.drupaltherapy.com/gmap
> 0 votes

# Answer
For a single map at a brochure site try the simple Location Map Module.
> 0 votes

# Answer
Drupal doesn't seem to render iFrame code correctly. You can embed a Google Map by using an object tag instead of iFrame. Example:

```
<object id="map" type="text/html" data="http://maps.google.com/maps?f=q&source=..." style="width:450px;height:300px;">

```
> 0 votes

---
Tags: 7, google-maps
---


# Question
Title: Views- Show a table of users with each column indicating whether or not a user has a role
I am using Views Data Export to get data on my Drupal users into Excel. My site has a large number of roles (Roles A - Z), and some of these are important for user statistics.

The view I use for data export is a table of fields. I added **Roles** as follows:

This gives me something like *RoleA, RoleC, RoleD, RoleI* for each user. This sort of data is difficult to manipulate in Excel.

**What I would like to do instead is to have a column in the table for each important role that has 1 if the user has the role, or 0 if the user does not have the role.**

In other words, my table looks like this now:

But I want it to look like this in Views:

# Answer
> 6 votes
Here's a solution using a simple module and a custom field template.

## Overview

The view (obviously of the User Table) should only contain one field: `User: Name`. All of the other Role columns are generated by implementing HOOK\_views\_pre\_view() with a loop for each defined role. The module also defines a custom function that compares the original output (comma-separated list of roles) and returns true if the list contains the current column's role.

The custom views field template simply calls the custom function for each column that corresponds to a role.

This solution will automatically scale if you add/delete roles and adjust if you rename/reorder roles etc.

## Module File

You'll obviously need an info file too. I chose to name the module `views_urt` (User Role Table) - but you can name it whatever you want or include these functions in an existing custom module if you choose.

```
<?php
/**
 * Implements HOOK_views_pre_view().
 *
 * Adds a field to the User Roles view for each role defined.
 */
function views_urt_views_pre_view(&$view) {
  if ($view->name == 'user_roles') {
    $roles = views_urt_roles();
    $count = count($roles);
    for($i=0;$i<$count;$i++) {
      $view->display['default']->handler->options['fields']['rid_' . $i]['id'] = 'rid_' . $i;
      $view->display['default']->handler->options['fields']['rid_' . $i]['table'] = 'users_roles';
      $view->display['default']->handler->options['fields']['rid_' . $i]['field'] = 'rid';
      $view->display['default']->handler->options['fields']['rid_' . $i]['label'] = $roles[$i];

    }
  }
}

/**
 * Determines if a comma-seperated list of roles contains the role of the
 * current column.
 *
 * @param $pos integer
 *   The column corresponding to the $field->position value in the view.
 * @param $user_roles string
 *   Comma seperated list of Roles (haystack)
 * @return bool
 */
function views_urt_has_role($pos, $user_roles) {
  $pos = ($pos -1);
  $user_roles = explode(',', $user_roles);
  $defined_roles = views_urt_roles();
  foreach ($user_roles as $user_role) {
    if (trim($user_role) == $defined_roles[$pos]) {
      return TRUE;
    }
  }
  return FALSE;
}

/**
 * Helper function that returns an array of roles exluding "Anonymous" and
 * "Authenticated" user.
 *
 * @return array
 *   An array of roles.
 */
function views_urt_roles() {
  $roles = user_roles();
  array_shift($roles);
  array_shift($roles);
  return $roles;
}

```

## Views Field Template File

This template should be picked up by all of the fields in this view for all of the displays. So, since my view is named `user_roles`, this template is named `views-view-field--user-roles.tpl.php`.

```
<?php
if ($field->field_alias == 'users_name') {
  print $output;
}
else {
  // We're assuming that this view only has one field (User: Name). All other
  // fields are generated by the HOOK_views_pre_view() function in the
  // `views_urt.module` and those should be passed through the
  // `views_urt_has_role` function which determines if the $output
  // (comma-seperated roles per user) contains the column role.
  print views_urt_has_role($field->position, $output);
}
?>

```

## Sample Output

# Answer
> 2 votes
I think another option is to build a custom view mode. You can implement hook\_entity\_info\_alter:

```
function MYMODULE_entity_info_alter(&$entity_info) {
     $entity_info['user']['view modes']['VIEW_MODE_NAME'] = array(
        'label' => t('Display user relation to existing roles'),
        'custom settings' => TRUE,
      );
    }

```

Then you can attach your theme function:

```
function MYMODULE__view($entity, $type, $view_mode, $langcode){
  if ($enitity == 'user' && $view_mode == 'VIEW_MODE_NAME') {
   // add some additional variables for template
    $node->content['#theme'] = 'VIEW_MODE_NAME_view';
  }
}

```

and in your theme function VIEW\_MODE\_NAME\_view:

```
   function  VIEW_MODE_NAME_view_theme(){
     // get all role and display the entity and
     //its roles the way you described
    }

```

Once you have your view mode working you can use it in views (any view) as well as any other place where the entity is rendered.

---
Tags: views
---


# Question
Title: Show a Custom Block on Homepage in Drupal 6
I am trying to show a simple block on my home page in Drupal 6.

The Drupal has simple HTML Text.

My question is that how can I show it in my code in let's say Page.TPL.PHP

I searched Internet and tried this:-

```
 if (drupal_is_front_page()) {

      // $block = block_load('block',314);
      // $output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
      // print $output;

      $block = module_invoke('user', 'block', 'view', '314');
      print $block['content'];

```

The block num is 314 but other than that I am not sure that what user, block or view means in the function. I want to show it on the home page, hence I put it in a condition.

Do I have to leave it disabled or should I enable it in some region so that it can be shown on the Home Page?

Thanksa lot.

# Answer
If you have a suitable region to display the block, why not set it to display in that region and in the Block *Visibility settings* configuration under *Show block on specific pages* select *Only the listed pages*. Then in the text area type `<front>` to display it only on the front page.
> 0 votes

---
Tags: blocks
---


# Question
Title: Drupal 7 : i want to add the registration fields (username/e-mail etc) to a profile 2 registration form
i am relatively new to drupal. So, here is my question :

I have more profile2 types, assigned as roles (doctors/patients/partners etc). Each role has it's own registration form, shown at registration page, alongside with the obligatory fields of the registration (username, password, e-mail, etc...). For each role there is a unique registration path. The problem is that i want the registration form to be a multistep sort of "registration wizard". I have accomplished that with the multistep and field group modules, but this applies ONLY to the profile2 registration form. In other words, as the steps for the profile2 registration form go forward, the obligatory fields for registration remain at their position, below the form. I would like to integrate them as a step (the first one) of my multistep wizard. Any solutions???

# Answer
> 1 votes
I have achieved the above with a similar setup to yourself.

You state you have used 'registration wizard', so I assume you have created custom forms for the profile2 fields. Furthermore, you are validating and submitting the values at the end.

The simplest method is to create a custom form at the beginning of your process for username, email, password, etc. Then using the user\_save() function. Of course you will need to ensure current users don't exist already, which is easy enough using user\_validate\_mail().

Hope this help. Amarjit

---
Tags: forms, users
---


# Question
Title: Adding class to the webform submit button
By default, the web form is displayed with `<?php print drupal_render($form['submitted']); ?>` .

I need to make a small edit and add `class="btn"` to the `submit` button.

I can change its value with `$form['actions']['submit']['#value'] = "click to become a member";`

But I couldnt find a way to add the class.

Please help!

Thank you

# Answer
> 0 votes
I think that you have to do something like this (add an array):

```
$form['actions']['submit']['#value'] = "click to become a member", array('attributes' => array('class' => array('btn'), 'style' => array('CUSTOM STYLE DIRECTLY') ));

```

I'm not really sure if is there is the right place the you have to add that code, but that generally it's this code:

```
, array('attributes' => array('class' => array('btn'), 'style' => array('CUSTOM STYLE DIRECTLY') ))

```

---
Tags: 7, webforms
---


# Question
Title: How to Change "USER has no blog entries" Text
When you click on a user's blogs link and there are none he message "USER has no blog entries." comes up. I want to change that. I have tried using string overrides within settings.php but it does not seem to work. I used !username for the user as it is a link but nothing.

# Answer
> 1 votes
You have to isolate first exactly where this text is coming from. From your description, it sounds like you're using the core blog module which has this line here:

https://api.drupal.org/api/drupal/modules%21blog%21blog.pages.inc/function/blog\_page\_user/7

```
else {
  drupal_set_message(t('!author has not created any blog entries.', array('!author' => theme('username', array('account' => $account)))));
}

```

So the correct string you want to use (and what your string override in settings.php will be looking for) is

```
!author has not created any blog entries.

```

Using the string overrides module or your settings file, its easy then to change this text to whatever your like

---
Tags: string-overrides
---


# Question
Title: How to create custom menus with different path
I want to create custom menus.

I created **dashboard** named menu, now i want to provide links under dashboard menu,

i created one link named myprofile.

and it is asking for path. i want to link it with user edit page who is logged in.

I have no idea regarding this.

Does anybody have idea regarding this.

Thanks

# Answer
If you want to give user view page then this :

1) You need to give path as `user`. That will take you to the currently logged-in user account.

Or if you want go to view edit page:

2) You can use menu token module to give path as user edit page.You can use the token replacements to get to the user edit page.Hope this helps you.

3) You can use user/\[current-user:uid\]/edit once you have the menu\_token module installed.But i dont know why its not working.

You can try installing me aliases module and give path as `user/me/edit`. This will give option for editing user account.Hope this resolves your current issue.
> 2 votes

---
Tags: views, 7
---


# Question
Title: Override _user_mail_notify() to NOT send email on user_save() if user status is changed
I have an external service registering and altering the status of Drupal users, performing user\_save() on several occasions depending on the service response. So i am blocking and unblockiing users and other operations.

My problem is i cant find a descent way to override this code inside user\_save()

```
// Send emails after we have the new user object.
if ($account->status != $account->original->status) {
 // The user's status is changing; conditionally send notification email.
 $op = $account->status == 1 ? 'status_activated' : 'status_blocked';
 _user_mail_notify($op, $account);
}

```

ideally i would like to have full control on what is going to be sent depending on user role, the account status etc. say for example

```
// pseudo code
if (user_is_external and statusChanged){
  dont send email
} else {
  send_email
}

```

Is this possible? thanks

# Answer
> 3 votes
Maybe you should take a look at `drupal_mail` function

```
// Invoke hook_mail_alter() to allow all modules to alter the resulting e-mail.
drupal_alter('mail', $message);

// The original caller requested sending. Sending was canceled by one or
// more hook_mail_alter() implementations. We set 'result' to NULL, because
// FALSE indicates an error in sending.
if (empty($message['send'])) {
  $message['result'] = NULL;
}

```

Then `hook_mail_alter`

From description

> **$message:** An array containing the message data. Keys in this array include:
>
> **'send':** Set to FALSE to abort sending this email message.
>
> **'params':** An array of optional parameters supplied by the caller of drupal\_mail() that is used to build the message before `hook_mail_alter()` is invoked.

Parameters usually contain $message\['params'\]\['account'\], so you can abort e-mail sending by role or other way.

Example (not tested) aborting any e-mail to account with specific role:

```
function MY_MODULE_mail_alter(&$message) {
  $role = 'CUSTOM_ROLE';
  if (!isset($message['params']['account'])) return;
  $account = $message['params']['account'];
  if (is_array($account->roles) && in_array($role, array_values($account->roles))) {
    $message['send'] = NULL;
  }
}

```

There is an issue then sending custom e-mails, $account contain sender account object, not receiver. But for default notifications this should work. So don't forget to check $message\['key'\] for default notification types from \_user\_mail\_notify, it always provide $account object mail is sending to:

```
'register_admin_created': Welcome message for user created by the admin.
'register_no_approval_required': Welcome message when user self-registers.
'register_pending_approval': Welcome message, user pending admin approval.
'password_reset': Password recovery request.
'status_activated': Account activated.
'status_blocked': Account blocked.
'cancel_confirm': Account cancellation request.
'status_canceled': Account canceled.

```

# Answer
> 1 votes
The decision not to send email is Not made in the user\_save function but rather in \_user\_mail\_notify(). That function checks the variables table.

The only way I see for you to acquire this control (without hacking core) is for you to disable all related user email for the core email functions, and to write your own module using hook\_user\_insert and hook\_user\_update.

---
Tags: 7, database, users
---


title: Adding a title to a ul in the menus

text:
# Question
Title: Adding a title to a ul in the menus
I need to create the following to a menu system in drupal 7. I want to be able to create a href that is not connected to a content type. Is this possible?

```
<ul>
  <li>link</li>
 <li>link </li>
 <li>
<ul><a href ='#' class="dropdown">I need this link to not be attached to a content type</a>
    <li>link</li>
    <li>link</li>
   </ul>
  </li>
</ul>

```

# Answer
> 0 votes
try this module "Nice Menus" and this "Menu Attributes".

You can follow these tutorials for more informations: http://codekarate.com/daily-dose-of-drupal/drupal-7-menu-attributes-module http://codekarate.com/daily-dose-of-drupal/drupal-7-nice-menus-module

I hope it helps you out. Thank you

# Answer
> 0 votes
I used the following to fix this issue,

**special\_menu\_items module** This allows me to nolink so I could create a href="#"

**menu\_attributes module** To add an id

---
Tags: 7, routes
---


# Question
Title: How do I remove default comment validation in drupal 7?
Drupal is showing error message for empty comments by default. how can i remove that error message. Note:- (I have not written any custom validation. It's the default validation provided by drupal module.) My changes in comment.module

```
if (empty($comment->cid) && empty($comment->pid)) {
if(($form['#node']->type=='iks_videos_youtube_video') || ($form['#node']-               >type=='iks_videos_vimeo_video' || $form['#node']->type=='iks_videos_video')){
if(isset($form['#node']->type) && $form['#node']->type=='iks_videos_youtube_video')
{   $vtype='yt';}
else
{   $vtype='v'; }
$form['#action'] = url('video/' . $form['#node']->video_id[LANGUAGE_NONE][0]['value'] . '/'.$vtype.'/' . strtolower(str_replace(' ', '_', $form['#node']->title)));
  }else{
$form['#action'] = url('comment/reply/' . $comment->nid);}

```

}

my custom module code

```
function  iks_videos_form_comment_node_iks_videos_youtube_video_form_alter(&$form, $form_estate) {
if (isset($form['actions']['preview']))
unset($form['actions']['preview']);
$form['subject']['#access'] = FALSE;
unset($form['author']['mail']['#description']);
$form['#submit'][] = '_iks_videos_comment_form_submit';
    }

```

alter form

```
function _iks_videos_comment_form_submit($form, &$form_estate) {

if(($form['#node']->type) && $form['#node']->type=='iks_videos_youtube_video')
    $vtype='yt';
else
    $vtype='v';
$form_estate['redirect'][0] = 'video/' . $form['#node']->video_id[LANGUAGE_NONE][0]['value'] . '/'.$vtype.'/' . strtolower(str_replace(' ', '_', $form['#node']->title));

```

}

# Answer
> 1 votes
You can see error message because comment\_body is required for comment entity. You can delete `#required` parameter for `comment_body`:

```
function my_module_form_alter(&$form, &$form_state, $form_id) {
  if(strpos($form_id, 'comment_node_erpal_task_form') !== FALSE) {
    $form['comment_body'][LANGUAGE_NONE][0]['#required'] = FALSE;
  }
}

```

But just know that you'll have php notice then. Because posting comment without the body is not right:

> Notice: Undefined offset: 0 in comment\_submit() (line 2197 of W:\home\erpal.local\www\modules\comment\comment.module).

Make sure yhat you added custom validation for body field.

You you can handle validation callbacks for the whole form in `$form['#validate']` array. Also you can handle validation callbacks for each form element in `#element_validate` array. E.g. for comment\_body:

```
$form['comment_body'][LANGUAGE_NONE]['#element_validate'][] = '_my_module_comment_body_validate';

```

**Update**

You musn't change any code in Drupal core modules, it's very bad hardcode. You can do all your logic that you added to comment.module in hook\_form\_alter.

```
function my_module_form_alter(&$form, &$form_state, $form_id) {
  if(strpos($form_id, 'comment_node_erpal_task_form') !== FALSE) {
    $form['comment_body'][LANGUAGE_NONE][0]['#required'] = FALSE;

    if(isset($form['#node']->type) && $form['#node']->type=='iks_videos_youtube_video') {
      $vtype='yt';
    }
    else {
      $vtype='v';
    }

    $url = url('video/' . $form['#node']->video_id[LANGUAGE_NONE][0]['value'] . '/'.$vtype.'/' . strtolower(str_replace(' ', '_', $form['#node']->title)));
    $form['#action'] =  $url;
  }
}

```

---
Tags: 7, comments, forms
---


# Question
Title: Panels to do a specific layout for one content type edit mode
How can i use panels to do a specific layout for a content type only for the add and edit form ? I'm a newbie on panels but not on Drupal.I'm using panels 3 on D7. will be great to give me examples or tutos ..

thanks

# Answer
Page manager (which, technically isn't the same thing as Panels), manages the url `node/%` differently from `node/%/edit`.

When you to go `Pages`, you need to enable the node edit task, and make configuration to that page, not the node view one.
> 2 votes

---
Tags: panels, chaos-tool-suite
---


# Question
Title: entity_load_multiple returns empty array although an eitity lives in the database?
I am trying to debug something related to an issue I am facing. The bottom line is that entity load is not returning the peroper values for some reason. For example:

```
$cids = array(119570363);
$comments = comment_load_multiple($cids);
dpm($comments);

```

return an empty array although the comment with id=119570363 exists in the database. I traced entity load function the the comment controller which inherits the load method from DrupalDefaultEntityController.While looking at the method I failed to notice anything that would cause this. Perhaps I am missing something. Are there implicit conditions on the load? Also, I tried with both `$reset = FALSE` and `$reset = TRUE` .

# Answer
comment\_load\_multiple will only load a comment if the node and the user linked to the comment both exist.

You can see this in the code for CommentController::buildQuery where it does an **INNER JOIN** on both the node and user tables. Note that if you trace through the execution of comment\_load\_multiple you have to pass in the RESET argument (or clear the caches before hand) otherwise you will get the cached result, and will never make it into CommentController::buildQuery.

Now the reason CommentController::buildQuery does an INNER JOIN rather than a LEFT JOIN (and the reason I didn't add this as an answer straight away) is that you are not supposed to be in a situation where you have a comment that does not have a node or a user.

You can see this because:

So the problem you are seeing suggests your database is somewhat inconsistent. This could happen if you deleted nodes or users without using the proper API, though it could happen for other reasons (eg. sometimes when dumping and re-saving MySql database you might loose the entry for the anonymous user - it has id 0, and must be in the database users table).

Another note: If this is the only issue affecting the loading then you can get the comments that won't load by doing an SQL query:

```
SELECT cid
FROM comment
LEFT JOIN node ON node.nid = comment.nid
LEFT JOIN users ON users.uid = comment.uid
WHERE (node.nid IS NULL)
      OR (users.uid IS NULL)

```
> 1 votes

---
Tags: comments, entities
---


# Question
Title: User role can't view/edit their own unpublished content
I have a Drupal 7 site where users have a listing they can edit.

This all works fine when the listing is published but as soon as it's set to unpublished they can't view the page or the edit page.

They've got all the relevant permissions:

View own unpublished content Edit own content

I've even got the Override Node and View Unpublished modules installed but still I get the page trying and trying to load but never actually loading.

As soon as I set it to published it's all fine.

Open to any ideas.

Thanks

# Answer
> 1 votes
That is how the permission system is setup for Drupal nodes. Users need some super user permission to be able to edit unpublished nodes (administer content I believe it's called), not very practical. You could instead make a custom form that allows users to publish their own content or create a custom node access function for editing nodes.

# Answer
> 2 votes
For me, the solution was to enable the "Bypass content access control" permission setting. In my case it was for an internal role, so I was comfortable with that but some roles I would not give that to.

I am running Drupal 7, BTW.

# Answer
> 0 votes
"Bypass content access control" only comes into play in a view. You can give someone permission to view their own unpublished nodes, but they will still not see those nodes in a View unless, in that specific view, you select
"Bypass content access control".

# Answer
> 0 votes
I had to create a view "Unpublish" in View module and Module: publishcontent and view\_unpublish works perfectly. Solves the problem.

---
Tags: nodes, users
---


title: multiple submit handlers

text:
# Question
Title: multiple submit handlers
I have the following code:

```
function corporate_form_alter(&$form, &$form_state, $form_id) {

  switch ($form_id) {
    case 'user_login_block':
    {
      unset($form['links']);

      $form['#action'] = '/user/login';
      $form['#submit'][] = 'custom_redirect';

      $form['actions']['submit2'] = array(
        '#type' => 'submit',
        '#value' => t('Sign Up')
      );

      //echo '<pre>';
      //print_r($form);
      //exit;

      break;
    }
  }

}

```

By all examples I have seen this should call a custom\_redirect() in which I have tried echo'ing and exiting and using drupal\_set\_message('Form submitted'); to verify this callback is called.

It is not...I have refreshed the cache a dozen times...I had this working about 3 weeks ago and changed something...

Any ideas?

# Answer
> 3 votes
All you need is `$form['#submit'][] = 'custom_redirect';`, if you want your custom submit handler to be ADDED to the default submit handlers.it will run along with the other (user module submit handlers) this way.

If you need this function only as your submit handler, then

`$form['#submit'] = 'custom_redirect';` (assignment not addition to the submit array)

No need to alter the $form action.

Just alter the original submit button title if its necessary, no need to add another.

---
Tags: 7, forms
---


title: Pass variable from function to template

text:
# Question
Title: Pass variable from function to template
I want to pass a variable from a mymodule\_preprocess\_node(&$vars) to my template file. Something as simple as the following:

```
function mymodule_preprocess_node(&$vars) {
  $vars['node_type'] = 'some_type';
}

```

I trying to pass this variable to a zone--content.tpl.php file.

PS: Cleared all the caches :)

# Answer
To pass variables to the zone template, you need to preprocess the zone, not the node

```
function mymodule_preprocess_zone(&$vars) {
  $vars['node_type'] = 'some_type';
}

```
> 3 votes

---
Tags: views, theming
---


# Question
Title: how to override the HTML of the search results page?
i am trying to override the search-results page with no luck. All of the answers that i have found in google are about overriding the results template. since i am using a subtheme i want to override the whole HTML output of the page. I want to change the header, the footer etc..

Instead results page is using the page.tpl.php. So far i found this How to theme the page template for search results with no success. Any correct way i can succeed this ?

Also i am trying to force the search to search only in specific content types and languages! Any suggestions?

# Answer
Hope this will help you,

In Drupal 7, you can also achieve this

**Using theme\_search\_results OR theme\_search\_result** to override search results page.

* **theme\_search\_results** : invoked for the search result page.

OR
* **theme\_search\_result** : invoked to render a single result

Both these theme functions used in a template file (search-results.tpl.php and search-result.tpl.php).

Source
> 2 votes

# Answer
I would suggest you to do it by help of Display Suite module for search results.

Once you enable this module, you will find **Manage Display** tab when you visit your edit content type. Click to **Manage Display -\> Custom display setting -\>** `check` **Search result** & **save**.

Now you can manage your Search result display by clicking **sub-tab** in the `Manage Display page`. Arrange your field in the way which you want to be displayed & save.

For full page layout, you can go for making a `page--search.tpl.php`. Remove or add the regions or HTML text which you want, clear the cache & ready to go.

If this TPL doesn't work then you have to declare it in `template.php` using `theme_hook_suggestions` in the same way as answer of your linked question. See for the URL which your instance is using for giving search result.

For `$base_url/search` use

```
//replace your theme name with MYTHEME
function MYTHEME_preprocess_page(&$vars) {
  if (arg(0)=='search') {
    $vars['theme_hook_suggestions'][] = 'page__search';
  }
}

```

Add this in your `template.php` & as you are suggesting TPL for page, you have to use `THEME_preprocess_page($vars)`.
> 0 votes

---
Tags: 7, search
---


title: From local server to web hosting

text:
# Question
Title: From local server to web hosting
I have created a website on local with bitnami. Now I want to upload it to a web server (probably on hostgator).

I don't care about content. The site is empty and I will add content only when I upload it.

I just want to keep the settings, permissions, content types and modules. So, I can start add content on air.

If I copy paste the htdocs folder with ftp in the server, this will work?

# Answer
> 2 votes
The simple way, (used to do all this useless stuff before GIT and capistrano...)

Copy/upload **all** (hidden) the **contents** of your Drupal folder in the public\_html or whatever your server document root is for that site.

Export your local database in a dump file.

Create a mysql database on the live server, import the local dump.

Edit the sites/default/settings.php file on your live server to serve your new database credentials. Edit the .htaccess file on the live server to your needs.

Visit your site.Clear the cache tables.

Set the correct permissions on settings.php (check status reports for errors) and the desired setUp on sites/default/files etc for file uploads

That's all

# Answer
> 0 votes
The upvoted and accepted solution provided by Pan Chrono will work.

But IMHO the Backup and migrate module is a great help when copying the database, because it will know what tables to exclude (such as cache and sessions), which will remove cruft from the database migration.

Here are my recommended steps to migrate a Drupal site developed locally to a server:

* Revert to the core theme.
* Uninstall and physically remove all modules that you no longer use (if any).
* Create a tar file of the Drupal file system set up you want to migrate to server (i.e. the Drupal root and all files below it.)
* Upload the tar file to the web server and extract it to desired location.
* Make sure the `sites/default` directory and the `sites/default/files` directory is writable by the web server user.
* Remove `settings.php` from the migrated site. Copy `default.settings.php` to `settings.php`.
* Fire up the browser, type the domain name, and do a clean installation of Drupal as usual.
* Migrate the database using Backup and migrate.
* Check that you still can log in as user #1 (*admin*). Note that since you've imported the user table, the *admin* username and password is the one used on the site you've just migrated.

# Answer
> -1 votes
> If I copy paste the htdocs folder with ftp in the server, this will work?

Not without the database; You have to import the database too, and then (if you really don't need the contents) delete them manually (there are a lot of ways to do that in bulk, like views bulk operation or a custom module that delete all contents you don't need).

Otherwise you can try Features module, where you can export all your fields/settings on a fresh install; but if the site has a bit of complexity I dont know if it will do the trick.

---
Tags: migrations
---


# Question
Title: How do I let end users create and manage arbitrary connections between their user account and an entity
I have an event content type and I want to allow users to 'add' themselves to it the same as Facebook users would join an event. Any ideas?

# Answer
I believe you are looking for the Organic Groups module (https://drupal.org/project/OG).

This module allows you set your current content types to be 'subscribed' to. Thus users can join a group, or event in your case.

The group can have administrators where they can manage and invite users, such as setting to them active, pending or blocked.

We recently created a Drupal module that would allow a group members to invite other users, even if they were registered or new.

Organic Groups will also allow you your members to 'post' content INTO the group. E.g. you could post pictures relating to that event.

It's quite easy to setup and many tutorials around.

Hope this helps, Amarjit
> 2 votes

# Answer
With Entity reference, this isn't very easy, because references are fields, and the permission management you need here is hard to do on a field level. You could still do it, but it would require a significant amount of custom work.

Consider using Relation or Flag instead.

You'll most likely get a better "out of the box experience" with the Flag module, but you will get better flexibility with the Relation module.

I've tried to convince one of Flag maintainers that the Flag is a special case of the Relation module and so should be based on it, but he didn't want to add a dependency.
> 6 votes

# Answer
The Entity Registration module should be a solution.

> Entity Registration is a simple, flexible module for allowing and tracking user registrations for events, or just about anything you want people to sign up for. Entity Registration can be integrated with Drupal Commerce to allow fee-based registrations: sell tickets to your stuff! This module is also handy if you want to collect information along with registrations: like shoe-size for a bowling event.
> 2 votes

---
Tags: users, entities
---


# Question
Title: What variable is responsible for the default admin bar on top of every default Drupal theme?
This is basically my html.tpl.php -

```
</head>
<body>
<?php print $page; ?>
</body>
</html>

```

What do I need to add to make that horizontal admin bar appear?

# Answer
It's stored in `$page_bottom`...you should also output `$page_top` to make sure you have a complete page:

```
</head>
<body>
  <?php print $page_top; ?>
  <?php print $page; ?>
  <?php print $page_bottom; ?>
</body>
</html>

```
> 2 votes

---
Tags: users, theming
---


# Question
Title: Drupal commerce. How to show only products suitable for selected vehicle?
Any ideas how to tackle following scenario with Drupal Commerce?

User selects his own vehicle from select drop-downs. Vehicle consists of following attributes: vehicle type, manufacturer, year, model. Then, by clicking any product category, user gets a view of products in that category that are suitable for the currently selected vehicle.

There are 50000 products in Excel file (with unique SKU), 8500 different vehicles as csv (with unique vehicle id and each vehicle attribute in their own columns), there are going to be 800+ product categories with many subcategories (snow mobiles, scooters, engine parts, exhaust pipe systems…) Many products may fit in many vehicles.

So where to start? How to match products with vehicles? How to match products with categories? Any help is appreciated. Thank you.

# Answer
General solution is to use Entity reference.

You need two entity types:

1. Cars
2. Products

Products you have already, thanks to commerce. Cars can well be nodes so you can create content type for them using GUI. To products add entity reference pointing to cars. Then create a view with product to car relationship, filtered by car.

For categories, use regular taxonomy.
> 2 votes

---
Tags: 7, commerce
---


# Question
Title: how see left or right sidebar in search result page?
I'm sorry if it sounds like obvious question, but I cannot solve this... I'm using D7.15, customized Fusion subtheme and Display Suite to style the search result appearance. But all the times I get the search results page in fullscreen (no left or right sidebars) and I can't find the solution for this. No costomizations on search-results.tpl.php.

please help! :/

UPDATE: I'm using drupal core search, I have tried Search by page module too.

# Answer
> 2 votes
Create one template file: **page--search.tpl.php**.

Write the following code:

```
//to print the main content
print render($page['content']);

//to print your right side-bar
print render($page['name_of_the_region_with_right_sidebar']);

```

and other customization as needed.

# Answer
> 2 votes
Hope this will help you,

As I understand, you need to show right and left sidebar in the search page. You can achieve it using **context** module.

Steps

* After enabling the context module, add a new context using **admin/structure/context/add**
* Select **PATH condition**
* **Add search PATH**
* Now its time to add blocks, **select Block Reactions**
* Now add the your blocks in right and left sidebars.

+ **Select blocks**
    + **After adding the blocks**
* **Search result with blocks**

NOTE

* Follow the same steps for **search/user/\***

# Answer
> 0 votes
This does not seem to be possible with the default core Search module or even apachesolr.

---
Tags: search
---


# Question
Title: Date Repeat: Display only the first and last instances of a series?
I have been going crazy trying to find a way to display only the first and last dates of a series using Date Repeat, either in a view or the node itself, of repeating events. For example, there is a course that starts on January 16, and repeats every Monday until March 5. I would like to be able to display something like "Every Monday from January 16 until March 5" or something to that effect. Does anyone have any advice, can anyone point me in the right direction?

Thanks in advance!!

# Answer
> 0 votes
This is an old question, but I thought I'd put in my two cents.

The only way I can think to accomplish this is with custom PHP and a call to the database. You could collect all of the dates for an event an then just show the first and last. The name of the repeat rule is saved in the `field_date_rrule` column and could be parsed from there.

# Answer
> 0 votes
I don't know what it's like in 6, but in 7 (with Views 3.x) you can just toggle the Repeat rule select and choose "Show repeat rule" on the field that contains your date. If you don't like the date display, you can create a custom one by going to admin/config/regional/date-time and modifying the formats and types.

---
Tags: 6, datetime
---


title: Multiple choice poll

text:
# Question
Title: Multiple choice poll
I thought this would be out of the box, but it doesn't seem so.

I'm looking for a way to be able to have a multiple choice poll where users can select more than one answer.

Is this even possible with the Drupal 7 Core Poll Module?

If Core Poll does not allow this, are there some other modules out there which are not in dev?

# Answer
> 2 votes
You might want to consider Webform. It functions differently from Poll, but it's also much more robust and has plenty of additional modules that extend it.

And, of course, creating a question that allows multiple choices is a snap.

---
Tags: 7, polls
---


title: How to create a menu for current book

text:
# Question
Title: How to create a menu for current book
I want to create a menu that will be shown on the node if it is part of a book. For example like this:

That menu should be shown for all books, which means I don't want to have a separate block for each book in the system.

I am not interested in how to implement accordion functionality, I just need a way to get menu items for all book elements of current node.

Book module provides a block with books navigation, but I don't want all books to be visible in this menu.

# Answer
I was surprised that I couldn't find a contrib module that does this out of the box so I created a simple one.

Here it is on Github too: https://github.com/balsama/bookoblock (`bookoblock` = "Book Outline Block")

Info file (`bookoblock.info`):

```
name = Book Outline Block
description = "Provides a block containing an outline of the current book."
package = Other
core = 7.x
dependencies[] = book

```

Module File (bookoblock.module):

```
<?php
/**
 * Define the Book Outline Block/
 * Implementation of hook_block_info()
 */
function bookoblock_block_info() {
  $block['book_outline'] = array (
    'info' => 'Book Outline',
    'cache' => DRUPAL_CACHE_PER_PAGE,
  );
  return $block;
}

/**
 * Define the contents and title of the block/
 * Implementation of hook_block_view()
 *
 * Returns a renderable block array containing the current book's outline if
 * the node is part of a book.
 *
 * Returns NULL if the current menu item is not part of a book heirarchy.
 */
function bookoblock_block_view() {
  if ($book = bookoblock_is_book_node()) {
    $tree = menu_tree_all_data(book_menu_name($book['bid']));

    // If we pass 1 as the second param, we just get the top level node in the
    // book. Since the key will be the top level mlid, we'll have to use
    // ['p1'] in the $book array (which contains the top mlid) when we use it
    // for the block title.
    $book_name = (book_toc($book['bid'], 1));

    // Build the block title and contents
    $block['subject'] = $book_name[$book['p1']];
    $block['content'] = menu_tree_output($tree);

    // Return the block
    return $block;
  }
  // If the current node isn't part of a book, just return nothing.
  return NULL;
}

/**
 * Checks to see if current node is part of a book.
 * Returns book array if it is part of a book, FALSE is not.
 */
function bookoblock_is_book_node() {
  if ((arg(0) == 'node') && (is_numeric(arg(1)))) {
    $node = menu_get_object();
    if (isset($node->book)) {
      return $node->book;
    }
  }
  return FALSE;
}

```

Just drop those two files into a folder named `bookoblock` inside your modules directory and enable the module. You'll now see a new block in the block admin page named `Book Outline`. That block will only appear on node pages where the node is part of a book. It contains a heierarchical menu of the entire book and it's title is the root node's title.
> 4 votes

# Answer
Book Block is what I've used on a site. It's currently got a dev release but it's been stable for us so far on Drupal 7.

It provides you with a block per book. You can then use context to set the conditions of display.

Update - In terms of scaling it you will have to automate the block position, something like when a new book is created a new context is added with the correct conditions and reactions. Unfortunately this isn't as simple as a drop in contrib solution.
> 2 votes

# Answer
See https://drupal.org/node/1930370#comment-7676439.

How does this request differ from what is available out-of-the-box from the core Book module?

*From the original question:*

> Book module provides a block with books navigation, but I don't want all books to be visible in this menu.

On the core Book Block configuration page, you have the option to `Show block only on book pages`, which according to the description:

> If `Show block only on book pages` is selected, **the block will contain only the one menu corresponding to the current page's book**. In this case, if the current page is not in a book, no block will be displayed. The Page specific visibility settings or other visibility settings can be used in addition to selectively display this block.

Unless I'm missing something (again), I think both of us somehow missed this the first time.

**Screenshot**
> 1 votes

# Answer
In addition to Adam's answer I would like to add some information on how to theme the outline of a book.

There are few theming tricks. It took me quite a while to figure them out, so I decided share:

* You can massage renderable array that you get with `menu_tree_output()` to change the output. You can either inject html directly to element of the leaf like this:

```
$leaf['#title'] = "<span class='my-class'>Custom  html here.. </span>";
$leaf['#localized_options']['html'] = TRUE;
$leaf['#attributes']['class'][] = 'my-class-link';

```
* Or you can change the theming function that will be applied to the element at the desired level of the tree:

$leaf\['#theme'\] = 'menu\_link\__my\_book\_outline';

in this case you will have to provide reference to this theme in `hook_menu` and provide implementation of the theme function declared in the hook:

```
/**
* Implements hook_theme()
*/
function my_book_outline_theme() {
  return array(
        'menu_link__my_book_outline' => array(
           'render element' => 'element'
        )
    );
}

/**
* Returns HTML for the section level elements of the my book outline
* see theme_menu_link for default implementation
*/
function theme_menu_link__my_book_outline(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';
  $output = '<h3>' . $element['#title'] . '</h3>';
  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }
  return $output . $sub_menu . "\n";
}

```

This way you will override the `theme_menu_link` call with your custom rendering.

* If you theming depends on levels don't forget that you can always find out the depth of the item - `$element['#original_link']['depth']`
> 0 votes

# Answer
Books structures are actually stored in the same way as menus, so if you are comfortable editing your database, you can very simply create a **custom menu** from to the book menu tree (that will therefore be available as a block).

This youtube video shows you how to do this:

http://www.youtube.com/watch?v=FuQIe5ik9as

Alternatively the menu\_block module will offer your books as options in the list of menus when you create a new 'menu block' to suit your needs.
> 0 votes

---
Tags: 7, nodes, navigation
---


# Question
Title: Warning: Illegal offset type in drupal_add_js() (line 4184 of C:\EasyPHP-5.3.8.1\www\lfp\includes\common.inc)
I am using D7. I am getting the above error when I created a js file with the code below and then included it in the .info file. What is wrong?

```
(function($) {
Drupal.behaviors.userLoginChanges = {
    attach: function(context) {
        $("#user-login-form").attr("placeholder", "Username");

    }
}
}) (jQuery);

```

# Answer
> 6 votes
I realized the issue - In the info file I was writing scripts\[all\]\[\] = filename, the same way you do it with css files. The correct syntax is scripts\[\] = filename.

---
Tags: 7, javascript
---


# Question
Title: Most efficient way to change CSS between pages
I'm looking to change certain parts of my design for my site through the CSS, my basic principle is that when you navigate to a certain page, it will kick in to effect, and change some CSS values.

Say for example you navigate to `mysite.com/colour/red`. It would change certain parts of the styling to red (like border colours, underlines, link colours etc) and it would remain in red until you then navigated to something like `mysite.com/colour/green` at which point, everything that had previously changed to red, now becomes green.

I have already written some code which runs a function when you navigate to one of these pages and sets a session variable using the Session Cache API so that I can set a temporary colour change for the site.

My question is, what is the best way of injecting the new lines of CSS into my site at this point? My initial train of thought is that I can extend the function I currently have to pull in an external CSS file with those specific colours already defined (ie if you go to `mysite.com/colour/red`, it will pull in `red.css`, with the border/underline already specified). Or alternatively, I have thought about using the html.tpl file to perform a check against the session parameter, and pull in a CSS file through there.

What would be the most efficient way of changing my stylesheet? Is there a function already in Drupal which would allow me to do something like this

NB. I am using the Alphorn Omega theme template

# Answer
I think the usual method of adding per-page CSS is in your template.php file using `HOOK_preprocess_page()`. A couple of examples:

```
alphorn_preprocess_page(&vars) {
  // Add CSS based on path (beware if you change your path structure!)
  // But as a bonus, this will add the CSS for any path under "/colour/red"
  if (strpos($_SERVER['REQUEST_URI'], 'colour/red') !== false) {
    drupal_add_css(drupal_get_path('theme','alphorn').'/css/red.css');
  }

  // Add CSS based on NID, with an out because this hook may be called on non-node pages
  // or pages that otherwise don't return anything useful for menu_get_object().
  @$node = menu_get_object();
  $red_nodes = array(1, 2, 3, 5, 8, 13);
  if(isset($node) && in_array($node->nid, $red_nodes)) {
    drupal_add_css(drupal_get_path('theme','alphorn').'/css/red.css');
    // If your stylesheet is really simple you could always inline it.
    drupal_add_css('body { background-color: #FF0000; }', 'inline');
  }

  // Then you need to plug your added CSS into your variables or nothing will happen.
  $vars['styles'] = drupal_get_css();
}

```
> 1 votes

---
Tags: 7, theming
---


# Question
Title: Programmatically add a translation of month
I need to add a custom translation of long form of months. The existing translation must be changed slightly.

One way to do it is via UI, however, not all months are available for translation yet (this is a new site). I would like to write a function in a module that would add all translations of months programmatically (and it would also be possible to use it on other sites). Is there a way to do it?

# Answer
Use string overrides directly in either your settings.php file or through the string overrides module. See this note for specifics, this also lets you migrate this string overrides snippet from site to site either through simple cut and paste or through the string overrides migrate extension. This also deals with strings not yet known to the locale UI through t().

Example:

```
 $conf['locale_custom_strings_en'][''] = array(
   'January'      => 'New string 1',
   'February'      => 'New string 2',
 );

```
> 2 votes

---
Tags: 7, datetime, i18n-l10n
---


# Question
Title: How to refer paths relative to the theme directory?
I have a theme called Eternal with the following data in it's **eternal.info** file-

```
name = Eternal
description = A Customized Drupal 7 Theme
core = 7.x
engine = phptemplate

```

In the template folder lies the **page.tpl.php**. Under the `/themes/` folder, the address becomes -

`/eternal/templates/page.tpl.php`

There are several lines inside the page.tpl.php that require I define a path for an image, like so-

`<img src="images/facebook_icon.png" alt="image comes here">`

The `/images/` folder is located inside the `/eternal/` folder, so to access it from `/templates/` one would need to travel one level up and then access the `/images/` folder. That would look like this - `/../images/`.

The problem is, I cannot define a link that works in Drupal. And I'm sure the images exist in that directory.

I've tried these-

`<img src="../images/facebook_icon.png" alt="image comes here">`

`<img src="images/facebook_icon.png" alt="image comes here"> <!-- not like this would have worked anyway -->`

`<img src="<?php drupal_get_path('theme', 'eternal'); ?>/images/facebook_icon.png" alt="image comes here">`

It just shows the alt text in every case. No image. How to accomplish this and what is the recommended and proper way to do this?

# Answer
> 6 votes
```
<?php print drupal_get_path('theme', 'eternal'); ?>

```

as you've already tried, is the correct way to solve your problem. Notice though that you have to print it out as well, as drupal\_get\_path will only return the path, not print it for you.

I can't immediately think of any reason why it would not work in your case. Some potential suggestions to try could be

1. Double-check your spelling of the theme name in the code.
2. Clear caches.
3. Try disabling the theme/module and re-enable it.

Failing everything else, you'll need to debug drupal\_get\_filename() directly.

# Answer
> 3 votes
You can get path to your theme with **$directory** variable which will be available in all your templates.

```
<img src="<?php print $base_path . $directory; ?>/images/example.png"/>

```

See template\_preprocess()

If you have multiple *img* elements in your page template you can create a dedicated variable for *page.tpl.php* that will keep path to your images directory.

```
/**
 * Impelements hook_preprocess_page().
 */
function eternal_preprocess_page(&$vars) {
  $vars['images_dir'] = $vars['base_path'] . $vars['directory'] . '/images';
}

```

Now, it looks more clear.

```
<img src="<?php print $images_dir; ?>/example.png"/>

```

# Answer
> 1 votes
You have to print/echo the output of drupal\_get\_path() for it to actually appear in your markup. By default it simply returns a PHP string.

```
<img src="<?php print($base_path.'/'.drupal_get_path('theme', 'eternal')); ?>/images/facebook_icon.png" alt="image comes here">

```

# Answer
> 1 votes
As mentioned by Letharion, `drupal_get_path()` should be your first port of call.

> Returns the path to a system item (module, theme, etc.).

The only reason I have posted this as an answer, rather than just left it at Letharions answer is that I wanted to bring attention to the System Stream Wrapper module as well:

> Provides stream wrappers to access module, theme, profile, and library files and directories.

Which means that `theme://eternal/images/example.jpg` would also work with this module enabled.

---
Tags: theming
---


title: Set a default text in an article

text:
# Question
Title: Set a default text in an article
Im looking for a way to create a text template or a way to make one, where, when you create a node of a specific content type, a text is preloaded into the node. (Similar to Word-Templates)

At the moment, whenever I habe to write a status report, I have to copy paste it, but I want this to happen automatically.

Any help would be greatly appreciated.

Best Regards.

# Answer
Couple options come to mind,

if you don't want to code then you can use Node Clone module and have 1 unpublished template node, and everytime you want to create a new one just clone the template node.

Also without installing any modules, you can use the `Default value` in the field setting of the content type

The other way is a bit more tricky, you have to create a custom module and use `hook_form_alter` to set the default values of the fields for your specific content type.
> 3 votes

---
Tags: nodes, theming
---


# Question
Title: How can I create a view that lists users who have NOT completed an order?
I am helping with a Drupal 6 / Ubercart site that has tons of spam user accounts registered.

I want to create a view that will list spam accounts. My thinking is that users who have registered but never bought anything in Ubercart have a high probability of being spam so I want to create this view. However, I can't figure out how to filter my user view to list only users who have **not** completed an order.

Is this possible?

# Answer
To save to anyone else the trouble, this is the view I created to achieve the above.

```
$view = new view;
$view->name = 'Spambots';
$view->description = '';
$view->tag = '';
$view->base_table = 'users';
$view->core = 6;
$view->api_version = '2';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
  'uid' => array(
    'label' => 'Order user',
    'required' => 0,
    'id' => 'uid',
    'table' => 'uc_orders',
    'field' => 'uid',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'mail' => array(
    'label' => 'E-mail',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'absolute' => 0,
      'link_class' => '',
      'alt' => '',
      'rel' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'hide_alter_empty' => 1,
    'link_to_user' => 'mailto',
    'exclude' => 0,
    'id' => 'mail',
    'table' => 'users',
    'field' => 'mail',
    'relationship' => 'none',
  ),
  'created' => array(
    'label' => 'Created date',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'absolute' => 0,
      'link_class' => '',
      'alt' => '',
      'rel' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'hide_alter_empty' => 1,
    'date_format' => 'small',
    'custom_date_format' => '',
    'exclude' => 0,
    'id' => 'created',
    'table' => 'users',
    'field' => 'created',
    'relationship' => 'none',
  ),
  'login' => array(
    'label' => 'Last login',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'absolute' => 0,
      'link_class' => '',
      'alt' => '',
      'rel' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'hide_alter_empty' => 1,
    'date_format' => 'small',
    'custom_date_format' => '',
    'exclude' => 0,
    'id' => 'login',
    'table' => 'users',
    'field' => 'login',
    'relationship' => 'none',
  ),
  'edit_node' => array(
    'label' => 'Edit link',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'absolute' => 0,
      'link_class' => '',
      'alt' => '',
      'rel' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'hide_alter_empty' => 1,
    'text' => '',
    'exclude' => 0,
    'id' => 'edit_node',
    'table' => 'users',
    'field' => 'edit_node',
    'relationship' => 'none',
  ),
  'delete_node' => array(
    'label' => 'Delete link',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'absolute' => 0,
      'link_class' => '',
      'alt' => '',
      'rel' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'hide_alter_empty' => 1,
    'text' => '',
    'exclude' => 0,
    'id' => 'delete_node',
    'table' => 'users',
    'field' => 'delete_node',
    'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
  'uid' => array(
    'order' => 'DESC',
    'id' => 'uid',
    'table' => 'users',
    'field' => 'uid',
    'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
  'order_id' => array(
    'operator' => 'empty',
    'value' => array(
      'value' => '',
      'min' => '',
      'max' => '',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'order_id',
    'table' => 'uc_orders',
    'field' => 'order_id',
    'relationship' => 'none',
  ),
  'rid' => array(
    'operator' => 'not',
    'value' => array(
      3 => '3',
      6 => '6',
      4 => '4',
      5 => '5',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'rid',
    'table' => 'users_roles',
    'field' => 'rid',
    'relationship' => 'none',
    'reduce_duplicates' => 0,
  ),
));
$handler->override_option('access', array(
  'type' => 'role',
  'role' => array(
    3 => 3,
    5 => 5,
  ),
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('header', 'The following accounts have no orders associated with them and are not assigned a specific role. Therefore it is safe to assume they are spambots.');
$handler->override_option('header_format', '1');
$handler->override_option('header_empty', 1);
$handler->override_option('use_ajax', TRUE);
$handler->override_option('items_per_page', 20);
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
  'grouping' => '',
  'override' => 1,
  'sticky' => 0,
  'order' => 'asc',
  'summary' => '',
  'columns' => array(
    'mail' => 'mail',
    'login' => 'login',
    'uid' => 'uid',
    'delete_node' => 'delete_node',
  ),
  'info' => array(
    'mail' => array(
      'sortable' => 0,
      'separator' => '',
    ),
    'login' => array(
      'sortable' => 0,
      'separator' => '',
    ),
    'uid' => array(
      'sortable' => 0,
      'separator' => '',
    ),
    'delete_node' => array(
      'separator' => '',
    ),
  ),
  'default' => '-1',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'spambots');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));

```

It will need tweaking to your needs because I've got it set up to filter based on user role too but should give you a good base to start with.

Also the SQL is:

```
SELECT users.uid AS uid, users.mail AS users_mail FROM users users  LEFT JOIN uc_orders uc_orders ON users.uid = uc_orders.uid LEFT JOIN users users_uc_orders ON uc_orders.uid = users_uc_orders.uid LEFT JOIN users_roles users_roles ON users.uid = users_roles.uid AND (users_roles.rid = 3 OR users_roles.rid = 6 OR users_roles.rid = 4 OR users_roles.rid = 5) WHERE (uc_orders.order_id IS NULL) AND (users_roles.rid IS NULL) ORDER BY uid DESC

```
> 4 votes

# Answer
first you will have to add a relationship linking ubercart orders to a user, then filter by the order number that is not greater than 0.
> 1 votes

---
Tags: views, 6, ubercart
---


# Question
Title: How to display comments of current node in a view
I would like to display comments of the current node in a view. The reason for doing so is that I want the comments to be neatly displayed in a table and views seems to be an easiest way to do so than messing with theme template etc. (I am new to drupal)

I have created a comment view and selected comment: nid as a filter selector. How do I provide the "current NID" as the argument for the filter? I have tried Comment:nid is equal to "current" but this does not work.

Any suggestion?

# Answer
You need a contextual filter. In your view, remove comment:nid from the Filter Criteria.

Next, on the far right, under "Advanced", add a "Contextual Filters" and select comment: nid there.

In the configuration options, under WHEN THE FILTER IS *NOT* AVAILABLE, select "Provide Default Value". From the Type dropdown, select "Content ID from URL".

Click Apply, save your view, and add the block as normal.
> 6 votes

---
Tags: views, comments
---


title: Can't choose content type anymore

text:
# Question
Title: Can't choose content type anymore
I installed the Webform module on my drupal 7 install and now, when I select to create new content, I don't get asked to choose the content type (basic page, article, webform) anymore. Where is the setting for this? I need to be able to choose which content type I want to create.

Thank you! Ron

# Answer
> 2 votes
This is caused by a hiccup in the node menu rebuild after installing a new module. If you run into this issue, its likely due to one of three problems, which you can address in the following order:

* Clear full cache, forcing the content menu to rebuild
* Go to the menu options under /admin/structure/menu/manage/navigation and look for your add content menu items and make sure they are disabled
* If these two fail, then there is probably an error in your build that is preventing the menu from rebuilding correctly - check in your error logs for any issue there and address.

---
Tags: 7, nodes, webforms
---


# Question
Title: How to disable "Add To Cart" button on select products?
I have a Drupal 7 / Ubercart 3 website. How can I disable the "Add to Cart" button on only some products? For instance, if I wanted to list product ABC but did not want to actually sell it online, I'd like for its "add to cart" button to either be hidden or to display a different button that would not be clickable.

The only solution I could find is for D6 (https://drupal.org/project/uc\_disable\_product).

Thanks!

# Answer
> 1 votes
On What ever products you dont want customers to buy or add to cart, the easiest solution is just hide them using css for that button alone.

```
.parentclass #add-to-cart
{
  display:none;
}

```

Or

you can use uc\_auction module and let the products be auctioned for particular period of time.there will be no add to cart button.

# Answer
> 1 votes
edit: new answer/idea

Assign a new toggleable attribute to your products. Access the product display template (or hook?) and check for that attribute and change/disable/remove the "add to cart" button if it's found.

---
Tags: 7, ubercart
---


# Question
Title: How to link to a users profile in a view
I created a view which displays users on my site. Using "Rewrite results" I displayed the first name and Surname in one column. I then checked "Output this field as a link".

My challenge is what path will I enter into the "Link Path" field to ensure that the names in the column link to the user profiles.

# Answer
> 3 votes
By default, user profiles are at `user/UID`, where `UID` is the numeric user ID. (This is true unless you are using a module like Pathauto to customize the profile URLs.)

So, one way to do this is to:

1. Add the numeric user ID field to your view. Make sure to check *exclude from display* so it won't actually be shown in the view.
2. Reorder the fields in the view so that the *user ID* field comes before the field for which you want to rewrite results.
3. The value of the *user ID* field will now be available as a token in "Rewrite results." So, you can use the token to create a link to the user profile like this: `user/[uid]` (the actual token may be slightly different).

---
Tags: views
---


# Question
Title: Users that exist only on slave cannot login
Once I've installed bakery, users that exist only on the slave site can no longer log in. Everything else is working perfectly.

Is this by design?

# Answer
> 5 votes
Bakery doesn't pre-sync accounts, so any accounts that exist only on slave sites (sub-sites) won't be synchronized to the master site. This is because of the nature of needing an authoritative account master, the Bakery master site. During authentication (on a slave site) Bakery sends the user to the master to validate so if the account does not exist there the user cannot be authenticated.

To note, accounts that exist on the master that do not exist on the slave will be synchronized when the user authenticates and visits the slave site (administrators also have the option to "pull" accounts from the master).

---
Tags: users, authentication-authorization
---


title: Email verification programmatically

text:
# Question
Title: Email verification programmatically
I have a custom registration form with three options(premium, trial and group). The premium user does not need email verification but other two do. So I need to send verification email pro-grammatically.

I have searched google where I got only options for some modules. But my need is only sending an email with unique URL for verifcation.

Please suggest me the drupal function that helps me achieve this.

Thank you

# Answer
You could use hook\_mail\_alter to abort the verification email being sent in the condition that the user is using the premium option. As stated on the api.drupal.org page if you set the 'send' parameter of the $message data to FALSE it will abort sending the email.

You'll need to retrieve the 'premium' context within your implementation of hook\_mail\_alter() to achieve this, which may require setting that property on the user, the session, or in a custom database table.
> 1 votes

---
Tags: users, emails
---


# Question
Title: Admin account has it's own log in form and should not be able to log in in default log in form
I have this certain problem which I don't know how to start doing this thing.

In drupal we have a log in form (let's call it **normal login form**) which **all** users can log in including admin.

So what I want is, to create a log in form for admin **only**. Which I already made it.

But the **problem** lies here, the normal login form should not let the admin proceed if the admin log in at the **normal log in form**

Here's a screenshot for it.

As you can see, that's the **normal log in form**. If the admin logged in to that, it should **not** let them proceed since **they have their own log in form**. All I want is only normal users can access can log in in this form.

Any possible solution for this?

# Answer
> 1 votes
You could implement hook\_form\_alter or hook\_user\_login() to check the roles of the user logging in and deny if the user is an administrator. Check the Examples module for uses of hook\_form\_alter and other contrib modules like Legal and User Auth API are practical examples of extra validation and control during user authentication.

---
Tags: 7, users
---


# Question
Title: Is there a way to see what parts are not in a feature?
I am working on a site where I have content types with fields coming from several different feature modules. I've added organic groups with groups on most of those content types, and also added some content types and fields.

Now I need to package things up, update the features modules, and make new ones. I am going over things looking for overridden features, and adding fields that are missing. While I can see what is overridden, it can be easy to overlook new fields that I need to add, especially when I have to cross-reference different modules.

Is there a way I can see what featureable parts are *not* in a feature? Since I'm dealing with several different features, I can't just look at one 'recreate' page and see what I need to add. I would like to see a master list of what part is in what feature and what is still in the database.

# Answer
2 options:

1. Using Drush, the following command will show you all the Features Components which aren't already claimed by a Feature:

```
drush features-components % --not-exported

```
2. You can install the Features Orphans module, which provides a list of unclaimed Features Components using Drupal's web interface.
> 2 votes

---
Tags: features
---


title: translating static text

text:
# Question
Title: translating static text
I have just built a view for one of my modules. In there, I have this line; %
of Applicants Admitted\`

I already installed modules like "Locale", "Content Translation" and "Internationalization" is already enabled. But I dont understand how these modules will translate this text to other languages. When I put it in `t('')` how will I know that it will translate it correctly. Can I manually enter the translation?

Thanks

# Answer
> 0 votes
Translations have to be entered manually... always. There is no "automatic machine translation" function provided by Drupal core or the Internationalization suite of modules.

Putting a string inside `t()` simply makes it available to Drupal's translation subsystem for translation; the string will still be displayed "as is" until it is translated manually.

To translate strings manually from the UI, if you have the Locale module enabled, you can go to the *Translate interface* page. (On Drupal 7: `/admin/config/regional/translate/translate`)

---
Tags: i18n-l10n
---


# Question
Title: contact page with some texts, a form & google map
I would like to have contact page which displays information about address, phone, email and some texts. + a contact form + a Google map showing location. Please let me know how the above is achieved. Thanks

# Answer
The best way is to use webforms to create your contact form. Make sure to use the option of creating the webform in a block. Create two more blocks. One containing the address and contact and the other containing your map.

And using like panels or a page. arrange your blocks on that page.
> 2 votes

---
Tags: 7, google-maps, emails
---


# Question
Title: Create a node on user account creation. Display link to user on first login
I need to capture addtional private information about a users company when they register (one time).

What i am currently doing.

1. Creating new node on account creation with rules.
2. Add a view that filters by node author, and display it on the users profile, with a edit link.
3. The user can then edit the node that he is the author to on his profile page.

This works

I want to display a link or auto redirect to the node once the user has logged in for the first time.

Been busy with this for a long time. Any advice or Pointers.

# Answer
> 0 votes
With Field collection I was able to add fields within a field to collect.

# Answer
> 1 votes
Assuming you are using Drupal 7, I'd advice you **not** to do this.

Drupal users are now *entities* and field-able.

In **Admin \> Configuration \> People \> Manage Fields** tab, you can add new fields to the profile. With Profile2 module, you can have even more control over these fields (this will become a new entity type, with option to have separate tab in user edit page, etc).

If you are using Drupal 6, while being prepared to upgrade your site to Drupal 7 or 8 in near future, you can use Content Profile module to do this.

Also, if you need to automate these data/fields with user registration, give a try to Rules module.

Profile2 and Content Profile, as well as core profiles have Views support so you can show these profile fields in user with a 1:1 relationship (if you create a new node without binding it to the user, how do you find the correct node from pool ?).

---
Tags: panels
---


# Question
Title: how is config saved in nodeapi_example module?
In this module, which hook is responsible for saving the user choice (at `admin/structure/types/manage/<CONTENT_TYPE>`) into the database?

I implemented `nodeapi_example_form_alter()` function exactly as it is, but it is not saving anything.

My hook\_form\_FORM\_ID\_alter() in my .module - this does NOT save the value of my radio - anything missing here?

```
function followbtn_form_node_type_form_alter(&$form, $form_state, $form_id) {
  // First, check for the node type configuration form.
  drupal_set_message('Entered hook_form_alter ...');
  //if ($form_id == 'node_type_form') {
  if (isset ($form['type'])) {
    // Alter the node type's configuration form to add our setting. We don't
    // need to worry about saving this value back to the variable, the form
    // we're altering will do it for us.
    $form['followbtn_rating'] = array(
      '#type' => 'fieldset',
      '#title' => t('Custom Rating settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#group' => 'additional_settings',
      '#weight' => -1,
    );

    $form['followbtn_rating']['followbtn_node_type'] = array(
      '#type' => 'radios',
      '#title' => t('NodeAPI Example Rating - Custom'),
      '#default_value' => variable_get('followbtn_default_mode_' . $form['#node_type']->type, FALSE),
      '#options' => array(
        FALSE => t('Disabled'),
        TRUE => t('Enabled')
      ),
      '#description' => t('Should this node have a rating attached to it?'),
    );
  }
}

```

I can see the "Enabled" and "Disabled" radio buttons; when I hit "save Content Type", these do not get saved.

# Answer
> 1 votes
There is no hook that needs to be implemented by the module for that purpose: Saving the value is automatically done by Drupal. In that case, the value for the nodeapi\_example\_node\_type form element is saved in the `nodeapi_example_node_type_<CONTENT_TYPE>` Drupal variable, which is the variable the module accesses for the default value.

```
// Compare the following line...
$form['rating']['nodeapi_example_node_type'] = array(
  '#type' => 'radios',
  '#title' => t('NodeAPI Example Rating'),

  // with the following.
  '#default_value' => variable_get('nodeapi_example_node_type_' . $form['#node_type']->type, FALSE),
  '#options' => array(
    FALSE => t('Disabled'),
    TRUE => t('Enabled'),
  ),
  '#description' => t('Should this node have a rating attached to it?'),
);

```

Similar code is used in locale\_form\_node\_type\_form\_alter().

```
  if (isset($form['type'])) {
    $form['workflow']['language_content_type'] = array(
      '#type' => 'radios',
      '#title' => t('Multilingual support'),

      // The variabile name is <FORM_ELEMENT_NAME>_<CONTENT_TYPE>.
      '#default_value' => variable_get('language_content_type_' . $form['#node_type']->type, 0),

      '#options' => array(t('Disabled'), t('Enabled')),
      '#description' => t('Enable multilingual support for this content type. If enabled, a language selection field will be added to the editing form, allowing you to select from one of the <a href="!languages">enabled languages</a>. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array('!languages' => url('admin/config/regional/language'))),
    );
  }

```

As for the purpose of the other node hook implementations:

Notice that `hook_node_update()` and `hook_node_insert()` are mutually exclusive: Drupal calls one or the other, but not both the hooks at the same time. The first is called when an existing node is update; the second is called when a node is created.

In your code the error is the mismatch between the form element name (followbtn\_node\_type) and the name of the Drupal variable you are using (`followbtn_default_mode_<CONTENT_TYPE>`). You need to change your code in one of the following ways:

```
$form['followbtn_rating']['followbtn_node_type'] = array(
  '#type' => 'radios',
  '#title' => t('NodeAPI Example Rating - Custom'),
  '#default_value' => variable_get('followbtn_node_type_' . $form['#node_type']->type, FALSE),
  '#options' => array(
    FALSE => t('Disabled'),
    TRUE => t('Enabled')
  ),
  '#description' => t('Should this node have a rating attached to it?'),
);

```

```
$form['followbtn_rating']['followbtn_default_mode'] = array(
  '#type' => 'radios',
  '#title' => t('NodeAPI Example Rating - Custom'),
  '#default_value' => variable_get('followbtn_default_mode_' . $form['#node_type']->type, FALSE),
  '#options' => array(
    FALSE => t('Disabled'),
    TRUE => t('Enabled')
  ),
  '#description' => t('Should this node have a rating attached to it?'),
);

```

---
Tags: 7, nodes, hooks
---


# Question
Title: How to expose votings (such as in rate or voting api) to views?
To avoid the obvious misunderstandings: I know how to display the rate widget in a view, including the vote cast by the user, the average, sum etc. This is not what I'm looking for.

I want a view whose rows are the individual votes cast, with fields containing the information who cast the vote and what it was cast on and how much the rating was. When I create a new view, I can't select this kind of entity. How can it be done, preferably *without code*? (If at all)

# Answer
> 0 votes
Alright, I found a workaround by accident. Just add a new view that queries for the node bundle that the vote is attached to. No go to "Advanced" and add a relationship to "Rate" such that the relationship is required and not restricted to the current user. Don't apply any averaging or summing. Like that, it will spit out every node several times, once for every vote cast.

---
Tags: 7, views, rating
---


# Question
Title: How do I refresh a view (or a page) after a new comment has been posted?
I have a view that displays comments for a node. When user1 posts a new comment then that comment appears automatically in the view for user1. But for user2 viewing the same node, the new comment does not appear automatically without a page refresh (ie, the view does not get refreshed automatically).

I have tried to find an event in rules to trigger an event that could look like "refresh page" or "refresh view".

Any hint?

# Answer
> 2 votes
Try using Views Auto-Refresh module.

> A module to refresh a view after a specified time interval. Includes advanced options to avoid reloading the whole view, and to avoid causing a full Drupal bootstrap at each refresh.

If you are looking for REAL realtime update you should use some server side javascript like nodejs, to push event to the dom.

also there is nodejs module for Drupal.

A great tutorial

---
Tags: views, rules, comments
---