# Question
Title: How to set the time as 09.00 - 10.00 , 10.00 - 11.00 in day calendar view display?
I'm creating a calendar of event content types by using the date and calendar modules.

I already know how to customize the time grouping settings to set the time from particular time to the other (from Calendar: How to limit the range of hours in Days display?). Now I want to display the time as a duration like 09.00 -10.00 AM, 10.00 - 11.00 , 11.00 -12.00 , 12.00 - 1.00 format. I also don't want to display the times which don't have an event at the time.

For e.g :

1. Event one - 09.00 -10.00 Am
2. Event Two - 10.00 - 11.00
3. Event Three - 12.00- 2.00
4. Event Four - 04.00 - 06.00

I want to display this as :

1. 09.00 -10.00 - Event one
2. 10.00 - 11.00 - Event Two
3. 12.00- 2.00 - Event Three
4. 4.00 - 6.00 - Event Four

This is the result I'm trying to get from the day calendar view display. In the display, the time which doesn't have an event is not listed in the time column (e.g., from 2.00 - 4.00). Could anyone help me in this?

Thanks in advance.

# Answer
Ranjani, if you want to collapse all times which don't contain events for the day, then I don't think you really need to be using a day-calendar format? I think your best bet would be to just do a regular table display for your view.

1. Change your view to be a table format
2. Have the time range in one column and the event title in the other
3. To get the range in the first column, just display your date in two separate fields, the first time, display the 'from' time, in the second one display the 'to' time
4. Go into your field settings (screenshot) and select those date fields to be shown inline. You can then specify which character should separate the inline fields. Use a '-' in your case.

Does that get things close to what you were hoping?
> 2 votes

---
Tags: views, datetime
---


title: Allow Role to edit Custom Node Type

text:
# Question
Title: Allow Role to edit Custom Node Type
This is for Drupal 6.

I have a module that creates a custom node type called program. I have a role called "marketing" and it has a permission entitled "edit marketing copy"

I've used hook\_access to grant update permissions to users who meet this criteria, but the edit tab does not appear on the content when I view it.

```
function programs_access($op, $node, $account) {
    switch($op) {
        case 'update':
            if(user_access('administer programs', $account) || user_access('edit marketing copy', $account)) {
                return TRUE;
            }
        case 'delete':
        case 'create':
            if(user_access('administer programs', $account)) return TRUE;
    }
}

```

I know that the user has the permission because the view template shows specific things based on permissions and those work as intended. I just do not receive the "edit tab"

How do I make the edit tab appear on the page for the user? What am I missing?

# Answer
Check if the user has permissions to use that node's input filter.

If that is OK, try rebuilding the content permissions.
> 1 votes

---
Tags: 6, users
---


# Question
Title: How to programmatically set a custom field?
I am trying to programmatically change a custom field in a user object and I'm having very little success. I want to just use a function to set the field for the object, like `field_get_items`, except a setter version.

It seems like I could do:

```
$account = user_load($GLOABALS['user']->uid);

$edit = array(
    'field_custom' => array(
        'und' => array(
            0 => array(
                'value' => $lead_id
            )
        )
    )
);

user_save($account, $edit)

```

But there must be a better way to do this.

Any help would be appreciated. Thanks!

# Answer
Use the Entity module wrapper.

> The entity API provides some wrapper classes you may use to easily deal with entities and to leverage the entity property information modules provided. With the help of the wrappers you can access the property information, loop over known properties, or just get/set the described data values, etc.

Install the Entity module and do something like:

```
$user = user_load($GLOBALS['user']->uid);
$obj = entity_metadata_wrapper('user', $user);
$obj->field_custom = $lead_id;
$obj->save();

```

$GLOBALS is http://php.net/manual/en/reserved.variables.globals.php
> 9 votes

---
Tags: 7, entities, users
---


# Question
Title: Write a module to replace jquery with another js library
jQuery is great. But sometimes it's not exactly what I want. What would it take to write a module that could enitrely replace jquery with something like mootools or closure? Would this even be possible without hacking core modules?

# Answer
Theoretically you could use `hook_js_alter()` to remove all traces of jQuery (and any JS files that rely on jQuery) from the page build, and `drupal_add_js()` to add your replacement library/code.

Bear in mind that you would have to re-implement a *lot* of system/contributed javascript in your library of choice to maintain the same UI experience for your admins/users.

Also remember you'll lose access to jQuery UI so none of those widgets will be available until you provide an alternative in your new library.

All in all, it would be a lot of work to do this.
> 3 votes

# Answer
You cannot remove jQuery, but using other JavaScript libraries in parallel is not a problem.

You can add the library, and your custom JavaScript code with `drupal_add_js()`.
> 2 votes

---
Tags: javascript
---


title: Giving Blocks a Fixed Width

text:
# Question
Title: Giving Blocks a Fixed Width
Hello i am having a few problems with 3 menu blocks i have in a region of my theme. You can view this region on the main top of this page http://onlinebanter.com/latest

The top block just consists of 3 menu items and when you click one the child items appear (seperate menu block level). They appear to the right of the lower level menu block though.

Ive tried giving the first menu block a fixed width

.menu-block-14 { width:500px; }

To see if that will 'push the other menus down' but to no avail.

Can anyone suggest something for me to try?

thanks

# Answer
This should work:

.menu-block-12, .menu-block-14 { float: left; width: 100%; clear: both; }
> 1 votes

---
Tags: blocks
---


# Question
Title: Call to undefined function db_set_active()
I sure I have succeed to use these snippets in previous code, but now I get a "Call to undefined function db\_set\_active()" error. I don't understand why.

```
public function allUnits() {
  global $dbUtil;

  $list = array();
  $qryStr = "SELECT * FROM unit ORDER BY u_id";

  db_set_active('mpd_pro');
  $rs = db_query($qryStr);

  while ($row = $rs->fetchAssoc()) {
    $list[$row["u_id"]] = $row;
  }

  db_set_active('default');

  return ($list);
}

```

# Answer
> 1 votes
The 2 things that come to mind: your installation is not bootstrapping properly (improperly configured .htaccess or settings.php) , ***or*** you installation is corrupt.

I would recheck the apache logs, watchdog logs to see if any errors are mentionned, if all fails I would see if the application works with this module disabled, because this function is defined in core on line 2519 in `includes/database/database.inc` and should be available from all your custom module code.

Hope this helps, cheers!

# Answer
> 1 votes
If that code is called from hook\_exit(), then it can be called when Drupal bootstrap didn't initialize the database system.

In any case, calling drupal\_bootstrap(DRUPAL\_BOOTSTRAP\_DATABASE) would assure the database system is initialized.

```
public function allUnits() {
  global $dbUtil;

  $list = array();
  $qryStr = "SELECT * FROM unit ORDER BY u_id";

  drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
  db_set_active('mpd_pro');
  $rs = db_query($qryStr);

  while ($row = $rs->fetchAssoc()) {
    $list[$row["u_id"]] = $row;
  }

  db_set_active('default');

  return ($list);
}

```

If that doesn't help, then there is effectively something wrong. As stefgosselin said, it could be a configuration problem, or the database.inc file is corrupted, and `db_set_active()` is not found there. If the latter were the case, the site would be problems even when you try accessing the front page; the same is true if your site has problem bootstrapping.

---
Tags: database
---


# Question
Title: Making menu items active on desired page
I am creating a custom module for menus through which we can allow individual menu link to be active on desired path/paths. The module interface provides similar functionality as block module's visibility configuration.

I am using hook\_translated\_menu\_link() to implement the visibility functionality. As I have referred **menu item visibility** module for this, but not getting the desired output. Do i need to implement any other hook for this or I am missing out something. As I have implemented `hook_form_id_form_alter()` for the interface and `mymodule_submit()` for form submit functionality and right now trying out `hook_translated_menu_link()` for visibility functionality. I also have a database entry for my module.

# Answer
> 0 votes
The documentation for `hook_translated_menu_link_alter()` says:

> It is only invoked if `$item['options']['alter']` has been set to a non-empty value (e.g., `TRUE`). This flag should be set using hook\_menu\_link\_alter().

You need to also implement `hook_menu_link_alter()`.

As said by Lester Peabody, the functionality you want should be already implemented by the Context module. If the functionality it's not exactly what you want, you should implement `hook_translated_menu_link_alter()`, and `hook_menu_link_alter()`.

# Answer
> 0 votes
Is there a way you could make the Context module a dependency for your module and hook into the Context module to do this? Context already allows you to do this exact function. You specify conditions and reactions when those conditions are met, per context. In your case you would specify particular paths as conditions, and then your reaction would be to simply activate a particular menu item. I would seriously consider checking it out rather than reinventing the wheel.

---
Tags: hooks
---


title: Categorizing users

text:
# Question
Title: Categorizing users
Is there any way to categorize users in Drupal 7 so that one can browse users through a category (like users under "Seller" or "Buyer")?

# Answer
First of all create a taxonomy vocabulary, lets say 'User category'. Add the different categories.
Then, go to admin/config/people/accounts/fields and add a field with term reference to the 'User category' vocabulary. It depends on the case but you could set this as a required field in order to force users to set a category.
Then create a view of type 'Users'. Be sure to set format as a table and in the table settings field set the fields as sortable. Also add an exposed filter to filter only on buyers or sellers.
You can create a block of the view to show on the dashboard etc.
> 1 votes

# Answer
It's likely that you want to give different permitions to different usergroups. Therefore you're better off with creating different roles and put the users into the appropriate roles.

Every role has its own set of permitions.

1. Go to `admin/people/permissions/roles` and add the roles you need (seller, buyer).
2. Go to the user edit page and choose the roles it should have. You can assign a user to more than one role.
> 0 votes

---
Tags: 7, taxonomy-terms, users
---


# Question
Title: Template name convention for view mini pager
I'm trying to understand drupal's theming system and I thought I was doing quite well when, all of a sudden, I tried to create a custom template for the mini pager of the views module. I'm struggling to understand the right naming convention for the file, altough I've read alot during the past two days.

Here is what I've done: Test template name: myzen

* overridden the function myzen\_views\_mini\_pager in my template.php This works like a charm, the debugger hits the bps, if any.
* I tried to inspect the "Theme information" in the advanced section of the view edit page but I failed to see something related to the mini pager.
* I tried to follow this tutorial and I used the dprint trick to list the possible options and I found this: `Array
(
[0] => views_mini_pager__evento_view__block
=> views_mini_pager__block
[2] => views_mini_pager__default
[3] => views_mini_pager__default
[4] => views_mini_pager__evento_view
[5] => views_mini_pager
)`
* according to the tut and to what I found I tried to guess the template name, which should be: views-view-mini-pager--evento-view--block.tpl.php but this, obviously, fails. I tried like hundred of other combination (removing the block part, changing the - with \_, using only pager instead of mini-pager etcetcetc) and nothing worked.
* fun fact is that I can actually make a template for views-view--evento-view.tpl.php (which override the whole view, of course).

Can you help me in figuring out the right naming convention for the mini pager template in that specific block only?

Thank you!

# Answer
> 2 votes
After having Inspected the code more carefully and having read the whole resources I found again I finally found out the I bumped in one nasty corner case.

First of all, reading the code for the views module I found out that the tut I posted in my question was wrong and that the right naming convention for the template file is: views-mini-pager--evento-view.tpl.php (where evento-view is the name of the view).

Then I wanted to try and write a function template (instead of using the .tpl.php file) and I struggled again in finding the right naming convention. Since the views\_mini\_pager return with theme('item-list', ...) I tried to hook that for my specific view without any luck (mytheme\_item\_list would work, but changes the html output for every object using the 'item\_list'). I finally read more carefully Using the theme layer (Drupal 7.x) especially this:

> Drupal provides a few helpers to build complex HTML constructs easily. These are very useful features, and by using them it is easy to create a consistent look on tables and lists. The downside is that they are not readily accessible to a themer. Instead, they place code that should be at the presentation layer into the logic layer, and only advanced themers are able to do anything with it. These functions are more acceptable for administration pages. When creating output that is likely to be changed, it is best to avoid the use of these constructs and create the tables and lists with real HTML code. The forum themes are perfect examples of how to accomplish this and still create HTML code that is consistent. Function name suggestions with double underscores An even bigger problem with using common provided theme functions such as theme('item\_list') is that a theme probably does not want to override every theme\_item\_list() for every list output by Drupal anywhere, but only the one in our module. Therefore, instead of simply theme('item\_list'), we can use theme('item\_list\_*mymodule*\_main', $items) which would make it possible for a theme to implement themename\_item\_list\_*mymodule*\_main() or themename\_item\_list\__mymodule() to override item\_list() only for that specific instance.

So I made the mytheme\_views\_mini\_pager function in my template.php returning a theme('item\_list\__views\_mini\_pager') hook this with mytheme\_item\_list\__views\_mini\_pager and all worked like a charm

# Answer
> 0 votes
The theme developer is a very handy module when it comes to find the right theme method and template names. You can just point and click on the gui to get all possible names.

---
Tags: 7, views, paging
---


# Question
Title: What does menu blocks "Block title as link" option do?
The Menu block module has an option on each block titled "Block title as link". My interpretation of the description combined with some testing, is that if I leave the "Block title" setting out, the name of the menu will be used as the block title, and it *should* also be a link to the currently viewed menu item.

However, when I check the option and try it, I never get any links. I've been trying to follow the code, but I couldn't make any sense of it, so I believe my expectation on the functionality is wrong.

# Answer
For me it doesn't show the menu name, but the link to the parent menu item of the block. IE with a menu hierarchy like this:

```
<Main Menu>
-- a
---- b
------ c
------ d
------ e
-- f
-- g

```

If the block looks like this:

```
Title
c
d
e

```

Then having the block title as link makes the title a link to menu item b.
> 3 votes

---
Tags: blocks
---


# Question
Title: How to display photo properties (ISO, Aperture, Exposure, Shutter Speed) in Drupal 7
everyone! I know that every image contains specific information about itself( ISO, Aperture, Exposure, Shutter Speed). The problem is how to display them in the article of Drupal 7? Thanks!

# Answer
The exif module should get you going.

> The Exif module allows you to display Exif metadata on image nodes. Exif is a specification for the image file format used by digital cameras.
> 2 votes

---
Tags: media
---


# Question
Title: PDOException: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock;
I am getting the following error on my D7 site:

```
PDOException: SQLSTATE[40001]: Serialization failure: 1213
Deadlock found when  trying to get lock; try restarting transaction:
INSERT INTO {node} (type, language, title, uid, status, created, changed, promote, sticky)
VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2,
:db_insert_placeholder_3, :db_insert_placeholder_4,
:db_insert_placeholder_5, :db_insert_placeholder_6,
:db_insert_placeholder_7, :db_insert_placeholder_8); Array
(
[:db_insert_placeholder_0] => baby_clothes
[:db_insert_placeholder_1] => und
[:db_insert_placeholder_2] => Boys clothes and swing
[:db_insert_placeholder_3] => 1
[:db_insert_placeholder_4] => 1
[:db_insert_placeholder_5] => 1333240131
[:db_insert_placeholder_6] => 1333240131
[:db_insert_placeholder_7] => 1
[:db_insert_placeholder_8] => 0
)

in drupal_write_record() (line 6975 of includes/common.inc).

```

I have a module that saves nodes programatically on cron run. There is the possibiliy that two nodes could save simultaneously. Is that what could be causing this? The table locking mechanism is not working correctly to prevent collisions? If I put the site in maintenance mode and just run the batch of nodes to be saved, this never happens. Thoughts? thanks!

# Answer
This is a known issue in drupal 7.x core and has been resolved in the latest release (see this bug report for more information). Make sure you've upgraded to the latest version of Drupal 7, or try applying the patch if you need to get your site operational.
> 4 votes

# Answer
I was also having this problem. I realized there was some redundant data in the database. After deleting these, the problem is solved.
> 3 votes

---
Tags: 7
---


# Question
Title: Convert D6 user timezone offset to D7 timezone string
In Drupal 6 user timezones are stored as second offset, such as: -3600. In Drupal 7 it's the timezone string, eg: Europe/Berlin. I would to migrate users with their timezone setting to D7, but it's not obvious how to convert timezone offsets to strings.

My current solution is to create a full mapping table built from the timezone strings but I'm sure it's not the most elegant:

```
$d6_offset = -3600; // Input.
$zones = timezone_identifiers_list();
foreach ($zones as $zone) {
  $offset = format_date(time(), 'custom', 'Z', $zone);
  if (!isset($map[$offset])) {
    $map[$offset] = $zone;
  }
}
$d7_timezone = $map[$d6_offset]; // Output.

```

Do you know a better workflow?

# Answer
I would use the following code.

```
$map = array();

foreach (timezone_identifiers_list() as $zone) {
  if ($timezone = timezone_open($zone)) {
    if ($datetime = date_create("now", $timezone)) {
      if (($offset = $timezone->getOffset($datetime)) !== FALSE && !isset($map[$offset])) {
        $map[$offset][] = $zone;
      }
    }
  }
}

```

Keep in mind that the same offset is used for different timezone identifies. Showing just an identifier for each offset would be less useful for users.

For example, for Europe you would show the following list. (The list is partial.)

* Europe/Amsterdam 7200
* Europe/Athens 10800
* Europe/Dublin 3600

In your list, Europe/Rome, Europe/Madrid, Europe/Malta, and Europe/Kiev would not appear because the offset is already used for the three entries I shown.

A better code would the following one.

```
function mymodule_get_timezones() {
  $map = &drupal_static(__FUNCTION__);

  if (isset($map)) {
    return $map;
  }

  foreach (timezone_identifiers_list() as $zone) {
    if ($timezone = timezone_open($zone)) {
      if ($datetime = date_create("now", $timezone)) {
        if (($offset = $timezone->getOffset($datetime)) !== FALSE && !isset($map[$offset])) {
          $map[$offset][] = $zone;
        }
      }
    }
  }

  return $map;
}

```

As side note, I would not use `format_date()` if you use "custom" as date format, and you are not interesting in translating the returned date. In such case, the following code that is executed from format\_date() is extra, and useless, for you.

```
  // Encode markers that should be translated. 'A' becomes '\xEF\AA\xFF'.
  // xEF and xFF are invalid UTF-8 sequences, and we assume they are not in the
  // input string.
  // Paired backslashes are isolated to prevent errors in read-ahead evaluation.
  // The read-ahead expression ensures that A matches, but not \A.
  $format = preg_replace(array('/\\\\\\\\/', '/(?<!\\\\)([AaeDlMTF])/'), array("\xEF\\\\\\\\\xFF", "\xEF\\\\\$1\$1\xFF"), $format);

  // Call date_format().
  $format = date_format($date_time, $format);

  // Pass the langcode to _format_date_callback().
  _format_date_callback(NULL, $langcode);

  // Translate the marked sequences.
  return preg_replace_callback('/\xEF([AaeDlMTF]?)(.*?)\xFF/', '_format_date_callback', $format);

```

In the case I described, that code can be replaced with the following one.

```
return date_format($date_time, $format);

```
> 1 votes

---
Tags: 7, migrations, datetime
---


title: Separate frontpage per domain?

text:
# Question
Title: Separate frontpage per domain?
I have two sites, built in tanden but launched at completely separate points.

Both of them need *access* all content from both sites in some form, so that for example auto-completing references can be used across the two sites. For sake of brevity, I suggest exactly how *that* is done is kept out of this question.

The real difference between the sites, is that

1. One domain shows content types W and X, while the other domain shows Y and Z, they
2. Each domain has a completely separate front page.

**How would you go about solving the above two problems?**

# Answer
In my mind, the big advantage of using Panels is so that you can extend/alter sites like this in the future, without needing a lot of rework. In a lot of ways, Panels provides a framework for futureproofing sites.

While I am not sure if I have used Domain CTools,that is the first approach I would take. I essentially use a similar approach using Mobile Tools in combination with Domain Access for providing split desktop/mobile sites that share some, but not all, content and features.

The access rules that Domain CTools provides will show up in the visibility and selection rules inside Panels.

For the node pages, I would enable the default node override page inside Panels, and then make variants for each of my content types. I would then assign access rules to each, based on the domain.

For the home page, I would make a new custom page and set it as the home page. I would then make two variants, and make a selection rule based on the domain for each.

The other thing to think about is how nodes get used in places other than the node view page. For example, if you should double check your views and add access controls as needed. Assuming the approach outline above, you could also use the Domain CTools access rules. Depending on what other uses there are, you may need to investigate whether you need a custom `hook_node_access()` for your site.
> 2 votes

# Answer
One answer, requiring Panels (Everywhere), is to use an access plugin on content types as well as the site template and \<front\>, to provide varying experience depending on the domain.

There appears to exist a plugin called Domain ctools which provides this functionality.
> 0 votes

---
Tags: 7
---


# Question
Title: URL Alias Preventing a Pattern on Vocabulary
I am trying to setup a replacement pattern with URL Alias on a vocabulary called 'Media Categories' using the pattern 'media/\[term:name\]'. However whenever I try and generate the aliases this vocabulary is left unchanged. I have tried changing the pattern to something else like 'edia/\[term:name\]' and that works, it seems as though it is reserving the 'media/\[term:name\]' somewhere.

I have tried flushing the cache, deleting the vocabulary and terms and adding them again, however I have still had no success. The only option I have had so far is to manually enter the url alias.

Has anyone come up against something like this before? All I can think of is that 'media/\[term:name\]' is reserved somewhere...

# Answer
Ok thanks to Digital Fire, I started checking for other alias conflicts, which I found in my defined views. The problem I had initially was that the URL alias was working with views, however clicking on the link / taxonomy term took you too the default drupal view.

So in order to get the term with an alias working with view's I realised that in the view path use the original link to the taxonomy term instead of the url alias.

Hopefully that makes sense and might help someone else out.
> 1 votes

---
Tags: uri
---


title: Cannot configure the Antispam module

text:
# Question
Title: Cannot configure the Antispam module
So I've installed a new Drupal 7 on my server, and installed the "AntiSpam" module with Drush. (\[See Installing modules without FTP.)

I can't configure the module. When I open up the Configuration panel, I get an error message, saying:

> Akismet spam protection service requires a...

When I click on "Configure," I get dropped back to the Configure menu.

What did I miss? Drush didn't display any error message, and the module shows up in the modules page as enabled.

# Answer
The module asks for an API key, as the description for the "Akismet API key" field on admin/config/antispam says:

> Please, enter here your Akismet API key. If you don't have one already, you can get it by simply signing up for a free account at Akismet.com. Note that this information is required in order to use the Akismet Service. Please, consult the Akismet FAQ for further information.

Drush doesn't report any error because there isn't any error to report. Only after you enable the module you can see its settings page, where you need to enter the API key. Even if you installed the module using the browser, you should not have seen any message about entering the API key.

If you cannot access the setting page to set the API key, you can:

* Obtain the API key using the link I reported before
* Use Drush to set the Drupal variable antispam\_wpapikey

```
drush vset antispam_wpapikey $key

```

(Replace `$key` with the API key.)
> 2 votes

---
Tags: 7, drush
---


title: fetching user name

text:
# Question
Title: fetching user name
how to fetch user name and this types of information's as a php variable, which can be added as PHP code in block. As a example, a Welcome message like,

```
Hi, $data['user'] Welcome to my site

```

It's output should like this:

```
Hi, user name Welcome to my site

```

above code is not working but i think you understand what i want to do. Any idea?

# Answer
> 1 votes
The username is attached to the global `$user` object so you can get it like this:

```
global $user;
$username = $user->name;

```

And then output it like this:

```
print 'Hi, ' . $username . ' Welcome to my site';

```

---
Tags: users
---


# Question
Title: How to uninstall module if admin/modules path is not accessible due to memory error
The problem is - I installed ubercart and was playing with devel module. Now when I'm trying to go to admin/modules I'm getting:

> Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 8642561 bytes)

I would like to uninstall devel module because I think this is its fault, but I can't as I don't have access to admin/modules because of this error :/ . Is there another way to uninstall a module and free some memory?

**Edit:** Well, turning off some options in devel settings helped, but still it would be nice to know answer to this question as problem can potentially appear for someone :) .

# Answer
`drush dis MODULE-NAME`

* You can also disable modules manually in the database:

`UPDATE system SET status='0' WHERE name='module_name';`

Then you need to clear cached system list (Drupal 7 only):

`DELETE FROM cache_bootstrap WHERE cid='system_list'`
> 6 votes

---
Tags: 7, installation
---


# Question
Title: How do I disable some available countries in Commerce Shipping?
I am using Commerce Shipping and I need to disable all countries, except for Canada and the US. How do I make it so only those two are available in the Shipping Info on checkout?

# Answer
> 8 votes
Easy (assuming Drupal commerce 7.1 in my testing) - you want to just navigate to

Admin \> Store \> Commerce Profiles \> Profile Types \> Manage Fields \> \[Your Address Field\] \> Edit

Under 'Available Countries', select the ones you want per the instructions 'If no countries are selected, all countries will be available.'

You may also refine the list of available countries that appear in the above-mentioned 'Available Countries' selection list (and any other country chooser in a Drupal 7.x site) with the countries module.

# Answer
> 5 votes
Disable shipping contries under

admin/commerce/customer-profiles/types/shipping/fields/commerce\_customer\_address

---
Tags: 7, commerce
---


title: How to keep content out of features?

text:
# Question
Title: How to keep content out of features?
I have plenty of Panels pages that I track using the Features module. Currently, if I create put a Custom Content pane inside of a page, all of the content that is inside that pane is then stored in code.

If I make the custom content pane reusable or use a block instead, it is referenced by id. I don't want this behavior, either. For example, I create the block on my development environment, add it to my page, and commit my feature containing that page to version control. When I pull those changes into my test environment, the page is looking for a block with a specific id. Chances are the block won't exist, and I have to go create it. When I do that, though, there's no guarantee that my block will have the same id. Even worse, a block might already exist with that id, and the page will be using a block with completely unwanted content!

Blocks that are organized using the Context module rather than Panels have the same problem, I think.

I'm looking for a module or an approach that lets me reserve a space for content. I don't want that content to be kept in code (my feature) at all, but I do want the feature to know that my panel or context has a space reserved for that content. Modifying the content shouldn't cause the feature to show up as overridden.

Is there an existing module that allows for this functionality? If not, which module developers should I contact in order to get this sort of thing implemented? Or will a whole new module need to be created for this?

Maybe I'm misunderstanding the current behavior of these modules, even. Any help would be appreciated.

By the way, I don't think this is a problem that's specific to one version of Drupal, but if you have to pick a Drupal version to talk about, I'd say 7.

# Answer
So I opened some tickets with the relevant modules:

Unfortunately, it doesn't seem there's an elegant way to accomplish this at all.
> 1 votes

# Answer
Though I don't think this solves your problem of not wanting the content included in the feature at all, there are 2 ways that I know of to be able to create blocks that don't use numerical ids, and that can therefore be safely included in a feature.

1. Boxes
2. Beans

Personally, I prefer the Bean approach, since the Bean Bundles are fully fieldable, allowing to create very advanced types of blocks. Both of these modules however essentially allow you to create blocks that have machine\_names (feature proof) as opposed to numerical ids, which as you know are a royal pain in the ass when it comes to features integration.

EDIT: actually, now that I think of it, Bean does not create blocks with machine\_names - it uses numerical ID's. It is the Bean Types (think Content Types) that have machine\_names. So, if you want blocks with machine\_names, Boxes is the way to go.
> 3 votes

# Answer
I just read about a module that let's you do this, Bean Panels:

> Provides a ctools content type for bean module, allowing placement in panels.
>
> **Features**
> Loose coupling, enter your bean delta - the delta need not exist. If the delta does not exist and permissions are sufficient presents a link to add the bean. Pure separation from content and configuration - your panel is tied to a bean delta but the content does not have to exist.
> 0 votes

---
Tags: 7, features
---


# Question
Title: Aggregation and grouping with dates and integers
I am using Views along with Highcharts Module.

Here is my objective:

I have some integers that are contained in nodes 3 different integer fields to be exact. These integers occur over a duration of time and are entered on various days.

What I am trying to do is sum all the integers that happen on the same day.

Example:

```
Day 1 - 5/24/12

node #1
integer field: 10

node #2
integer field: 10

node #3
integer field: 10

node #4
integer field: 10

node #5
integer field: 10

Day 2 - 5/30/12

node #1
integer field: 20

node #2
integer field: 20

node #3
integer field: 20

node #4
integer field: 20

node #5
integer field: 20

```

Desired output of data for highcharts would be:

```
Day 1 - 5/24/12
integer field: 50

Day 2 - 5/30/12
integer field: 100

```

I have tried to use grouping and aggregation but I could not get a desired display. I could get all nodes to display but could reduced them down to the desired result.

Please let me know if I can clarify in any way or if this is even possible

thanks!

# Answer
> 0 votes
I was able to accomplish by setting my aggregation differently. I set it to sum and with value checked it began to work as documented. thanks. Let me know if anyone is having trouble with aggregation its kinda tricky getting to function properly thanks!

---
Tags: views
---


# Question
Title: CSS, Omega theme - how to make a <li> use 2 or 3 grids depending on screen with?
This question applies to Omega theme, but I think it is general to any responsive grid based theme.

Is there a method to make a `<li>` occupy either 2 or 3 grids, depending on screen width?

In other words, when the body tag has class `responsive-layout-wide` then the `<li>` should occupy 3 grids (as if it had omega class `grid-3`) and when the body has class `responsive-layout-normal` it should occupy 2 grids (as if it had omega class `grid-2`). (The body class is determined using media queries by Omega theme)

Currently the HTML looks like this:

```
<li class="mydiv grid-2-normal grid-3-wide"> </li>

```

At design time I don't know the screen width, so I applied both possible classes. So currently, despite of the screen width, the `<li>` width is always 3 grids because `grid-3` is added last. Does Omega have any tools to make it dynamic?

The origin of this question lays here: http://drupal.org/node/1571938, unfortunately it is not explained to the end. The Views Columns Class module says:

> So you can apply alpha to the 1st, 5th, 9th blocks and omega to the 4th, 8th, 12th blocks but also apply alpha-mobile to the 1st, 3rd, 5th blocks and omega-mobile on the 2nd, 4th, 6th blocks. **This gives the freedom to the theme to apply the styles that would render a display of 2 columns for smaller screen resolutions and 4 columns for larger screen resolutions.**

So, I will end up having multiple styles for a `<li>` (like e.g. `grid-2-normal` and `grid-3-wide`) and my theme is supposed to react to screen width and intelligently apply appropriate style to change the `<li>` width. Width measured in grids (columns), not in pixels. But how this can be achieved, how to *render a display of 2 columns for smaller screen resolutions and 4 columns for larger screen resolutions*? Where "display" means a view display, not the whole page layout (that's what I think)

# Answer
I don't know if Omega can do this out of the box, but I don't think so. Some base themes that use the grid system can change a size based on whether a column next to it is empty, but this isn't one of those conditions.

Your best option is to use the `grid-2` size in the config for that region, and then if you want it to be different, put an override for `mydiv` in one of the sheets that get enabled by the media queries (narrow, normal, or wide). In your case you would add something like

```
.mydiv { width: 280px; }

```

to yourtheme-alpha-default-wide.css The actual width will vary based on whether you are using 12, 16, or 24 columns, and you may need an `!important`, too.
> 0 votes

# Answer
Taken for the theme's page:

Omega allows for contextual layouts (different layouts/settings for various portions of a site) through integration with Delta and the Context module.

Never done it myself to guide you but I believe what you want can be achieved by using these 2 modules. The documentation is always the best way to start.
> 0 votes

---
Tags: theming
---


# Question
Title: How to allow user to use one exposed filter and select between two views
I am using the search\_api module with views as the back-end. Users will have the ability to search through two different kinds of content, and there will be two separate views (one for each content type) to power the search results. I want to expose **one** search box, but then allow the user to direct those search terms to one view or the other.

Here is a picture that should make my desire more clear:

If the user selects "songbook", then their search gets directed to the song view. If they select "blog", then their search is directed to the blog view. How do I accomplish this using views?

# Answer
Usually views with exposed filters use get params fx

```
example.com/view1?filter_a=search
example.com/view2?filter_b=search

```

If you create your own form then build the URL bases on input and search type it should work just fine. I don't think it will be possible to do a view selection with exposed filters.
> 3 votes

---
Tags: 7, views, search
---


# Question
Title: How to highlight only unpublished nodes in views result
I have a node view with bulk operation style which is available for only admin role. I would like to hilight only the unpublished nodes. It doesn't matter if just one of the fields or whole row of those nodes are hilighted.

I suppose I need to add special css class to unpublished nodes but how can I do that?

# Answer
in your views add fields:

1. Node: Published, options "Label" empty, tick "Exclude from display", "Output format" choose "True/False"
2. Node: Title, option "Rewrite the output of this field" write `[title]`
3. Make css class ".false {color:red;}" for "unpublished" in your theme .css file

make 2 and 3 to your vbo fields, add "Node: Published", and rearrange to be first top field
> 4 votes

---
Tags: 6, theming, views
---


# Question
Title: CCK doesn't find the Image module on Drupal 7
After successfully migrating from Drupal 6 to Drupal 7, I wanted to migrate my CCK fields to core fields. I downloaded CCK for Drupal 7, and its field migrate module.

However, for all of my image fields, I got this error:

> Missing field module: 'image'. This field cannot be migrated.

What is that module 'image' that is missing? There is no more imagefield for Drupal 7, as it is supposed to be part of core.

# Answer
Actually, the Image module is part of Drupal core. Enable it, and the error should vanish.

If you don't find the module listed between the modules, then you need to copy the Drupal files again on your server.

If the Image file is already present in your web server, it is enabled, and CCK keeps saying it cannot find the module, then open an issue report for CCK.
> 4 votes

---
Tags: entities
---


title: jquery is not adding a class

text:
# Question
Title: jquery is not adding a class
On my Drupal site, I have a simple jquery file attached to the theme. This file is added in preprocess\_node. The whole content of the file is as follows:

```
(function ($) {
  console.log("hello world");
  $('li').addClass('hello');
  $('div').addClass('hi');
})(jQuery);

```

Here is what happens when I run any Drupal page:

1. no javascript errors
2. the console shows "hello world "
3. in Chrome debug, div's do not have class "hi" and li's do not have class "hello"

I ran the same (without wrapper function) on jsfiddle for some basic html and the result was as expected, classes were added to div's and li's and can be seen in Chrome debug. So why is it not working in Drupal?

# Answer
> 5 votes
You need to utilize Drupal's JavaScript Behaviors functionality in order to ensure that your javascript is run after the DOM has loaded and that it will not conflict with other javascript in Drupal.

Try changing your JS file's code to this:

```
(function ($) {

Drupal.behaviors.myModuleBehavior = {
  attach: function (context, settings) {
    console.log("hello world");
    $('li').addClass('hello');
    $('div').addClass('hi');
  }
};

}(jQuery));

```

---
Tags: 7, javascript
---


title: DB error after upgrade interrupted

text:
# Question
Title: DB error after upgrade interrupted
I'm in the process of upgrading from Drupal 6 to Drupal 7 and the upgrade process terminated due to disk usage error.

I found out that ibdata1 occupies 98% of /var. So I decided to empty this file so I can have the space again and re-run the update.php, but I got bunch of SQL PDO error.

> PDOException: SQLSTATE\[42000\]: Syntax error or access violation: 1286 Unknown table engine 'InnoDB': SELECT name, value FROM {variable}; Array ( ) in variable\_initialize() (line 943 of /var/www/vhosts/drupal/includes/bootstrap.inc).

```
    mysql> show engines;
    ERROR 2006 (HY000): MySQL server has gone away
    No connection. Trying to reconnect...
    Connection id:    177
    Current database: drupal_drupal

    +------------+---------+----------------------------------------------------------------+--------------+------+------------+
    | Engine     | Support | Comment                                                        | Transactions | XA   | Savepoints |
    +------------+---------+----------------------------------------------------------------+--------------+------+------------+
    | MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance         | NO           | NO   | NO         |
    | MRG_MYISAM | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
    | BLACKHOLE  | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
    | CSV        | YES     | CSV storage engine                                             | NO           | NO   | NO         |
    | MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
    | FEDERATED  | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
    | ARCHIVE    | YES     | Archive storage engine                                         | NO           | NO   | NO         |
    +------------+---------+----------------------------------------------------------------+--------------+------+------------+
    7 rows in set (0.06 sec)

```

Do you have any idea?

# Answer
This solved my problem.

```
chmod 775 /var/lib/mysql

```
> 0 votes

---
Tags: upgrading
---


# Question
Title: How is DRUPAL_CACHE_PER_USER handled for anonymous users?
If a block is set to use `DRUPAL_CACHE_PER_USER` for caching, will the block be unique for each anonymous user, or the same for all anonymous users?

For reference from API docs: hook\_block\_info DRUPAL\_CACHE\_PER\_USER

Looking at `includes/common.inc` source it appears to be based on `uid`, so I'd assume it would use the same block for all anonymous users (`uid = 0`), but wanted to double-check in case I could use this instead of `DRUPAL_NO_CACHE` (doing geolocation-driven results in the block).

```
elseif ($granularity & DRUPAL_CACHE_PER_USER) {
  $cid_parts[] = "u.$user->uid";
}

```

*(lines 6084-6086)*

# Answer
> 2 votes
Yes. If a user is not logged in then uid is 0. So all anon users share the same user id.

I guess you will have to do your own caching, e.g. based on the IP address.

# Answer
> 0 votes
There is a option to "Cache pages for anonymous users" in Drupal 7.

Admin-\>Configuration-\>Performance Look in the Caching Group just below the Clear Cache button.

---
Tags: blocks
---


# Question
Title: Is there a table listing contributed modules that have been ported to Drupal 7?
To date I have found no quick way to determine which Drupal 6 contributed modules have been ported to Drupal 7.

Do you know of one, such as an automatically updated table that provides this critical site-building and version-selection information?

# Answer
There is the D6 Upgrade Status Module that will list what modules installed on your system have modules in the D7+ versions of Drupal.
> 0 votes

---
Tags: 7
---


# Question
Title: Views-How do i redirect to the same page after saving the comment?
Sorry Guys , i have an easy question!

i used views to create a page that contains a kind of content with comment!

the link is "http://mydomain/testpage"

but when i write the comment on the content which is displayed by the view, the system will go to the "http://mydomain/node/%"

how can i stay at the same page after i writting the comment in the view?

# Answer
> 0 votes
i think i fix the problem, i just use the page management and change the setting of the node view,give a content type variant and then user http response.

Problem fixed ~ if you have the same question, take a try!

---
Tags: views, comments
---


# Question
Title: Just migrated to pressflow and now users can't log in.. any ideas?
I just migrated to Pressflow (newly downloaded) from vanilla Drupal install, and all of a sudden users cannot log in. The page simply reloads, but there is no authenticated user.

I am getting the following errors when I flush the cache (and I got them after running update.php):

> Warning: Attempt to assign property of non-object in drupal\_write\_record() (line 3488 of /home/traders/public\_html/includes/common.inc). Warning: Attempt to assign property of non-object in drupal\_write\_record() (line 3488 of /home/traders/public\_html/includes/common.inc). Warning: Attempt to assign property of non-object in drupal\_write\_record() (line 3488 of /home/traders/public\_html/includes/common.inc). Warning: Attempt to assign property of non-object in drupal\_write\_record() (line 3488 of /home/traders/public\_html/includes/common.inc). Warning: Attempt to assign property of non-object in drupal\_write\_record() (line 3488 of /home/traders/public\_html/includes/common.inc). Warning: Attempt to assign property of non-object in drupal\_write\_record() (line 3488 of /home/traders/public\_html/includes/common.inc). Warning: Attempt to assign property of non-object in drupal\_write\_record() (line 3488 of /home/traders/public\_html/includes/common.inc). Warning: Attempt to assign property of non-object in drupal\_write\_record() (line 3488 of /home/traders/public\_html/includes/common.inc). Warning: Attempt to assign property of non-object in drupal\_write\_record() (line 3488 of /home/traders/public\_html/includes/common.inc). Warning: Attempt to assign property of non-object in drupal\_write\_record() (line 3488 of /home/traders/public\_html/includes/common.inc). Warning: Attempt to assign property of non-object in drupal\_write\_record() (line 3488 of /home/traders/public\_html/includes/common.inc). User warning: Duplicate entry '0' for key 'tmd' query: INSERT INTO blocks () VALUES () in \_db\_query() (line 147 of /home/traders/public\_html/includes/database.mysqli.inc).

Any help would be so so greatly appreciated! If I can't figure this out in next couple of minutes, I'll roll back to normal Drupal.

Thank you!

\**Edit: My admin account was already logged in after I ran update.php and is working fine. It seems like a problem creating a new session.

MORE INFO: When a user logs in, my log says "Session opened for XXXXX." but it's quite clear the account isn't logged in ($user-\>uid is not set)

# Answer
> 1 votes
Not sure if that's going to be of any help for you, but I had kind of similar problem - on staging site, after upgrade from Pressflow 6.16 to 6.26, users were not able to log in anymore - or actually, according to Watchdog, they were logged in, but still being redirected to log in form.

No warning like yours though, although I assume that in your case they we caused by your admin account already logged in.

At this time prod site was still running Pressflow 6.16.

What helped in my case was changing `$cookie_domain` value in `settings.php` file on the staging server, which "unlinked" staging and prod cookies.

Essentially, before both staging and prod sites were using the same `$cookie_domain` (let's say it was `mydomain.org`), and everything started to work fine after changing it to `stage.mydomain.org` on the staging server.

Perhaps the problem is with the different way of handling cookies, and once our Pressflow is updated on prod server too it will again work fine with the same `$cookie_domain`, but this is still to be tested and confirmed.

---
Tags: 6, users
---


# Question
Title: Validation message on Login form not shown
On /user/login, when I forget to enter the login credentials, and click on the submission button, no error message is shown as expected.

What problem might be causing this?

# Answer
> 2 votes
Look at the form id for login form. and then try hook\_form\_alter() in any custom module.

Add a submit callback or validation callback in which you can check for the empty fields yourself. According use `drupal_set_message()` to display the error message.

---
Tags: authentication-authorization
---


title: Site Configuration returns blank page

text:
# Question
Title: Site Configuration returns blank page
I have just updated the Internationalization and language\_dropdown modules successfully after Drupal asked me to. Having done that, the `site configuration` when clicked every time, returns blank page. Sometimes when I click it twice, it returns a screen with a table of PHP errors of the the l10n update. This is frustrating. I know that this is regarding the update I made. But a bit of searching indicated that this is because l10n\_update is still available in beta3 form.

# Answer
I would start by troubleshooting the horrid White Screen of Death. Once you find the culprit module/file/function/setting this should be much easier to fix.

You may also want to scope out the Language Dropdown bug list, the i10n\_update bug list and the i18n bug list.

If you will post back with details regarding the WSoD I'll do my best to update my answer.
> 2 votes

---
Tags: 7, i18n-l10n, wsod
---


# Question
Title: Getting first the terms starting with the string I am searching for
I am using Drupal 7. I add one vocabulary in taxonomy and I am using it as auto-complete in user's registration.

Now I have a problem with how it search.

When I enter *y*, it shows taxonomy terms containing *y*, but I wanted to first see the terms that start with *y*.

There is module to set this settings, but this module doesn't support Drupal 7.

How can get first the terms starting with the string I am searching?

# Answer
The Taxonomy Autocomplete Settings module has now a Drupal 7 version, and an official release (7.x-1.0).
> 3 votes

# Answer
I know a pretty easy way around this. (Actually 2).

First way is to update that module you linked to up to D7.

Second way is to create a small module, and use the D6 code needed for your autocomplete.

1. Create a D7 module skeleton, or a simple hello world module that can be found lying around.
2. Get your .info and .module file working.
3. Find the code in the module you linked that rearranges the autocomplete,
4. Rip it out. Ctr-c the %&% out of that old outdated D6 code.
5. Implement the same code in your module (hint: ctrl-v)
6. Don't tell anyone. Unless you ultimately *share* that code, then read the licences of the code you are using and give credits where due according to those terms.
7. Most important: Check the code you just ripped. Learn something out of it, if possible. See how it works, why it does it. If it can be improved, even.

Good-luck, just message me if you need further help on this.
> 1 votes

# Answer
Well since the answer stefgosselin gave is not really very helpful, cut and paste does simply not work. I built a module for drupal 7 and attached it to an issue, so if you want to test it or have questions or want to contribute check it out under:

http://drupal.org/node/1413974
> 0 votes

---
Tags: 7, taxonomy-terms, ajax
---


title: Creating a menu based on cck field

text:
# Question
Title: Creating a menu based on cck field
I would like to build a custom menu structure based on cck fields.

lets say I have 2 fields in which I will type the menu item.

* parent item = field\_category
* child item= field\_subcategory

So in a node create form i use for '**field\_category**' apples or pears and for '**field\_subcategory**' green or red.

These items will also be made terms(i have a 3rd field containing tags that are equal to all menu items)

**my menu structure is like:**

* apples
    + green
    + red
* pears
    + green
    + red

my terms are: apples, pears,red, gree.

Then part 2: These items must be linking to a term or multiple terms.

* apples --\> links to term apples
    + green --\> links to term apples AND green
    + red --\> links to term apples AND red
* pears
    + green
    + red

I suspect i wuould need a custom module to do so, but i am not a programmer...so I really hope someone has a solution with contrib.

# Answer
> 0 votes
If you're only concerned about taxonomy term fields, then I reckon that you should investigate the taxonomy\_menu or similar family of modules. In fact, looking at your other post, I suggest that you go through the entire list of taxonomy modules on Drupal in general :)

---
Tags: routes, entities
---


title: Is 'file path' required in hook_menu()?

text:
# Question
Title: Is 'file path' required in hook_menu()?
I just started learning Drupal 7 Module development. In a tutorial I watched, the person said that

> "In hook\_menu(), if we have a **'file'** attribute then the **'file path'** is a must and drupal wont work if it is not declared in drupal 7."

But when I read a book, it said that

> The **'file\_path'** is not required in drupal 7 provided that the file is present in the same directory.

As you can see, its a bit confusing. So my questions are

**1) Is 'file path' required in Drupal 7 ?**

**2) When to use 'file path' ?**

I've posted a snippet of the hook\_menu implementation :

```
function modulename_menu() {
  $items['...'] = array(
    ....
    ....
    'file' => 'modulename.admin.inc',
    'file path' => drupal_get_path('module','modulename'),
  );
  return $items;
}

```

**Note :** Assume that the file is present in the same modules folder

# Answer
> 2 votes
The first sentence you quoted is wrong. "file path" is not a must, if you set "file"; in fact, by default Drupal will take its value is the directory containing the module implementing the menu. If you want to use a different directory, such as `drupal_get_path('module', 'mymodule') . '/includes')`, then you can set "file path."

\_menu\_router\_build() contains the following code.

```
// Calculate out the file to be included for each callback, if any.
if ($item['file']) {
  $file_path = $item['file path'] ? $item['file path'] : drupal_get_path('module', $item['module']);
  $item['include file'] = $file_path . '/' . $item['file'];
}

```

`$item['module']` is set by menu\_router\_build() using the following code.

```
  foreach (module_implements('menu') as $module) {
    $router_items = call_user_func($module . '_menu');
    if (isset($router_items) && is_array($router_items)) {
      foreach (array_keys($router_items) as $path) {
        $router_items[$path]['module'] = $module;
      }
      $callbacks = array_merge($callbacks, $router_items);
    }
  }

```

A module could implement `hook_menu_alter()` to alter `$item['module']`.

# Answer
> 1 votes
> 1) Is 'file path' required in Drupal 7 ?

Required if file being included is not in module path. Its not mandatory if the file is included in the module itself.
file path: The path to the directory containing the file specified in "file". This defaults to the path to the module implementing the hook.

> 2) When to use 'file path' ?

When you want to include a file outside your module.

---
Tags: 7, routes
---


# Question
Title: can't import sql dump to new database for backup
i have a site on drupal. I want to make a copy of that site so as to be able to make changes to the site without the fear of loosing something.

I have problem with the database. I export it in spl format. The size is about 100 MB. When i try to import it to the newly created database it says it is in progress but nothing is happening. The import is not proceeding.

I tried to transfer each table separately but when i reach a table that it is 36 MB (locale\_sources) it shows it is in progress but nothing is happening.

Everything is done through phpmyadmin.

Can anyone suggest anything?

Thank you.

# Answer
> 2 votes
You can use mysql on the command line to avoid timeouts when updating big dbs.

Example:

```
mysql --password=yourpw --user=name --default-character-set=utf-8 db_name <your_dump.sql

```

See `mysql -?` or the manpage for more options.

# Answer
> 2 votes
Backup and Migrate module is a better option to perform site replication.

The features provided by this module are:

> 1. Backup/Restore multiple databases.
> 2. Backup to FTP/S3/Email
> 3. Drush integration
> 4. Multiple backup schedules
> 5. AES encryption for backups
> 6. Backup your files directory (with the Backup and Migrate Files module)

**NOTE:** Make sure you change the value of `upload_max_filesize` to anything `>100M` in your `php.ini` file (usually at line# 886)

# Answer
> 1 votes
If you want to avoid/or don't have access to commandline MySQL, then I suggest that you explore the export options in PHPMyAdmin. First, make sure that you are using the compression option: bzip/gzip are very good and should lead to a much smaller file. Secondly, try to avoid INSERT statements with multiple value sets - the longer the statement is, the more troublesome things get from an import POV.

In newer versions of PMA, these options should be hidden within the "Custom" export section.

# Answer
> 0 votes
Try big dump. I used it for importing databases of a 1-2 GB and it worked perfectly.

# Answer
> 0 votes
Personally, I can't stand phpMyAdmin, and prefer to keep Apache out of the picture when doing database maintenance.

I prefer the MySQL GUI Tools. They are at end-of-life, but they still work well.

With these, you can take and restore backups with MySQL Admin. You can also schedule backups with it, too. The tool will restore backups taken via other methods if you tick the "Ignore Errors" option.

I wouldn't be surprised if you are getting silent "Packet too large" errors, and need to adjust `max_allowed_packet`. That is a frequent problem with backups on Drupal systems.

Once I have a good value set to `max_allowed_packet` set, I have used MySQL Admin to take and restore 2G catalogs.

It may also be worthwhile to configure your backup to include the `CREATE` statements for the cache tables, and the watchdog table, but not include the actual data.

Also, if you are not using it already, take a look at the Backup and Migrate module, which makes taking and restoring backups a snap, and includes the options to exclude cache and watchdog data.

---
Tags: database, importing-exporting
---


# Question
Title: How can I specify required fields when programmatically loading a node creation form?
I'm building out a custom workflow. Newly registered users can create a node that has several fields - some of the fields are required, others are pre-filled, and others are disabled. The benefits for having 1 content type to handle this greatly outweigh the negatives.

Fields that I set the `#default_value`, `#access`, or any other FAPI attribute on are working properly, but fields where I set #required = TRUE are **not** validating and are **not** stopping the node from being created!

Here's my code:

```
function my_custom_callback($arg) {
  module_load_include('inc', 'node', 'node.pages');
  $page['node_form'] = node_add('content_type_name');

  if ($arg == 'foo') {
    $page['node_form']['field_favorite_color'][LANGUAGE_NONE][0]['value']['#required'] = TRUE;
  } else if ($arg == 'bar') {
    $page['node_form']['field_favorite_food'][LANGUAGE_NONE][0]['value']['#required'] = TRUE;
  }
}

```

If I visit this page with `$arg = 'foo'`, I can submit this form without entering anything in `field_favorite_color`, even though this field shows the red asterisk and has the class 'required' and is showing as `#required = TRUE` in the form's render array when I do a `dpm()` within the callback function.

Why won't Drupal require that this required fields be filled out? Do I need to rebuild the form somehow after I've altered the fields? If I set the same code in a `hook_form_alter()` then it works as expected, but in that case I don't have the control that I get through my custom callback to lead the user through a multi-step workflow.

**Edit:** This is Drupal 7. Tried adding that tag but am seeing 'drupal-7' and 'drupal7' tags are not allowed.

# Answer
In short, to answer your question "*How can I specify required fields when programmatically loading a node creation form?*" ... use hook\_form\_alter() and keep your sanity! :)

Here is what I ended up doing after toying with a bunch of proposed solutions I ran across wile learning hook\_form\_alter() and Drupal's Form API.

I'm sure this solution could be massively improved, but this worked for me and it seems to be fairly simple to manage/maintain.

**Managing a Single Content Type With a Complex Workflow Using Node Edit Forms**

First after hours of debugging, I decided not to use a custom callback. Instead I edited the built in node add/edit form using nothing more than hook\_form\_alter(). (I like hook\_form\_FORM\_ID\_alter() instead of hook\_form\_alter() as it helps me keep my code organized. A personal preference for sure.)

> Note: Drupal 7 use the Administration theme by default for creating new nodes/content. You can get around this by unchecking the '***Use the administration theme when editing or creating content***' field at the bottom of 'admin/appearance' page in the admin panel.

**Using the Rules Module To Keep Track Of Workflow Stages**

I added a new field called "workflow" to my node type (Added through UI at: http://example.com/admin/structure/types/manage/%content\_type%/fields) so I could keep track of what stage the user was currently at.

My workflow field ($form\['field\_workflow'\]) was a select list with predefined options (stages).

```
 'new' => 'New', //Default Value For New Nodes
 'foo' => 'Foo',
 'bar' => 'Bar'

```

I used the Rules module to move the workflow along. Rules allowed me to move a bunch of the 'submit function' code into rules configuration. This made updates simpler as I don't need to make as many module edits.

Rules makes it very simple to do things like 'if the node is new, set the workflow to *foo* after saving' or 'if the workflow is set to *foo*, set the new workflow state to *bar* after saving.'

**Organization: Ugh... Setting Up The Actual Flow**

First I tried to keep each stage of the workflow as clean as possible by packing alterations in their own functions with a custom naming convention.

```
function MODULE_stage_new(&$form) {
    //Insert all alterations here for use when node has not yet been saved. It's new!
    $form['field_favorite_color'][LANGUAGE_NONE][0]['value']['#access'] = FALSE;
    $form['field_favorite_food'][LANGUAGE_NONE][0]['value']['#access'] = FALSE;
}

function MODULE_stage_foo(&$form) {
    //Insert all 'foo' stage alterations here.
    $form['field_favorite_color'][LANGUAGE_NONE][0]['value']['#required'] = TRUE;
}

function MODULE_stage_bar(&$form) {
    //Insert all 'bar' stage alterations here.
    $form['field_favorite_food'][LANGUAGE_NONE][0]['value']['#required'] = TRUE;
}

/**
* Implements hook_form_FORM_ID_alter().
*/
function MODULE_form_FORM_ID_alter(&$form, $form_state) {
    /**
    * Place any alterations here that apply to all stages here before the
    * 'if' statements below.
    *
    * I generally place my validation callbacks and CSS additions here.
    **/

    if (empty($form['nid']['#value'])) {
        MODULE_stage_new($form);
    } else if ($arg == 'foo') {
        MODULE_stage_foo($form);
    } else if ($arg == 'bar') {
        MODULE_stage_bar($form);
    }
}

```

Now that hook\_form\_alater() is being used exclusively without a custom callback, you shouldn't have any issues with the `['#required']` elements.

Occasionally I would have to add an '#after\_build' function (yea, yet another function to keep track of...) but did so with a common naming convetion. For example, if I needed to add a new stylesheet at the 'foo' stage I would use the following functions.

```
function MODULE_stage_foo(&$form) {
    //Insert all 'foo' stage alterations here.
    $form['field_favorite_color'][LANGUAGE_NONE][0]['value']['#required'] = TRUE;
    $form['#after_build'][] = 'MODULE_stage_foo_after_build';
}

function MODULE_stage_foo_after_build($form, &$form_state) {
    drupal_add_css(path_to_theme() . "/css/foo.css");
    return $form;
}

```

I hope this wasn't too overkill or off topic. I honestly found that sticking to hook\_form\_alter() for node add/edit form modifications saved me a ton of headaches over how I was trying to do it before. The custom callback method using `module_load_include('inc', 'node', 'node.pages');` never worked for me the way it seemed to for people writing the examples I found. Then again, I'm still pretty new to Drupal. :)
> 3 votes

# Answer
One answer **(that I really hope is not the correct one!)** to this is to have my custom callback remain in charge of the node creation form's appearance:

```
function my_custom_callback($arg) {
  module_load_include('inc', 'node', 'node.pages');
  $page['node_form'] = node_add('content_type_name');

  if ($arg == 'foo') {
    // do something informative to the user.
  } else if ($arg == 'bar') {
    // do another thing informative to the user.
  }
}

```

and then set my requirements and general form alterations in `hook_form_FORM_ID_alter()`, but this means I'm spreading my code out in 2 places **and** I've got to look in the `arg()` function to see what the user's workflow state is, which is generally messy.
> 0 votes

---
Tags: 7, forms
---


# Question
Title: How to create a related page or content type with in an existing custom content type?
I have created a custom content type that is a product page. It takes various pieces of information relevant to creating a software product page. For example the products Name, System Requirements, and features and builds a custom page for each piece of software that I may make.

The issue is that I have a product page, and several ways to obtain the software:

1. Potential Trial version download from my site directly.
2. Link to Purchase from the Mac App Store,
3. And a link to Purchase it from a FastSpring store.

I am Trying to find a nice way to conceal that all behind one button on my product page, so that I do not have to clutter my Product page with 3 links to various ways to obtain the product. I just want to have a button "Get Product" that can load a separate page or equivalent.

What are some ways to do this in a semi automated way so that it can happen when I create a new product page and then have Drupal also make another page or something that I can fill in with links that I know to acquire the product?

Because I really don't want to manually make two separate content types one for the product and one for the product downloads links and then have to manage a releationship between them for all products. Trying to make it so that the ways to obtain the product are included in the product page content type in an elegant way.

# Answer
> 1 votes
If your concern is merely visual, you can use Fields to separate the different buying options then use Field Groups to separate them using, for instance, an accordion. You could then use javascript to control/open/close the items on the tabs.

---
Tags: 7, entities, nodes
---


title: Load module in a drush script

text:
# Question
Title: Load module in a drush script
I have a Drush script that I am running from my Drupal environment which loads a particular module that I want to get access to. Particularly, I want to use one of the functions it has defined in one of it's included files.

I tried just calling the function in my script, but PHP fails with an error citing an undefined function.

I am running the script as follow:

```
drush php-script ~/path/to/script.php

```

And this is my script in its entirety right now:

```
<?php
    $val = biblio_get_contributor(1);

    print_r($val);
?>

```

`biblio_get_contributor($aid)` is most definitely defined in the module.

So to sum up, I need to get this module's functions loaded somehow. Thoughts?

# Answer
> 5 votes
The `biblio_get_contributor()` function is located in the includes/biblio.contributes.inc file. The file isn't automatically included by the module unless it needs it, which is probably why you're getting that error.

You can include it into a page build explicitly with the following:

```
module_load_include('inc', 'biblio', 'includes/biblio.contributors');

```

---
Tags: 7, drush
---


# Question
Title: Are there any contributed/commercial themes available for Open Atrium?
Googling "Open Atrium Theme" doesn't yield very many results. I have a sinking feeling that most people who install Open Atrium stick with Ginko for the theme.

Are there any contributed themes out there for Open Atrium or Commercial Themes?

# Answer
> 5 votes
Here's a bunch of them (scraped from Google cache, it seems the original page is no longer available):

If memory serves I've had Miro installed before with good results.

---
Tags: theming, distributions
---


# Question
Title: String Override limited to certain pages?
I'm using the Fivestar module on different areas of the site. It displays "x votes" below the rating widget.

On some areas on the site it would like to change "votes" to "reviews". How could I do that?

# Answer
The 'votes' text seems to be hard-coded into the `theme_fivestar_summary()` function (around line 264 of 'includes/fivestar.theme.inc'). It is run through `format_plural()` (so will eventually make itself available to string overrides), but I don't know of a way of defining complex conditions/contexts for string overrides.

The only (easy) way I can see to solve this is to re-implement that theme function in your own theme, copying the full function code from `theme_fivestar_summary()` to `MYTHEME_fivestar_summary()`, and introducing a contextual condition to alter the specific text that you want to change.

You'd be basically looking at changing these lines:

```
if (isset($votes) && !(isset($user_rating) || isset($average_rating))) {
  $output .= ' <span class="total-votes">'. format_plural($votes, '<span>@count</span> vote', '<span>@count</span> votes') .'</span>';
  $div_class = 'count';
}
elseif (isset($votes)) {
  $output .= ' <span class="total-votes">('. format_plural($votes, '<span>@count</span> vote', '<span>@count</span> votes') .')</span>';
}

```

to:

```
$context = MYTHEME_get_fivestar_context();
if ($context == 'something') {
  $metric = 'review';
}
else if ($context == 'something_else') {
  $metric = 'vote';
}

if (isset($votes) && !(isset($user_rating) || isset($average_rating))) {
  $output .= ' <span class="total-votes">'. format_plural($votes, '<span>@count</span> ' . $metric, '<span>@count</span> ' . $metric . 's') .'</span>';
  $div_class = 'count';
}
elseif (isset($votes)) {
  $output .= ' <span class="total-votes">('. format_plural($votes, '<span>@count</span> ' . $metric, '<span>@count</span> ' . $metric . 's') .')</span>';
}

```

It's not particularly pretty, but I think it's about the most efficient way to do it.
> 1 votes

---
Tags: 7, string-overrides
---


# Question
Title: How can I scrape data from the web into drupal?
I want to scrap location data from google. So for example; If I search for "Restaurants in Miami". I get over 14K results. I reviewed; How to import Nodes and Node Location data using Feeds module?. But that doesn't really help me with importing a query term from google.

1. How would I be able to scrap each one of the locations that the query gives as a result and import them as a node into drupal?
2. Are there any pre-built modules that might assist in this process?
3. I'm I going to need to build a custom module for this use case?

UPDATE: I've found this page; http://drupal.org/project/example\_web\_scraper and will studying the info to see if this is what I'm looking for.

AH HA MOMENT:

# Answer
Not to put a damper on things (I've written more scrapers than I care to remember and it's always fun), but such an act is specifically against Google's Terms of Service:

> Do not misuse our Services, for example, do not interfere with our Services or try to access them using a method other than the interface and the instructions that we provide.

I'm sure you'll be ok if you're doing this for fun/educational purposes (don't take my word for it though, I'm not a lawyer!), but if you make something commercial out of this you could find yourself in a tricky position.
> 5 votes

---
Tags: 7, location
---


title: How to add a term image to node

text:
# Question
Title: How to add a term image to node
I have a nodes, and a few vocabularies to choose terms from. I would like to show images of terms from specific vocabulary in nodes (If node is associated with term from specific vocabulary, it would show image from that terms field). What would be the best (most "Drupal") approach to this? :)

# Answer
> 14 votes
One way to do it -- if you don't want to create/mess with the theme template files for your content type, would be to display the corresponding tag image via a view.

Here are the steps to doing that:

1. I'm assuming you already have your vocabulary set up properly and you have the image field added to it (can be done at admin/structure/taxonomy/\[YOUR VOCAB ID\]/fields) and some terms have been populated with their corresponding images.
2. Create a new view with a block display, and set it to apply only to the relevant content types
3. Add a term relationship to your view, so you can access the vocab/term fields, and not just the node fields!!
4. Once you've done that, go into the fields you want to pull for each node. I'd remove the 'Title' field that's added by default and only add the field that represents the image associated with your term. It should be somewhere under the 'Taxonomy term:....' section of the field list.
5. Make sure that you set it to use the relationship you created above
6. Finally, since we'll want this block to take its cue of which image to display based on which node it's on, let's add a contextual filter. Under the 'Advanced' section --\> 'Contextual filters', add the 'Content: Nid' one and make sure you set it up to take its NID from the page it appears on if a filter isn't present in the URL
7. All done! Go to one of the relevant pages and test. Of course, you'll have to enable the block via contexts or the block admin page (admin/structure/block) first, since it's not placed anywhere by default. Display the block on the second sidebar, in the actual content section -- anywhere you want.

Let me know if this helps!!

================ EDIT ===================== Solution 2 (upon request)

To do this through your template file, go ahead and copy your regular node.tlp.php file and rename it node--\[YOUR CONTENT TYPE MACHINE NAME\].tpl.php

Then, right under or above the content, insert the following code:

```
$term=taxonomy_term_load($node->field_thats_term_reference['und'][0]['tid']);
$image_field=field_view_field('taxonomy_term', $term,'field_main_image');
print render($image_field);

```

Just substitute 'field\_thats\_term\_reference' with the name of your term reference field, and substitute 'field\_main\_image' with your image field name.

That'll do the print out. You can place this anywhere you want. If you want to customize how the print out actually looks, just do a dpm($image\_field) once you've set that variable (must have the devel module installed), and you can see all the parts of that field and how to get to them if you want to print them out separately as opposed to the default way render() prints it all out. I think that part is beyond the scope of this question, but it should get you started!

---
Tags: 7, nodes, taxonomy-terms
---


# Question
Title: What will happen if I restore backup DB with empty session table?
It seems that only the session is really big compared with other tables.
Is there any bad effect to Drupal site if I restore my backup Mysql file after deleting all the rows in session table?

# Answer
> 2 votes
The main issue is that people will need to log in again.

A side effect of this is that any session data that your site may have saved for users will also be gone. This is usually a nuisance, and not a major problem, though.

Personally, I have never had any problems caused by either not restoring `{sessions}` or manually clearing out the table, either via `DELETE FROM {sessions}` or a drush command.

---
Tags: 6, database, sessions, backups
---


# Question
Title: Where is the Profile2 field data hiding?
I created a couple of different profile types in Profile2. I then register new accounts through /admin/people/add user (my-profile-type). All of my custom fields show up, and I enter the data accordingly. However, when I go back to the user's profile to edit it, the data isn't there.

Am I missing something obvious? Another post here said there was a button in the admin that gives access to the profile2 fields - but I don't see anything like that?

# Answer
> 2 votes
Each profile type comes up as a second-level tab on the user edit page, like this (using admin theme):

'Parent Information' is a profile type, and the 'Account' link is for the normal edit page.

If those tabs are missing from your theme I'd have a look at page.tpl.php to make sure you're outputting the tabs correctly.

---
Tags: users
---


title: Drupal path linking to wrong content

text:
# Question
Title: Drupal path linking to wrong content
I have a content type for news. All my news nodes use the pathauto path: "node/\[title-raw\]". However, when I click to go to view any of my news items, instead of displaying the news item, the page displays a newsletter that was created using Simplenews. None of the normal Drupal content codes is being added. It's like it's just viewing a basic HTML page of the newsletter. Something is going wrong with the paths.

It seems like this newsletter has taken over all paths beginning "news...".

I'm not sure where to start looking for the problem. I would be grateful for any suggestions anyone has.

To see what I mean you can see the website at www.signamic.co.uk, and then click on any of the news items near the bottom.

Thanks in advance,

Ben

# Answer
@citricguy exactly - seems that any URL you type after /news/ ends up showing your newsletter.

You probably have an index.html file there with that content.

Example:

http://www.signamic.co.uk/news/something-that-should-not-exist

Gives the same output as:

http://www.signamic.co.uk/news/full-time-pacourse-adminstrator-vacancy

Check your folder structure in root and .htaccess file.
> 0 votes

---
Tags: 6, path-aliases, uri, emails
---


# Question
Title: How to break up long words in a views display?
I have a "related discussion" block view. Long words like links are breaking my layout.

Is there a way to force line breaks on those long words?

I could limit the length of links that then they wouldn't be as useful.

**Update:** Turns out that the CSS doesn't work across all browsers and also wraps regular words in funny ways sometimes.

Is there a way to do this in Drupal?

# Answer
There are no universal solutions to this issue. But the currently acceptable ones are to use the `wbr` HTML tag (perhaps with some JS), or to, as you have seen, use `break-word` (as opposed to Chrome's break-all) along with some fallbacks. Both of these solutions are proposed here. Drupal.org uses or used to use the `word-wrap: break-word;` solution.
> 4 votes

---
Tags: views, theming
---


# Question
Title: SimpleTest clicking one of multiple "Add Another Item" buttons
I'm attempting to test a node's form that has multiple fields that allow arbitrary numbers of entries. As such, there are several "Add Another Item" entries. In the SimpleTest docs (I think, I may have found it somewhere else ... code samples or something) it has examples for how to trigger the click of the Add Another Item button. Something like this:

```
$this->drupalPost(null, array(), t('Add another item'));

```

The trouble with this is that is targets the value of the field and the value is not unique across the page. In the docs it also suggests that you can pass in an array as the third parameter to drupalPost:

```
$this->drupalPost(null, array(), array('path' => '', 'triggering_element' => 'something_add_more');

```

Unfortunately I don't know what to set the path to. The default doesn't work (/system/ajax I believe) and I don't know what path drupal is using to trigger the ajax request to begin with when you manually click the button (if it's ajax at all).

I have also tried just passing the id or name of the button as the third parameters with no luck.

So here's my question: How can I uniquely select any one of the "Add Another Item" buttons found on the page from within the SimpleTest environment?

# Answer
I think FileWidgetTestCase::testMultiValueWidget() should be useful as an example.

As you can see there, only drupalPostAJAX() supports to target the actual button based on the name, for drupalPost(), they actually mess with the HTML source ($buttons is a xpath result that can be altered).
> 2 votes

---
Tags: ajax, testing, entities
---


# Question
Title: What operators and functions can I use in a Views "Global: Math expression" field?
When you create a "Global: Math expression" field in Views, the following help appears beneath the Expression field:

> Enter mathematical expressions such as 2 + 2 or sqrt(5). You my assign variables and create mathematical functions and evaluate them. Use the ; to separate these. For example: f(x) = x + 2; f(2)

I tried to use a modulo operator (%), but it didn't work, and the function specified in that help is obviously not vanilla PHP.

What syntax or language is allowable in this field?

# Answer
Views Math expression fields use a custom expression parser in the Chaos Tool Suite (ctools) module. The code for this is contained in `ctools/includes/math-expr.inc`.

As of mid-July 2012, the built-in functions are:

```
'sin','sinh','arcsin','asin','arcsinh','asinh',
'cos','cosh','arccos','acos','arccosh','acosh',
'tan','tanh','arctan','atan','arctanh','atanh',
'pow', 'exp',
'sqrt','abs','ln','log',
'time', 'ceil', 'floor', 'min', 'max', 'round'

```

Most of these are PHP's own math functions. The trigonometric functions beginning with "arc" are aliases to the ones beginning with "a". "ln" is an alias for "log".

The built-in operators are `+` `-` `*` `/` `^`

The first four act just as they do in PHP. The fifth is the exponent operator; `x ^ y` is the same as `pow(x,y)`.

You can create your own functions using this syntax, and such functions can use more than one variable. You can use this to create your own modulo function:

```
mod(x,y) = x - (floor(x/y) * y);

```

(Beware: The above function does not work with negative numbers.)
> 9 votes

---
Tags: views, chaos-tool-suite
---


# Question
Title: Set field_id for views "Global: Custom text" field
I have a view with several '**Global: Custom text**' fields. These are actually just serving as place-holders, and I'd like to create a field template file for each, that essentially places some custom html/php when it encounters these fields in a view.

Almost everything is in place and working... except, I notice that Drupal automatically gives the id of '**nothing**', '**nothing\_1**' etc to its global custom text fields. So, if I have more than one of these global text fields and would like to create a separate field template for each, I'm presented with a problem.

I'd have to name my template files **views-views-field-nothing.tpl.php** etc. This is undesirable, because I want to reuse these field templates throughout my site. I shouldn't have to worry about ordering these global fields just so in my views, so that the one I expect to be nothing is 1st and gets that id and the one that I expect to be nothing\_1 or nothing\_2 gets that id...

Has anyone run into this issue before? Any ideas whether I can set my own field-ids for global custom text fields in views, so they don't all have those generated id's? Is there a module that does this out there? My searching hasn't found anything yet.

Thanks for any guidance!

p.s. The reason I'm doing this is because I'm trying to put some html in my view (like \<fieldset\>) that is getting stripped from the views fields, so I need to do it in a template file.

# Answer
> 3 votes
Well, sometimes the only way to solve a hard problem is to write your own module (or, as in my case, just collaborate with someone who's already writing such a module).

I'm now using the newly-launched Views fieldsets module to achieve what I was trying to do!

# Answer
> 2 votes
I am not sure if this is a good solution, but I came across the same issue with those template file suggestions. What I did was work around it:

1. hide all fields by checking "Exclude from display" on each.
2. add one 'Global: Custom text' field at the end of the field list put the \[fields\] into the HTML structure you want
3. Remove or override field & wrapper style settings

May be a solution for you? Another replacement for 'Global: Custom text' field is to use the views\_php field.

---
Tags: 7, views, theming
---


title: Can't add menu items to new menu

text:
# Question
Title: Can't add menu items to new menu
I get a message: your configuration has been saved, but when I look at list links it says no links have been added.

I found a similar question and tried the answers to no luck.

I added a new menu Login Menu which worked fine and shows up with the other default menus. I created a page content to serve as my login page for the site. When I try to add a link to my new Login Menu it says it has been saved, but it does not show up.

My objective is to move the User login block to show only on it's own page. So I need a menu for anonymous users to go to for logging in.

# Answer
The problem was with the hierarchical menu module 7.x-3.0-alpha5. Although no error is created when trying to add a new item to a menu, an error is generated when adding new content with a menu link. This error allowed me to search for a solution.

I disabled the module and was able to add a new menu item to my new menu.
> 1 votes

# Answer
Try clearing the menu cache: menu\_rebuild().

In Drupal 7 go to: Administration -\> Configuration -\> Development -\> Performance and click "Clear All Caches" (example.com/admin/config/development/performance if clean URLs are enabled)
> 0 votes

---
Tags: routes
---


# Question
Title: How do you make an existing variable (from a module) available for use in my__node.tpl.php? D7
The contrib module i'm using (media gallery) outputs a block with a single thumbnail used to trigger a lightbox gallery.

The module has a tpl file used to render the thumbnail.

I want to isolate the single block thumbnail image ($media\_gallery\_item used in media\_gallery\_media\_item\_thumbnail.tpl.php) and insert it directly into a new node template (node--media-gallery.tpl.php)so that I can float the image in the body field (and preserve the lightbox trigger).

This is my first attempt at using a preprocessor. Incidentally, I posted in the modules issue queue two weeks ago. I'm posting here as well to hopefully get a quicker response.

# Answer
> 1 votes
The only variables different template files have in common are the ones returned from template\_preprocess(), or `hook_preprocess()`. See also \_template\_preprocess\_default\_variables(), which defines the default values for some of those variables.

---
Tags: theming, media
---


# Question
Title: Is there any way to export user account information and content profile together?
I need to export all the information of a few user accounts and relevant content profile nodes together per user. It doesn't matter what format it should be but I'll eventually import back to the same site.

It seems that View Bulk Operation does the job but in the Views I must include all the profile fields,CCK fields and all the rest of the information the account and the node has. So it's just not realistic in my case.

Is there any way I can export all the data that belongs to one user ?

# Answer
> 2 votes
I would still go with Views, unless you want to do it in your own custom module as suggested in the other answer.

There is Profile CSV, but this is limited to user accounts and core profile fields. There was a feature request for Content profile, but that issue wasn't finished, and in fact a Views-based approach was also suggested in that thread.

You can build a view of user account fields and related CCK views using Views relations, and export to CSV using the Views data export plugin. (And you can later import CSV via User import).

I believe any solution other than Views requires coding.

# Answer
> 0 votes
Try with custom module as it will be easier for you to tune the output. Loading users/nodes is not hard (user\_load and node\_load functions) and at the end it might take you less time than to play around with contributed modules.

---
Tags: 6, views, users, backups
---


# Question
Title: Privatemsg overwrites page title for custom code. How do I correct it?
I am using Private message as PHP in a block on the node of a page so that a person can contact the node author without having to leave the page. Here is the code:

```
$node = menu_get_object();
if ($node->uid != 0) {
module_load_include('pages.inc','privatemsg');
  $recipients = $node->uid;
print "<div>Contact " . $node->name ." about this post.</div>";
  $subject = $node->title ." question.";
  print drupal_render(drupal_get_form('privatemsg_new', $recipients, $subject));
}

```

However, Private message hijacks the title of the entire page, and now every single node value is 'Write so-and-so' a new message, instead of what the page title should actually be.

Thoughts on how to correct this?

You can check out what's happening here on the test server:

http://g.hokkaido-select.com/classifieds/cars-and-vehicles/motorcycles-and-scooters/2006-150cc-scooter (note, you have to be logged into see the block, but the page title error can still be seen)

# Answer
I guess the private message form sets the title directly. A simple way round it might be to cache the current title before you render the form, then set it back again afterwards:

```
$stored_title = drupal_set_title();
print drupal_render(drupal_get_form('privatemsg_new', $recipients, $subject));
drupal_set_title($stored_title);

```
> 2 votes

---
Tags: 7, privatemsg
---


# Question
Title: Errors to Display: None - Settings won't save
I've got my site developed and I'm preparing it for production. There are some errant warnings that appear every once in awhile (I've checked them, they aren't actually a problem, just something dumb in one of the php libraries I'm using). I'd like to hide all warnings and errors on the production site.

I, as an administrator, go to /admin/config/development/logging and I change Errors to Display to None, then I click Save. It says my changes have been saved, but the option is still set to "All Messages" and the errors and warnings are still showing on my site.

What's wrong? Why can't I change this setting?

I'm logged in as user 1, with administrator permissions, but I can't change this setting. Can you help me?

# Answer
Found it!

This is my first Drupal site I'm pushing to production. I still had the following lines of code in my settings.php as suggested on this site: http://drupal.org/node/1056468

```
error_reporting(-1);
$conf['error_level'] = 2;
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

```

Those lines were forcing it to ignore the value in the database and always set it to Show All Errors. I commented those lines out and it's respecting the form value I choose now.
> 3 votes

# Answer
Apparently the form isn't being submitted properly, so the question is what's causing that. I would suspect that page shows javascript errors - you can check using Firebug, and if there are, the errors should point you to the problem (could be a bug with a contributed module, for example).

Are you using any modules that are likely to influence configuration forms? (I'm thinking of things like Domain Access, when not configured properly forms might not be saved correctly).

As a workaround, you can also try disabling javascript in your browser and saving the form.
> 1 votes

---
Tags: 7, users
---


# Question
Title: How to setup custom breadcrumbs with taxonomy?
I have content types that use taxonomy to categorize content. The Pathauto url alias structure is 'content type' / 'taxonomy term' For example:

Food/japanese - where food is the content type and japanese categorizes it.

I am using Custom breadcrumbs with great success except for when viewing a taxonomy page at it's alias. breadcrumbs don't work at all. The term does not show up, the parent does not show up, nothing happens. I have the 'custom breadcrumbs taxonomy' module enabled.

I saw that enabling that sub module created a place where I could create a custom path for each term. Technically I could go through and create a path, but I have 100s, if not over 1000 different terms and more added all the time. It would not be possible to use the term.

This would be very easy if I could just specify 'content type' / 'term' like I do for Path auto. One entry could take care of every situation. Is this possible? anyone know how I can configure this correctly?

# Answer
I ran into a similar issue in D7 and opted to use Easy Breadcrumb: http://drupal.org/project/easy\_breadcrumb.

Easy Breadcrumb compiles the breadcrumb from the URL, and is simple to set up. But it seems like it should work in yours.

Here is an example of how it works:

* URL: www.example.com/portfolio/french
* Breadcrumb: Home › Portfolio › French

What is wonderful about Easy Breadcrumb is that it doesn't matter whether you are using content types, taxonomies, views, or whatever, because it only looks at the URL. *Because* it relies strictly upon the URL, however, it won't be appropriate in many cases.

I wasn't comfortable with how it handled searches (Home › Search › Content › \[Search term\]) and recently messaged the maintainer about the possibility of being able to list instances in which Easy Breadcrumb would be omitted, and he obliged in the latest release.
> 3 votes

# Answer
Not sure if this is the best solution, but you can do that always with theme\_breadcrumb() function in your theme like this:

```
function YOUR_THEME_breadcrumb($vars) {
    $breadcrumb = $vars['breadcrumb'];
    if (count($breadcrumb)) {
        if (arg(0)=='taxonomy' && arg(1)=='term') {
            $term = taxonomy_term_load(arg(2));
            if ($term->vid==YOUR_VOCABULARY_VID) {
                $breadcrumb[] = l('Your landing page', 'landing-page-url');
            }
        }
        return '<ul><li>'.implode('<span class="separator">»</span></li><li>', $breadcrumb).'</li></ul>';
    }
}

```

I'm assuming you're using D7.
> 3 votes

---
Tags: breadcrumbs
---