# Question
Title: permisssions set to 755 - image upload is not possible - in drupal-commons 6x 24.
hello and good day hope you are all well!

**newest update:** Now i have created a second installation with partly other conditions:(haviing permissions 755 with **user vhost: www** on /home/vhost/WWW/campus-24.com/sites/default The selected file xxxxx could not be uploaded. Only JPEG, PNG and GIF images are allowed. Well this is a new error - i had not this error before - what can i do. Guess that i have a made a big step... what do you think!?

Here the original-thread-start: just installed a drupal -commons version 6x 24:

when i try to upload images i get errors - and after doing some search in the system and the adminstration-controll i fould out: the reported error

image upload is not possible - in drupal-commons version 6x 24 {released on jan 18th ): i have done some research and found out that i have: 755 - in directory sites/default/files

Allthough i have the **permisssions set to 755 -**

what can i do here - just lemme know!

The directory sites/default/files is not writable see the path where i i have recogniczed the error

http://schulcenter.org/?q=admin/build/themes/settings

The directory sites/default/files is not writable

Well what can i do here?!

**update:** thx alexandru and Mpd - thx for the answers; well everytime i touch the permissions i get lost.- (i have troubles n issues with permissions and file users. see here https://superuser.com/questions/382792/setgid-bit-always-unset-when-changing-file-permissions hmmm - well MPD guess that you are right and i am pretty lost -here . what can i do now??

# Answer
> 3 votes
You have to set files directory permissions to 777 to make it writable by "others". As I understand you set it to 755 and expect to be writable? 755 means all for the owner, read and exec by group and read and exec by others.

**EDIT**: As MPD said, if the owner of the files is same user as the one apache runs as than files directory doesn't have to be 777. 755 is enough and it is also recommended.

---
Tags: media, users, theming, 7
---


# Question
Title: The PUT request shows "HTTP/1.0 406 Not Acceptable: Missing node type"
I have been trying to update a node data from the PUT request using cURL. bit due to some reason its showing "HTTP/1.0 406 Not Acceptable: Missing node type", I think the request is done proper but the data is not in proper format. Below is my code.

```
        $newSketchBoard = array(
          'title' => $title,
          'type' => 'rest_sketchboard_user',
          'field_sketchboarduser_user_id[und][0][value]'=>$data['uid'],
          'field_sketchboard_paintjob_id[und]' => $data['paintjobid'],
          'field_sketchboard_template_id[und][0][value]' => $data['templateid'],
          'field_sketchboard_user_color_id1[und]' => $data['colorid1'],
          'field_sketchboard_user_color_id2[und]' => $data['colorid2'],
          'field_sketchboard_user_color_id3[und]' => $data['colorid3'],
          'field_sketchboard_user_color_id4[und]' => $data['colorid4'],
        );
        $entity_id=$sketchboard_data['entity_id'];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER,true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 600);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_COOKIE, "{$session_cookie}");
        curl_setopt($ch, CURLOPT_PUT, 1);
        curl_setopt($ch, CURLOPT_URL, REST_BASE_URL."/node/{$entity_id}");

        $putString = $newSketchBoard;
        // Put string into a temporary file
        $putData = tmpfile();
        // Write the string to the temporary file
        fwrite($putData, $putString);
        // Move back to the beginning of the file
        fseek($putData, 0);
        curl_setopt($ch, CURLOPT_INFILE, $putData); // file pointer
        curl_setopt($ch, CURLOPT_INFILESIZE, strlen($putString));
        //curl_setopt($ch, CURLOPT_POSTFIELDS, $newSketchBoard);
        $result = curl_exec($ch);
        print_r($result);

```

I also tried using the following code, but it's not working.

```
$putString = json_encode($newSketchBoard);
$putString = http_build_query($newSketchBoard);

```

# Answer
This ticket might be of some help. http://drupal.org/node/1191786
> 2 votes

---
Tags: services
---


# Question
Title: Locking access to /user redirect if logged out
We have a Drupal 7 site that uses a bespoke login module for ordinary users. Certain (administrative) user rôles, however, must use the core login form at `/user` to log in, as they have escalated privileges. Regular users get a login form at `/` (redirected from any URL when not logged in) and cannot log in at `/user`; administrative users cannot log in at `/`, but must use the form at `/user` — these two forms ask different login questions.

We would like to be able to restrict the `/user` login form to a whitelist of IP addresses, so that only users coming from known IPs can use this form to log in. This would seem simple, at a first glance, as we could use Apache to reject requests for `^/user$` coming from non-whitelisted IPs, except that Drupal also uses `/user` as a redirect to the currently-logged-in users's profile page and this link appears in a handful of locations in our site.

Now I don't want to go hacking through Core, but I can't see how I can enforce the whitelist for anonymous users, whilst allowing any authenticated user to access their own profile page on the URL `/user`.

Should I go through everywhere that we link to `/user` (including the menu block) to substitute in the user's profile ID, or is there some more-elegant solution that I'm just not seeing?

All suggestions gratefully received :o)

# Answer
> 2 votes
I'm not sure this is necessarily the 'best' way to handle this but you could override the access callback for the `user` and `user/login` paths in a custom module and do your whitelist check in there:

```
function MYMODULE_menu_alter(&$items) {
  $items['user']['access callback'] = 'MYMODULE_access_callback';
  $items['user/login']['access callback'] = 'MYMODULE_access_callback';
}

function MYMODULE_access_callback() {
  global $user;

  if ($user->uid) {
    // If a logged in user is trying to access the login page, deny access
    if (arg(0) == 'user' && arg(1) == 'login') {
      return FALSE;
    }

    // Otherwise let the user see their page
    return TRUE;
  }

  // If we've got this far the user is not logged in and the access
  // is based on the whitelist
  $whitelist = get_whitelist_array();
  if (in_array(ip_address(), $whitelist)) {
    return TRUE;
  }

  return FALSE;
}

```

---
Tags: 7, redirection, users
---


title: Check a truth value in Rules Module

text:
# Question
Title: Check a truth value in Rules Module
For a "Page" node, I want to add an event that only acts on node edited by users who are not administrator user.

I use the following code, it doesn't work:

```
<?php [node:user-id] != 1 ? TRUE : FALSE; ?>

```

No matter what I change; for Admin the event is getting called. I've checked all permutations and combinations of syntax (including return) but it seems that "Check a truth values" is getting ignored.

# Answer
The code you are using is not outputting any value; the PHP code you are writing is supposed to output 1 if the actions associated to the condition need to be executed, and 0 when they don't need to be executed.

The correct condition is the following one:

```
<?php echo ([node:author-uid] != 1); ?>

```

Alternatively, you can use the following one:

```
<?php echo ($author->uid != 1); ?>

```
* Verify the token you are using is the correct one; the one I see with Drupal 6 is *\[node:author-uid\]*.
* The operator `!=` already returns a boolean value; there is no need to convert it to a boolean, as you do with the code you have written. The "Truth value" field accepts also 1 and 0 as values; there is no need to convert a value to a boolean.

The description reported for "PHP Evaluation" is the following one:

> PHP code inside of `<?php` `?>` delimiters will be evaluated and replaced by its output. E.g. `<? echo 1+1; ?>` will be replaced by 2.

To notice that the user with ID equal to 1 is a particular user to whom Drupal always give any permission defined from any module; this is the only user account that is treaded in this particular way. Administrator users don't have their user ID always equal to 1; if you are checking the user ID to verify if the user is an administration user, then you are doing it wrong. In Drupal, you usually check the permissions the user has with `user_access()`.
> 4 votes

# Answer
In addition to kiamlaluno's answer describing the appropriate syntax, the other vital clue is that **you must turn the PHP Filter module on**. Otherwise, Rules interprets your input as plain text, which almost always evaluates to TRUE in PHP. Turn the PHP Filter on, use the syntax in the other answer, and you should be all set.
> 1 votes

---
Tags: rules
---


# Question
Title: How to conditionally load a javascript or css?
I just got assigned to a project that requires bug fixes. It is not a bug, but the client is asking us to reduce size of our site's compressed javascript.

I found out that the compressed js' size is around 500kb, which is pretty big. I think it is that big because Drupal loads all the javascript from all the enabled modules. The problem is that there are scripts that I don't use on my homepage or other pages.

What would be a good solution or workaround for my issue? One thing I can think of is to turn off compreconditionally disable modules in my template...but...is that okay or even possible?

# Answer
> 1 votes
What your looking to do is remove extra JS or CSS files, correct? AdvAgg can do this for you.
hook\_advagg\_js\_pre\_alter()
hook\_advagg\_css\_pre\_alter()
are the hooks you want to implement. Then inside of the hook you can use the arg() function to figure out what page your on.

```
$args = arg();
if (   isset($args[0]) && $args[0] == 'node'
    && isset($args[1]) && is_numeric($args[1])
    && !isset($args[2])
      ) {
  $node = node_load($args[1]);
  if (!empty($node) && $node->type == 'page') {
    // Do awesome stuff to the JS/CSS array.
  }
}

```

See advagg\_js\_cdn\_advagg\_js\_pre\_alter() for an example on how the hook is used. Also be aware of drupal\_is\_front\_page(); it might be useful.

# Answer
> 0 votes
You can also check out a context add assets module:

> This module will add a reaction within context to add theme, module, or custom folder files to your page(s).
>
> Ever wanted to quickly add a css file to a theme? Include a js file on only one page (or section?)
>
> Make using multiple CSS files a breeze with this module and harness the power of Context in your theme!

From context add assets project page. Of course it requires the context module and that maybe a lot of overhead to do something like this. But it's a lot easier!

---
Tags: 6, javascript
---


# Question
Title: How to export translated variables settings in code?
In a custom module I define several configuration variables by implementing the Variable module's API. The module is part of a multilingual site project, so some of these variables should be translatable.

In my `hook_variable_info()` implementation, these variables are defined as with `'localize' => TRUE` so they are available in the *Multilingual settings \> Variables* interface provided by the Variable translation module (part of Internationalization). But their default state is not to be translated. So, in order to have the variable translated, the site administrator needs to visit the page and select my module's variables.

I need my custom variables to be automatically translated when the module is installed.

The module already uses Features to export other configuration, so a solution based on Features would be nice. But it can be purely code based.

# Answer
**Update**: With recent version of the Variable translation module (ie. 7.x-1.7), the list of translated variables is stored by the `language` *variable realm* controller in its `list` variable. The following code demonstrate how to use the realm controller to set translated variables from a module `hook_enable()` implementation.

```
function MODULE_enable() {
  // Get the language variable controller.
  $controller = variable_realm_controller('language');
  // The list of translatable variables.
  $translatable_variables = $controller->getEnabledVariables();
  // The list of variables that could be translated.
  $available_variables = $controller->getAvailableVariables();
  // Add our variables to $translatable_variables.
  foreach ($available_variables as $name) {
    // Translate user mail messages.
    if (preg_match('/^user_mail_[a-zA-Z_\[\]]*\[mail_part\]$/', $name)) {
      $translatable_variables[] = $name;
    }
  }
  $translatable_variables = array_merge($translatable_variables, array(
    'user_registration_help',
    'user_picture_guidelines',
    'maintenance_mode_message',
    'menu_main_links_source',
    'menu_secondary_links_source',
  ));
  // Save the updated list of translatable variables.
  $controller->setRealmVariable('list', array_unique($translatable_variables));
}

```

---

**Update**: This is not the way to do it, unless you are using an old version of Variable translation module (\< 7.x-1.7)

The names of the translated variables are stored in the `i18n_variable_conf` variable. This variable itself cannot be exported using Strongarm (or similar solution). I ended using an old trick: checking the variable in a `hook_init` implementation and setting it if needed. The array in the foreach controller contains the names of the variables to be translated.

```
/**
 * Implements hook_init();
 */
function MODULE_init() {
  $i18n_variable_conf = variable_get('i18n_variable_conf', array());
  $i18n_variable_conf_updated = FALSE;
  foreach(array(...) as $name) {
    if (!in_array($name, $i18n_variable_conf)) {
      $i18n_variable_conf[] = $name;
      $i18n_variable_conf_updated = TRUE;
    }
  }
  if ($i18n_variable_conf_updated) {
    variable_set('i18n_variable_conf', $i18n_variable_conf);
    variable_set('i18n_variable_list', variable_children($i18n_variable_conf));
    cache_clear_all('*', I18N_VARIABLE_CACHE, TRUE);
  }
}

```

Compared to a feature based solution, this enforce the settings for the configured variables and will cancel any manual edit. This may wanted or not wanted. In my case it was.

My only issue with this solution, is that it had some overhead to each request.
> 4 votes

# Answer
A solution based on Features should be strongarm. However, that feature does not exist (yet) http://drupal.org/node/1086986
> 1 votes

---
Tags: 7, i18n-l10n, configuration
---


# Question
Title: Allow users to see restricted nodes via views
I have a content type with meta data about a department, and these nodes is restricted using Taxonomy Access Control so that only the department heads can actually view them. I would like to create a view of *some* of the information in these nodes that will be visible to people without full view rights to the node, but views filters out nodes that the current user can't see, which means that these nodes are hidden for non-department heads. Is there a way to override the node access filtering for a specific view?

# Answer
I've not used Taxonomy Access Control, but I'd look in Views' Advanced Settings / Query Settings and check Disable SQL rewriting. But, as the warning says, "Disabling SQL rewriting means that node access security is disabled. This may allow users to see data they should not be able to see if your view is misconfigured. Please use this option only if you understand and accept this security risk."
> 1 votes

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


# Question
Title: Views Sort Criteria: Contextual Filter Multiple Value Order
I have a view that pulls in a collection of nodes via node id. I'm using the Node:Nid filter, and have it set to allow multiple inputs separated by the '+' sign. (443+112+2060...) This part works beautifully.

I was wondering if I could sort the view by the order of the nids? I thought it might do this by default if I remove all sort criteria, but no joy. I'm looking and I don't see a way to sort the view by this data.

Any advice you might be able to give me would be greatly appreciated.

Drupal 7. Views 7.x-3.x-dev.

# Answer
I guess some other people had the same idea I had.

The Views Arguments Extras module handles my situation perfectly. I used the version for 7 (duh :) ), but there is a drupal 6 version as well.
> 5 votes

---
Tags: 7, views
---


title: Managing javascript / css dependancies?

text:
# Question
Title: Managing javascript / css dependancies?
I know you can add css / js with the drupal\_add\_css() or drupal\_add\_js(). Is there a way to define dependancies ?

*Use Case Example:*

> I need a custom tabs/carousel jquery plugin working. I need jquery and jquery ui to load first. In order to ensure that i'd like it to load after jquery and jquery ui.

How would one do that?

Also, is there a way to declare if a script / library is already loaded? i.e. if i load two jquery (1.4 vs 1.8.1) libraries it'll conflict.

Or would this discussion be better suited for the drupal core issue queue?

# Answer
> 1 votes
This is pretty much what hook\_library is for. You define your library

```
function mymodule_library ()
{
    $path = drupal_get_path("module", "mymodule");

    $libraries = array();

    $libraries["mymodule_util"] = array(
        "title" => "MyModule Utilities",
        "version" => "0.0",
        "js" => array(
            $path . '/UTIL.js' => array(),
        ),

        'weight' => -10,
    );

    return $libraries;
}

```

You can add CSS and declare dependencies, if needed.

Then you say you want to use it

```
drupal_add_library("mymodule", "mymodule_util", TRUE);

```

This ensures all of the dependencies get loaded exactly once.

Check out drupal\_add\_library for more details. The core jQuery UI components are loaded this way, too. The module is `system` and the names all begin with `ui.`, eg `ui.scroller`.

I would also check out jQuery Update to upgrade things so you stay in sync with that other jQuery plugins need.

# Answer
> 0 votes
This is built into drupal core with the `hook_library`.

This functionality isn't smart enough to figure out if you want to load two versions of the same thing, but I can't see a generics usage of loading different versions of the same library. Also with regard to jQuery and the version numbers, are you confusing jQuery and jQuery UI which can live side by side (has different version numbers).

---
Tags: javascript, files
---


# Question
Title: Will a Fields form with many submissions make an overload of nodes?
I need to create some user submission forms, and I'm debating the merits of using a custom content type Fields API forms, or a custom module form like the ones in Examples module.

As I understand it, Fields API forms will create a new node for each submission. These forms will have hundreds of submissions every day all year long, and this will create a lot of nodes. I am wondering if this would present a problem in terms of database performance, and site management.

# Answer
Generally, the bigger the database the potentially slower it can get. If you get 200 nodes submitted every day that's 73,000 nodes a year. A lot of news sites or forums or w/e that run on Drupal easily surpass numbers like that.

You can use the Form API to capture content in a custom table of your creation, there's absolutely nothing wrong with that. If you need everything that comes along with nodes, fields, contrib modules that plug into nodes, etc., than you may want to just use nodes. Then there's the ability in D7 to just create a custom fieldable entity (not a node but "like" a node in that it's a piece of content that Views and other things can hook into) and save overhead by keeping things lean.
> 1 votes

---
Tags: nodes, entities
---


# Question
Title: How can I find a list of fields output by a view block?
**FINAL UPDATE**

Success! Apparently there were field-level permissions set on several of the CCK fields I needed, in spite of the original developer telling me that content permissions were not enabled. Once I allowed anonymous viewing of the required fields, they displayed with no problem.

---

I've created a view with a block display. The view has a grouping field, and in the views ui preview, the output displays as grouped by that field:

When I display the block using my template, though, it's not printing out the grouping info (Advanced Learning Session or General Session). That field is not a standard one, like title - it's a CCK text field on my content type. How do I access that field in my template? I've tried the solutions shown here to get a list of available fields, but none of them work.

**Edited after trying @schnippy's answer**

When I mouse over the field, I see this:

So I tried adding

```
<?php print "session type: ".$fields['field_session_type_value']->content; ?>

```

to my template, but although the "session type:" string prints, there's no value coming through after it. I've also tried writing just the value to the error log, in case there was something weird about combining it with a text string, but still nothing.

**Edit again...**

Just to provide a bit more info, if it will help - I'm using the mobile jquery theme, which has a views-view-list.tpl.php file to display views where the output is HTML List. That template looks like this:

```
<?php
// $Id: views-view-list.tpl.php,v 1.3 2008/09/30 19:47:11 merlinofchaos Exp $
/**
 * @file views-view-list.tpl.php
 * Default simple view template to display a list of rows.
 *
 * - $title : The title of this group of rows.  May be empty.
 * - $options['type'] will either be ul or ol.
 * @ingroup views_templates
 */

?>

<div data-role="collapsible">
   <h3><?php print $title; ?></h3>
  <<?php print $options['type']; ?> data-role="listview">

    <?php foreach ($rows as $id => $row): ?>

      <li class="<?php print $classes[$id]; ?>"><?php print $row; ?></li>
    <?php endforeach; ?>
  </<?php print $options['type']; ?>>
</div>

```

I have a number of views that are being displayed via blocks with this template, and for the most part it's fine because they all are grouped by a title field. But for one view, the records are grouped by a CCK field called field\_session\_type\_value, and if the value of that field matches a specific value, I want to print that field instead of `$title`.

**Another update**

According to views-view.tpl.php, $rows is the variable that views sends out as the results of the view query. Now, if I have multiple fields, I would expect that doing a print\_r on $rows would return a multi-dimensional array - each record or row would be an array containing a key/value pair for each field. Like so:

```
Array (
  [0] => array('title'=> 'Advanced Consumer and Shopper Insight - An Interactive Symposium',
               'session' => 'general-session'),
  [1] => array('title' => 'Creating a Powerful Brand One Dirty Job at a Time',
               'session' => 'advanced-learning')
)

```

(Yes, I realize my pseudocode array is not formatted correctly. But you get the idea.) But that's not what I'm getting. What it's sending back is a single-dimension array, containing just the titles:

```
Array (
  [0] => Advanced Consumer and Shopper Insight - An Interactive Symposium
  [1] => Creating a Powerful Brand One Dirty Job at a Time
)

```

What do I need to do to make sure it sends all the fields through in the $rows array?

# Answer
> 0 votes
Apparently there were field-level permissions set on several of the CCK fields I needed, in spite of the original developer telling me that content permissions were not enabled. Once I allowed anonymous viewing of the required fields, they displayed with no problem.

Lesson learned; always check for field-level permissions.

# Answer
> 0 votes
You're using the 'row style' type 'fields' here, correct? The field you are grouping on should also be added as a field in your 'fields' list in order for this to be showing correctly in your preview so all you need to do is find the name, which can be tricky to guess depending on the cck field type. One way you can do this is by hovering over the 'link' in the fields editor within views:

and get the name of the field from the url in your browser status bar, ex.

```
../view_name/display/field/<your field name>

```

and then you just print out the rendered view content of your field in your tpl with:

```
<?php print $fields['<your_field_name>']->content; ?>

```

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


# Question
Title: Recovering from a WSOD related to hierarchical select module
I was messing around with the hierarchical select module (trying to create an exposed filter that would use the hierarchical select interface) I got some strange AJAX related error and then tried to cancel out of what I was doing. After doing so, when ever I try and edit this view I get the White Screen of Death. I went to MAMP server PHP log files and found this error:

> \[02-Feb-2012 15:58:10\] PHP Fatal error: Call to undefined function \_hierarchical\_select\_setup\_js() in /Applications/MAMP/htdocs/sites/all/modules/custom/hierarchical\_select/modules/hs\_taxonomy\_views\_handler\_filter\_term\_node\_tid.inc on line 26

Since I can't get back to my view I don't seem to have any way to remove this broken exposed filter. Any way out or did I just lose this whole view?

# Answer
The \_hierarchical\_select\_setup\_js() function is defined in the hierarchical\_select.module so this is one of those "it should work" situations. Since it isn't, a quick workaround would be to copy it out of there and into, oh, say, your template.php file, wrapped in a "if !function\_exists()" so it doesn't WSOD when it does :)
> 2 votes

---
Tags: taxonomy-terms
---


# Question
Title: Adding DIV ID= Tags to a views table output
I know that I can do a template override to style the views output, as described here.

I've also used a template preprocess function to add a "row\_classes" to a views output. This will add DIV classes, but is it possible to add IDs as well?

Could I also use the views UI for that, maybe with a rewrite?

# Answer
Btw, I ended up using a rewrite in the views UI. I added "content:nid" to the top of the fields and then used "rewrite content" on the title field to:

```
<div id="nid[nid]">[title]</div>

```

Not a perfect solution but it seemed practical to me (at least at the time of writing this) ;-)
> 2 votes

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


# Question
Title: Updating taxonomy vocabularies with Rules?
I'm wondering if there's a way to add/edit/delete Taxonomy terms in a Rule with Drupal 7? I haven't found any way to define an action that will let me do that.

Usecase: I'm trying to use Rules to maintain a vocabulary of usernames of a certain role, so when a user's role is updated I add/remove their username.

# Answer
> 1 votes
Try the rules action "Set data value." If the user includes a taxonomy reference field, you should be able to add or remove it this way.

Alternatives: I'm not sure what you intend to use the vocabulary of usernames for, but it is straightforward to use the views module to generate a list of users by role.

Alternately, I have been using the flag module-- the latest Drupal 7 beta features rules integration-- to automatically flag users upon adding or removing roles. You may be able to use flags instead of a vocabulary.

---
Tags: 7, taxonomy-terms, rules, actions
---


# Question
Title: Why are my fields are out of order when viewing?
I have a content type called 'article'. I create custom fields and drag-n-drop them in the order I want. My user fills out the fields in the order that I prefer. User then clicks SAVE. Now the fields are out of order when this content type 'article' is being viewed. When user clicks EDIT, then everything is back in order, just not when viewing. Why is this and how do I fix it?

# Answer
> 4 votes
Reordering the fields for the content type only affects the edit/add form. To change the order of how they display (and other things, such as label display/placement) you need to go to Structure -\> Content Types -\> \[Your content type name\] -\> Manage Display -\> Default.

---
Tags: 7, entities
---


# Question
Title: Why are my custom error pages returning HTTP status 200 headers?
Drupal 6 on IIS 7. We have webconfig.xml setup to "Execute" the error pages when an error occurs, but the problem is that this now send status code 200 to the client (it is successfully serving the custom error content), which now means that unpublished URLs get indexed by search engines and other crawlers.

I notice that a default Drupal install send the correct HTTP status codes (404, 500, 403, etc), so it must be something in our configuration.

The option to use the default Drupal error pages is likely not on the table with this client.

# Answer
> 0 votes
I believe you still have to return the proper status code from your custom error page. For instance, for a custom 404 page, you need:

```
<?php header("HTTP/1.0 404 Not Found"); ?>

```

---
Tags: 6, iis
---


title: Adding Google maps to a page

text:
# Question
Title: Adding Google maps to a page
I'm trying to add google maps into the header of a view, nothing fancy, as I just used the demo code from the google maps page.

```
<script src="http://maps.google.com/maps?file=api&v=2&key=myKey"
          type="text/javascript"></script>
        <script type="text/javascript">

        jQuery(document).ready(function() {
          if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map_canvas"));
            map.setCenter(new GLatLng(37.4419, -122.1419), 13);

            var marker = new GMarker(map.getCenter());
            GEvent.addListener(marker, "click", function () {
              marker.openInfoWindowHtml("Hello");
            });
            map.addOverlay(marker);
          }
        })

        </script>

```

But for some reason I'm getting this error:

> Uncaught TypeError: Cannot read property 'firstChild' of null

I have no idea what is going wrong.

# Answer
Do you have an HTML element with the id of "map\_canvas" anywhere on the page?

Also I'm assuming you actually have your API key in your first script tag and it doesn't actually say "myKey".
> 2 votes

---
Tags: javascript, google-maps
---


# Question
Title: How do I upgrade to a stable release instead of a development snapshot?
When I use `drush pm-update`, it usually updates to a development snapshot.

How do I force it to update to the next stable release?

# Answer
> 12 votes
`pm-updatecode` (and `pm-update`, which calls it) won't ever switch from development snapshot to stable. If you're on a development snapshot and you want to switch to a stable release, use `pm-download`.

```
drush pm-download somemodule-7.x-1.2

```

```
drush pm-download --select somemodule

```

Make sure that the stable release is *newer* than the development snapshot you are running, and then run `drush updatedb`.

---
Tags: drush
---


# Question
Title: How to get by insufficient memory impass - can't access site?
Can someone help me by this impasse? I have multiple instances of Drupal running (for now). One is for testing and major changes. It seems that I cannot get past the WSOD on my testing instance. The php.log indicates insufficient memory when database.mysql.inc runs. I've tried my php.ini max memory setting at 256M and even -1 (unlimited) and restarted apache with no better results. I can't run drush, can't access the test site. I'm STUCK!

Can anyone suggest a method to get by this issue to allow me to move forward? BTW - the other instances work just fine with a 128M max.

# Answer
> 3 votes
There is 3 method to increase your PHP memory limit. They are all outline in http://drupal.org/node/207036

The best way to check your current situation is to create a file in the root directory call phpinfo.php, with these lines of code

```
<?php
  print phpinfo();
?>

```

Then check the settings by going to http://www.example.com/phpinfo.php

# Answer
> 1 votes
What changed just prior to your out-of-memory issues? If it's a bad module or theme, you can always deactivate it by directly altering database values, namely setting the relevant project's status to '0' in the `system` table.

---
Tags: 7
---


title: Dashboard display two blocks pagination

text:
# Question
Title: Dashboard display two blocks pagination
I have two block views in my Drupal 7 site dashboard: One is a custom module and one is a normal views block. Both are assigned to the dashboard.

The custom module has a table in the block\_view hook. It also has a pagination in it. The second one is generated via the Views module, and also has a table with pagination.

When I go to the second page or to any page of the first table, the second table is updated too.

>

>

I made the view based table's pagination AJAX based, but I suppose it is not to right way.

How do I solve this problem?

# Answer
> 1 votes
You have to change the ID of one of the pagers. For the Views module is under *Pager setting*, *Field pager ID*.

The description for that field says:

> Unless you're experiencing problems with pagers related to this view, you should leave this at 0. If using multiple pagers on one page you may need to set this number to a higher value so as not to conflict within the ?page= array. Large values will add a lot of commas to your URLs, so avoid if possible.

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


# Question
Title: problem with page count in pressflow & varnish
i'm using pressflow & varnish & cashrouter in my site. my problem is node counter is not true because google analytic show diffrent count of node. for example in google analytic show count of node is 12000 but in pressflow show 300 hint. im using revers proxy.

# Answer
> 1 votes
This module should take care if it for you
http://drupal.org/project/jstats

For other options see the Performance wiki and look (ctrl-f) for `Statistics`
http://groups.drupal.org/node/187209

---
Tags: caching, 6, proxies
---


title: Download folder through drupal

text:
# Question
Title: Download folder through drupal
How can I allow users to download the whole folder from Drupal? Is there any easy way? As far as understand, right before they click download link I need to execute php script on a server that will zip the folder and return link to user. This is just too complicated for me. Is there any module that can work? The best I've found is: http://drupal.org/project/download\_file but it seems it only works with single file. I have a shared hosting.

# Answer
Depending on what level of access your users have the ElFinder module is capable compressing and making a directory available for download.

What directory are you allowing your users to download? Be extra careful that they cannot download critical files like /sites/default/settings.php!
> 2 votes

---
Tags: 7
---


# Question
Title: IMCE stops uploading image in the middle of uploading
I have a very strange case. I am using IMCE 6.x-2.2. and when my editors try to upload a new image, it stops uploading in the middle of the process and gives message: "A file with the specified name already exists.".
now when i check on the server, i found that it has uploaded part of the image only (image cropped). this happens always on google chrome and sometimes on Firefox!!
any idea is highly appreciated

# Answer
> 1 votes
I cannot find the string "A file with the specified name already exists" anywhere in the source of IMCE 6.x-2.2.

Looks like the same issue was noted here on Drupal.org and was not part of IMCE

I would recommend updating to the newest version of IMCE in the 6 series to see if this fixes the issue. (Currently 6.x-2.3)

---
Tags: 6, media, files
---


title: How to get the site name in drupal 6?

text:
# Question
Title: How to get the site name in drupal 6?
In some situations, I need the site name of a Drupal 6 site which is given while installation of the site.

How can I achieve it?

# Answer
In both Drupal 6 and Drupal 7, you can use variable\_get. The CMI initiative will likely deprecate this function in Drupal 8.

```
$name = variable_get('site_name', '');

```

Notice the blank '' at the end, which is the "default" value, in case a variable isn't defined.
> 5 votes

---
Tags: 6
---


title: Update report / drush up issue

text:
# Question
Title: Update report / drush up issue
I'm experiencing some odd behavior with D7's update report. When I view the update report it can only determine the status of roughly 5 or so modules/themes. The ones that it finds are random and each refresh reveals a different list of statuses that it can determine. The list reveals all enabled modules but majority of them are grey with "No release found" for the status. `Drush up` behaves the same, except that it only returns the random 5 or so modules that it can find a status for.

Has anyone experienced this issue? Could it be that drupal.org is not responding and the issue is with drupal.org? It's really painful because the elegance and ease of `drush up` is no longer relevant when you have to run it 20 or so times to update modules.

# Answer
> 4 votes
When the update manager reports 'no release found', it typically means you installed from a git (formerly CVS) checkout. If you did do this, you'll need to run the Git deploy module to properly track module versions.

If you didn't use direct git checkouts, but rather, downloaded normal releases from Drupal.org, it may be a bug, which should be reported with as much detail about your setup as possible in the Drupal 7 issue queue.

**Edit**: you may also be experiencing this Drush issue.

# Answer
> 1 votes
This seems to be an issue with Drush 4.4. Upgrading to Drush 4.5 solved this problem for me.

---
Tags: 7, drush, updating
---


# Question
Title: How do I render a node returned by the Drupal search module?
I'm using Drupal 7 to build a fairly simple directory site. I'm trying to theme my search results page the same as a taxonomy page, but as you may know, the results arrive by a completely different process in those two situations. I've copied the `search-result.tpl.php` file from the Search module to my own theme, and am trying to take advantage of the `$result` variable returned by the module. However, it doesn't seem to be as simple as `print render($result);`

I tried to isolate the relevant `node` object within `$result` and perform `render()` on it, like so:

> ```
> $content=Array(); $content['#node'] = $result['node'];
> print render($content);
>
> ```

But that just throws an error (can't use object as array) or simply returns nothing.

`$result['node']` definitely contains the fields I want to echo on the page, so what am I doing wrong?

# Answer
> 5 votes
You need to prepare a view for the node object:

```
$view_mode = 'teaser'; // Or whatever
$view = node_view($result['node'], $view_mode);
print render($view);

```

---
Tags: 7, theming, search
---


title: Custom RSS Template

text:
# Question
Title: Custom RSS Template
I have a view that creates an rss feed on my site.

The view is called RSS\_List. What i would like to do is to create a template to build the rss u dynamically from custom fields.

I have created a template called views-view-row-rss.tpl.php and views-view-rss.tpl.php and both do not work as expected (When loading the url it asks to download a file, and downloads what appears to be a randomly named .part file. These were both suggested under theming information.

Any idea what i am doing wrong?

I would like to create a template rather than install a module etc if at all possible.

My current template is below if this helps:

```
<?php
// $Id: views-view-row-rss.tpl.php,v 1.1 2008/12/02 22:17:42 merlinofchaos Exp $
/**
 * @file views-view-row-rss.tpl.php
 * Default view template to display a item in an RSS feed.
 *
 * @ingroup views_templates
 */
?>
<item>
  <title><?php print $title; ?></title>
  <link><?php print $link; ?></link>
  <description><?php print $description; ?></description>
</item>

```

# Answer
I managed to get this working by using a module called Content Templates (Contemplate) to style the RSS feed. It allowed me to create a template for a certain content type.
> 0 votes

# Answer
I could be mistaken but the file name looks incorrect. Also, I don't think you load views template files directly through your browser.

The first place I would check would be the 'Theme: information' section of your view to see which templates are currently in use. It is possible you have another template overriding the one you have created. This section will also show you 'expected' file name of views templates.

Lastly, you can force Drupal to rescan your template directory for new templates that you have added.
> 0 votes

---
Tags: theming, feeds
---


# Question
Title: Can multiple users edit a node to create several different revisions without being able to publish them?
I want to create a Wiki style website where many users can edit a document but can not publish their edits. Imagine having four users -- an administrator and three normal users. The three users can't publish anything they create or edit. So... one user creates a node. The administrator publishes the node after reviewing it. Then a second user edits the node and it's saved to a draft and after the third user edits the node and it's saved to a different draft. Now there is a published node and two different drafts of the node from two different users waiting for the administrator to publish one of them. Is there a clean Drupal solution for this?

# Answer
> 3 votes
The Workbench module with Workbench Moderation seems to do what you require. Users create drafts, which can then be markled for review. Once an admin reviews the content he can choose to publish it, update it or send it back to the user for further work. Each user has their own drafts, so different users can have drafts of the same document.

You can have as many stages and transitions as you want, so you could have a reviewer role who reviews content and sends it off to a publisher role to be published.

Workbench is Drupal 7 only, but Workflow seems to do similar things for Drupal 6, although I've got no experience with it personally.

# Answer
> 2 votes
Drupal supports revisions natively, but does not allow for very sophisticated "revision-play". However, as it is the case for almost anything with Drupal, you can use a module that allows more advanced revisioning options. Its name is - guess what - Revisioning.

Notice, that if you want to create a complete wiki, you will probably have to use some wiki-specific modules that provide most of the wiki functionality without any hassle. An example of such a module is Wikitools.

Finally, if you do not have enough time and you prefer to click-and-play you can check the Wiki Installation Profile.

---
Tags: nodes
---


# Question
Title: Generate a Barcode from Form Data & Submit Form Data to Database (for Views)
I'm trying to create a bar code generator like the one at http://qr.insready.com/node/add/vcard . This generator is created with Drupal 7 & the Barcode contributed module (by the module's creator).

What I need my application to do is accept a number of items of user data input into a form, concatenate the field entries using tokens into the barcode input field, then generate a bar code on form submit as well as save the data into a database.

This is what I've accomplished so far. I have created a custom multi-part form module following the example in the Examples module, & got it to input data into the database. (I don't know if this will be exposed to Views, since I'm learning this as I go; it's a table I created within Drupal's database specifically to store the data.) Independently, I have created a custom content type with a barcode field that gets tokens from other fields in the form, & successfully creates a bar code encoding the data from the fields in concatenated form.

I would appreciate some pointers on getting this working together. What I need is a way of getting the barcode field into my custom form. Then it can pull data out of the other fields using tokens just as with the custom content type I created.

I can post code snippets if they are needed.

# Answer
`field_attach_form` is the function used to attach fields to forms. This will however attach all fields for a specific entity (fx a node type) to the form. So you most likely will need to do some work on removing unwanted fields or you could do something like this:

```
$form = array();
$fields = array();
field_attach_form('node', $node, $fields, $form_state);
$form['field_bar_code'] = $field['field_bar_code']; // Replace with your field name

```

You also need to invoke validation and submit on the field using `field_attach_form` and `field_attach_submit`. The data itself is saved when you save the node, all those functions do is populate the data on the node.
> 1 votes

# Answer
Have taken a look at these modules. MERCI Barcode, Views Bulk Operations Barcode Select , Barcode

The first two are for Drupal 6 only so they will not work in a Drupal 7 site out of the box. If you save the files without installing them you can read the code and see what they did. The Third one has a beta for Drupal 7.x, so it can be installed. Feel free to borrow code to learn how.

As for getting it to work together...we would need specifics to provide answers. Ask about whatever your stuck on.
> 1 votes

---
Tags: 7, forms
---


# Question
Title: How to easily display a 12 by 12 matrix of input field for integers?
I am still very new to Drupal. I need to let users create nodes to enter 12 by 12 matrix of numbers on one screen block. I don't really know where to start regarding displaying those fields (i.e. layout).

Is there a module/functionality helping defining the layout of those 144 input field in a square shape in Drupal? Some kind of WYSIWIG layout editor? Or, should I try to position those input fields with Javascript within a block?

Thanks.

# Answer
> 3 votes
Might be worth trying CCK table field or Table Field

Both seem to do a very similar function, I would give them both a try on a local dev environment

# Answer
> 1 votes
if you're using drupal 7, you already have your work done using fieldAPI, its the part of core and you dont need to download any additional module. All you need to do is to create a content type and add a field to it using field API, now the creation of field is your job, you need to create a field which will hold the serialized data of first 12 columns. When finalizing the creation of your field, you will specify the number of field instances in the field creation form, and you can put 12 in it. Now on the UI you can show 12 fields in columns whose serialized data will go in single instance of you field

---
Tags: entities, blocks, wysiwyg, theming
---


title: How to create a table field?

text:
# Question
Title: How to create a table field?
Following an answer to another question, I installed the Table Field module. However, I don't see them in the create field menu. How does one create such fields? Thanks (I am new to Drupal).

# Answer
Ok, my bad. I need to create that field instance in content types themselves.
> 2 votes

---
Tags: entities
---


# Question
Title: OG "Add people" username predictive searching
In OG7, I have given one user the role of **overseer** and that role has the **Administer Organic groups permissions** enabled so he can administer all Organic Groups on the site.

So, for each group, when my overseer goes to *Group* -\> *Add People* and he attempts to input the **user name**, the textfield does not predict/provide suggestions of matching user names. However, this helpful effect does happen for the site administrator.

**Can anyone tell me how I can enable this user name prediction effect for my overseer role?**

# Answer
> 0 votes
The permission to set is "View user profiles".

---
Tags: 7, organic-groups
---


# Question
Title: Drupal 7: Duplicated and Extended values on hook_preprocess by Drupal
I'm trying to pass variables from my module to a template. Everything is working fine, but the variables passed to the view appear to be modificated.

Callback to generate and fill the view:

```
 function mycallback() {
    //(...)
      //var_dump($members);
      return theme('team_members', $members);
    }

```

Contents of $members:

```
array
  0 =>
    object(stdClass)[55]
      public 'mid' => string '1' (length=1)
      public 'name' => string 'LLUIS' (length=5)
  1 =>
    object(stdClass)[18]
      public 'mid' => string '2' (length=1)
      public 'name' => string 'OSCAR' (length=5)

```

This is the hook:

```
function global_preprocess_team_members(&$variables) {
  //var_dump($variables);
  $variables['members'] = $variables;
}

```

The content of `$members` is the following one:

```
array
  0 =>
    object(stdClass)[55]
      public 'mid' => string '1' (length=1)
      public 'name' => string 'LLUIS' (length=5)
  1 =>
    object(stdClass)[18]
      public 'mid' => string '2' (length=1)
      public 'name' => string 'OSCAR' (length=5)
  'content' => null
  'theme_hook_suggestions' =>
    array
      empty

```

Somehow, content, theme\_hook\_suggestions has been added to the array, but there is more.

Finally, when I print the results on the template file (tpl.php) via `var_dump()` again:

```
array
  0 =>
    object(stdClass)[55]
      public 'mid' => string '1' (length=1)
      public 'name' => string 'LLUIS' (length=5)
  1 =>
    object(stdClass)[18]
      public 'mid' => string '2' (length=1)
      public 'name' => string 'OSCAR' (length=5)
  'content' => null
  'theme_hook_suggestions' =>
    array
      empty
  'members' =>
    array
      0 =>
        object(stdClass)[55]
          public 'mid' => string '1' (length=1)
          public 'name' => string 'LLUIS' (length=5)
      1 =>
        object(stdClass)[18]
          public 'mid' => string '2' (length=1)
          public 'name' => string 'OSCAR' (length=5)
      'content' => null
      'theme_hook_suggestions' =>
        array
          empty
      'members' =>
        &array
  'zebra' => string 'odd' (length=3)
  'id' => int 1
  'directory' => string 'sites/all/themes/global' (length=23)
  'classes_array' =>
    array
      0 => string 'team-members' (length=12)
  'attributes_array' =>
    array
      empty
  'title_attributes_array' =>
    array
      empty
  'content_attributes_array' =>
    array
      empty
  'title_prefix' =>
    array
      empty
  'title_suffix' =>
    array
      empty
  'user' =>
    object(stdClass)[9]
      (...)
  'db_is_active' => boolean true
  'is_admin' => boolean true
  'logged_in' => boolean true
  'is_front' => boolean false

```

I know Drupal adds some variables here (e.g. user session), but as you can see, my array has been added twice. One in the variables root, and another one inside the members variables (with the extra fields I do not want).

What am I doing wrong?

I thing the ideal situation is having the members variable inside the variables without the extra content (only once).

Do you have any idea?

# Answer
> 1 votes
This bit is the problem:

```
$variables['members'] = $variables;

```

When you declare named variables in your theme function they are passed in as named keys of the `$variables` array. So when you call your theme function:

```
// Note the array wrapping the passed variable and also the 'members' key of the array. This is required in Drupal 7.
print theme('team_members', array('members' => $members));

```

This is what you'll get in your preprocess function:

```
$members = $variables['members']; // This contains the original member array passed to the theme function as the named variable 'members'.

```

What you're doing at the moment is overwriting `$variables['members']` with the `$variables` array itself, so all you're really doing is adding an extra array around the variables array.

Try putting the members that are passed into the preprocess function into a different variable:

```
$variables['custom_variable'] = do_something_to($variables['members']);

```

and outputting that one in your template file:

```
print $custom_variable;

```

I think that's what you're trying to do, have a look at `hook_theme()` for more information :)

---
Tags: theming
---


title: xmlrpc_server has no settings

text:
# Question
Title: xmlrpc_server has no settings
How do I configure xmlrpc\_server?

I am using the Service module, and I need xmlrpc\_server. I installed, and enabled it, and it is showing me the following error:

> xmlrpc\_server has no settings
> The server doesn't have any settings that needs to be configured.

# Answer
> 5 votes
What would you want to configure?

As this message tells you, there is no need to configure anything when using the XMLRPC server. That's all. This isn't an error.

---
Tags: 7, services
---


# Question
Title: Any module which even comes close to frontpage slider module
I saw this front page slider module, and I was impressed by it, but I see there is no Drupal 7 module and it is payed property now.

Is there any module which comes close to this one?

# Answer
Views Slideshow is incredibly configable and I am sure it will cater for that type of display. However is it not an off the shelf product like the wordpress example so dont expect to install it and it just work.

Instead like much of Drupal it is more like a construction box, complex but hugely powerful.
> 6 votes

# Answer
WestieUK's answer is good. I used to use things like Views Slideshow and Views Carousel, but found them a bit too bloated (understandably so) and I wasn't able to configure everything I wanted. I've since just grabbed whatever JavaScript library I wanted to use (e.g. NivoSlider) and added the JavaScript files in my theme. You can even use the Views module to build the unordered list of items and then target that with your jQuery selector that activates the slideshow.

This approach gives you a bit more control.

And, as WestieUK points out, much of Drupal is complex and hugely powerful. To really do things well, you can run your own SQL query in a little custom module to grab the nodes you want, the image style presets, etc., and display them in a render array for use with whatever slideshow library. This kind of thing gives you the leanest, fastest loading, and most customizable slideshow you can get.
> 4 votes

---
Tags: 7
---


title: Blog custom URL

text:
# Question
Title: Blog custom URL
Is it possible to have, for example, www.mydomain.com/blog/username instead of www.mydomain.com/blog/1, as blog URL?

# Answer
> 5 votes
Just install the Pathauto module, visit `admin/config/search/path/patterns` and look at the bottom of the page for this pattern text field:

You can use the standard path recommended by Pathauto (which I think is exactly what you're looking for) or use the Replacement Patterns to build up a more satisfactory URL.

---
Tags: nodes
---


# Question
Title: How do I get all available form field types?
How do I get all form field types (e.g. "textbox," "select") available in Drupal 6?

# Answer
> 4 votes
The core fields are provided by `hook_elements` so you can just invoke that hook to get a list of all field types in the site using `module_invoke_all()`:

```
 $all_types = module_invoke_all('elements');

```

The array keys of `$all_types` are the machine names of the elements, each of those points to another array containing the element information.

---
Tags: 6, forms
---


# Question
Title: How to show views block output in drupal menu?
I have views block and I want to display its output in sub menu when user mouseover on main menu. I on't know how to implement it. Is there any module for it? Please help tell me how can I display views block in drupal menu?.

# Answer
> 1 votes
If you are trying to build a dropdown menu, you can have a look at Nice Menus. This module provides blocks that automatically generates dropdown menus from a selected menu.

If you want to build something more particular than a basic dropdown menu based on Drupal menu system, you should add your block to a hidden region in your html and then move it in the DOM with jquery.

You can do something like that:

```
// Get menu item
menu = jQuery('#selector .to li');

// Get block
block = jQuery('#block-block-myblock');

// Force hide
block.hide();

// Append the block to the menu item
block.appendTo(menu);

// Show / hide menu on hover
menu.hover(function(){ // Function to be run on mouse hover
  block.fadeIn();
}, function(){ // Function to be run on mouse out
  block.fadeOut();
});

```

Hope this will help you ! Cheers

# Answer
> 1 votes
If you actually wants to use view to build (part of) a menu with drop-down effect, the Views build menu module may suit your needs when combined with a module like Nice menus or Superfish.

# Answer
> 1 votes
menu\_minipanels should be the answer. With this module you can print any block (that comes from panel) under the menu.

# Answer
> 0 votes
Try with the Menu Views module.

This approach is rather simple: Attach a view to a menu item.
There are a few modules out there that really attempt to make mega menus simple, but their UI's are completely cluttered. We designed this module to give the admin the power to attach ANY view to ANY menu item. Once the markup is there, then your theme can style it however it wants.

---
Tags: views, 7
---


# Question
Title: Make a public object property visible in other places
I am using a class inside a Drupal module. I inserted the class inside the html.tpl.php like this:

```
require_once(drupal_get_path('module','shop')."/jcart/jcart.php");

```

Now I can use its properties in the pages but I need it to use one of them `($jcart->subtotal)` inside a block module I created like this:

```
function MYMODULE_block_info(){
    $blocks = array();
    $blocks['total'] = array(
        'info' => t('Total amount of the cart'),
                //'cache' => DRUPAL_NO_CACHE,
    );
    return $blocks;
}

/**
 * Implements MYMODULE_block_view().
 */
function total_block_view($block_name = '') {
    $block['title'] = t('Total');

        $total = $jcart->subtotal;

    $block['content'] = $total;
    return $block;
}

```

notes:

I cannot add the class twice with require (because the $jcart) is being initialized inside the class and cannot be done twice I need a block with so I think the variable is not visible in a Drupal block.

# Answer
I would use a function to instantiate your class in a static fashion and then you have access to the same instance across your page load:

```
function MYMODULE_jcart_instance() {
  $jcart = &drupal_static(__FUNCTION__, NULL);

  if (!$jcart) {
    module_load_include('php', 'shop', 'jcart/jcart');
    $jcart = new jCart(); // Or whatever this might be
  }

  return $jcart;
}

```

From then every time you need access to the jcart class instance anywhere else on the site you just call:

```
$jcart = MYMODULE_jcart_instance();

```

Just a quick note, putting in an include into `html.tpl.php` is not a good way to do this. The theme layer is not invoked until all other processing has been done so your include should really be in a module file. I've shown this above using the `module_load_include() function`.

Hope that helps

**EDIT**

I've just seen your previous question relating to this and you mention that the class is instantiated in the include file already. If that's the case just change your static function to this:

```
function MYMODULE_jcart_instance() {
  $included = &drupal_static(__FUNCTION__, FALSE);

  if (!$included) {
    module_load_include('php', 'shop', 'jcart/jcart');
  }
}

```

and then add a call to this in `hook_init()` (this will be called before pretty much any of the rest of your code):

```
function MYMODULE_init() {
  MYMODULE_jcart_instance();
}

```

If `$jcart` is declared in global scope you'll need to add `global $jcart` to the functions that want to use it.
> 1 votes

---
Tags: blocks
---


# Question
Title: The meaning of update.php pending updates
I have replaced Drupal 7 core files from version 7.10 to 7.12. Now I am running update.php and it displays 3 pending updates, e.g.:

> menu module
> 7003 - Add missing custom menus to active menus list

How do I get more information what this means exactly? I checked the site with release notes for Drupal 7.12, but there is no such string (7003) in that list.

# Answer
It's part of `menu_update_7003()`. The comments in that function say it all really:

> Make sure all custom menus are present in the active menus variable so that their items may appear in the active trail.

Usually just searching Google for the exact message in quotes (e.g. "Add missing custom menus to active menus list") will bring up the page that explains why it's been done (that's what I did to find this out). You can most likely do the same for the other two updates and find out exactly what they're doing.
> 2 votes

---
Tags: 7, updating
---


# Question
Title: How do you display a pane in an organic group?
I'm trying to create a menu of subgroups for organic groups in d7. I've copied the og list view and made a new view called og subgroups. I made a pane display and configured the pane's argument to be Og group ID from context. I also added the contextual filter: (group) OG group: Og group ID and the relationship: Group: Node group.

When I enter a group ID in the preview field of the view, it loads the appropriate menu items. When I go to the Group variant for the node template in panels, and add the pane as content in the appropriate region panels shows that the argument is group ID, but if I view the group it does not display the pane.

Am I doing something wrong?

# Answer
> 1 votes
This is what you need to do on the **view content pane**:

* Relationships: "Group membership: Node group membership"
* Contextual Filters: "(group membership) OG membership: Group gid"
* Pane settings: Argument input: From context \> Og group ID

On the **panel** contexts:

* Contexts: OG group \> Og group from context

Then you should add the view content pane to the panel pane and the argument should automaticaly be set to "OG membership: Group gid" \> "OG group".

These are required for it to work, and I'm currently using them.

---
Tags: 7, organic-groups, panels
---


# Question
Title: Notify user by email when matching content is uploaded
I'm setting up a real estate website that sends an email to a user notifying them when a property meeting their specifications is uploaded.

Any ideas how I can do this in drupal 6/7 ?

# Answer
> 1 votes
Take a look at subscriptions module also and especially at this tutorial. I think this is a much simpler approach.

# Answer
> 0 votes
Just speculation here, but I'd have a bunch of CCK/Fields and Taxonomies on your property content type. Then I'd put those same fields/taxonomies on the User objects (in 7 you can do this directly, because users are fieldable, but in 6 you would use something like Content Profile)

Then you would hook into the saving/updating of your property content type (most likely using a combination of hook\_nodeapi in 6, hook\_node\_insert and hook\_node\_update in 7 and hook\_form\_alter) to compare the fields/tags on the property to users with the same or similar tags/fields and then send those users an email.

If you have large number of users/properties, you'll probably want to use hook\_cron to batch process the recently updated nodes instead of doing them on demand. Also, you should be sure to store which properties a user has been notified of to avoid duplicates.

---
Tags: views, users, rules
---


# Question
Title: What is the proper RewriteBase setting for my staged server?
I'm having issues with Clean-URLs not working on my staged server, possibly stemming from the fact that the installation is pulled down from a Git repo, for staging.

I suppose the .htaccess file is configured properly for my local installation, but not for the staged one which has a different file path. (http://drupal.org/node/1018346)

I have my drupal installation on my staged server (which is having the clean URLs problem) in this location:

```
/home/user/drupal_dev/www

```

And in my web server's `/var` directory, I set a symlink pointing to that www directory in my home. That way I don't have to worry about copying files into a root directory that requires sudo.

Can you offer suggestions on what my .htaccess file should look like, in regards to RewriteBase?

# Answer
> 3 votes
Unless you are running in a subcdirectory (eg, http://www.whatever.com/sub/directory/that/has/drupal/), you should use

```
RewriteBase /

```

`RewriteBase` is really used when you are doing rewrites from a directory that doesn't match your `DocumentRoot`.

---
Tags: version-control, .htaccess
---


# Question
Title: How can I set specific download URI for file?
Here is my problem. I've got file (eg. some.xml) and multisite Drupal 7 installation. How can I allow to download this xml from my-multi-site.domain/some.xml? Is there any way to do it without writing custom module with hook\_menu?

P.S. this file should be different for every site on multisite installation

# Answer
> 0 votes
I decided to solve this problem by serving this file through nginx. That is not a universal solution, but it works.

# Answer
> 0 votes
The proper solution is a hook\_menu, which I believe is also going to be a requirement to make this reasonable when several sites want separate names.

I workaround would be to just symlink it to your Drupal root.

```
ln -s sites/example.com/files/somefile.xml some.xml

```

But if it's a requirement to have each filename only available on one domain, apache would need to have logic to block the "wrong" names, which is inconvenient.

A third possibility would be to rewrite the URL in apache, but I don't exactly know the syntax for this.

---
Tags: 7, files, multi-sites
---


title: Custom body class

text:
# Question
Title: Custom body class
I'm trying to add some other classes to my body in order to identify some pages. I've tried adding some classes, but for some reason drupal is not displaying them in the body.

Below is my preprocess\_html and the output of $vars\['classes\_array'\] and the actual output in html.

As you can see, only the class I added is not being displayed.

```
function theme_preprocess_html(&$vars) {
    $vars['classes_array'][] = drupal_html_class('page-' . $vars['head_title_array']['title']);
}

// output
array(10) {
  [0]=>
  string(4) "html"
  [1]=>
  string(9) "not-front"
  [2]=>
  string(9) "logged-in"
  [3]=>
  string(11) "no-sidebars"
  [4]=>
  string(9) "page-node"
  [5]=>
  string(10) "page-node-"
  [6]=>
  string(12) "page-node-41"
  [7]=>
  string(14) "node-type-page"
  [8]=>
  string(7) "i18n-en"
  [9]=>
  string(10) "page-legal"
}

// page output
class="html not-front logged-in page-node page-node- page-node-41 node-type-page i18n-en context-legal omega-mediaqueries-processed admin-menu responsive-layout-normal"

```

# Answer
I don't know how your `html.tpl.php` looks like, since that will effect it, but by default the interesting line looks like this:

```
<body class="<?php print $classes; ?>" <?php print $attributes;?>>

```

So what you want to alter is not `$vars['classes_array']` but `$vars['classes']`. This might explain why

```
context-legal omega-mediaqueries-processed admin-menu responsive-layout-normal

```

is printed out, but not in the `$vars['classes_array']` array.
> 2 votes

---
Tags: theming
---


title: Custom module log activity

text:
# Question
Title: Custom module log activity
I have a custom module that interacts with some third-party service. Please look at this function:

```
function mymodule_connect_entity_update($entity, $type) {
  // Update the entity's entry in a fictional table of all entities.

  //here's some call to external service and I'd like to log results.
}

```

I want to log information from $entity and other info. I'd like to know what is the best way to do this. This site is hosted on Acquia if it affects the decision. Someone recommended syslog, but I'm not sure about that, I'd like to have a separate log for this activity. My idea is to create a custom logger, and configure Linux logrotator to handle rotation. The thing is that I don't have permissions to configure rotator, and I'll have to support my decision in order to convince the System Administrator, and I'd like to know other approaches and their advantages.

# Answer
> 2 votes
For logging you could use Watchdog. The first parameter `$type` can be used as a filter on the report page which is often handy.

---
Tags: 7
---


title: $node->form_id doesn't exist?

text:
# Question
Title: $node->form_id doesn't exist?
```
function mymodule_node_insert($node){
    if($node->form_id == 'whatever_node_form'){
        // do stuff
    }
}

```

Returns an error: `Notice: Undefined property: stdClass::$form_id in mymodule_node_insert() (line 16 of /home/admin/public_html/website.com/sites/all/modules/mystuff/mystull.module).`

I can clearly see the array dump of $node that it is indeed an object and it contains form\_id. What am I doing wrong?

# Answer
This code is actually correct. When checking for an object, it's always a good idea to use `isset()` to make sure the variable exists!

This code was adjusted to the following:

```
function mymodule_node_insert($node){
  if (isset($node->form_id) && ($node->form_id == 'whatever_node_form')) {
    // do stuff
  }
}

```
> 1 votes

---
Tags: 7, hooks, forms
---


# Question
Title: Can nodes created using Feeds be updated automatically?
The Feeds documentation mentions that it's possible to import a CSV feed and create nodes from it, assigning column values as CCK fields, but it doesn't mention if it's possible to update nodes when those values change in an updated feed. Is this possible to do using Feeds or an additional module?

For example, a feed is downloaded in week1, creating a node for a Red Widget. Its price is £10.

In week2, the feed is updated with a new price of £12 for the Red Widget.

Can the node initially created be updated with that new price without importing a new or duplicate node?

# Answer
> 2 votes
I believe as long as you have a primary/unique ID for each item in your CSV this should be very easy to do with the Feeds module. When you do not have primary key to work with things get tough.

---
Tags: nodes, 6, feeds
---


title: WYSIWYG Editor questions

text:
# Question
Title: WYSIWYG Editor questions
We've had a custom theme made out of two themes combined basically a news and a video content section--I've installed WYSIWYG and TinyMCE. The weird thing is that the rich text editor only shows up when editing content in the video section, and not the news section. In the news section, not even the Enable Rich Text hyperlink shows up.

Is there a particular line of code I can look for that would enable the link (and therefore the editor) to show up in the news section?

# Answer
It's likely that you need to set your news 'body' field's text format to '**Full HTML**' instead of '**Filtered HTML**'.

For more info on your current setup head to admin/config/content/wysiwyg to see which Text Formats have the WYSIWYG editor applied.
> 4 votes

---
Tags: wysiwyg
---


# Question
Title: How to configure fivestar's star set in Drupal 7?
The FiveStar module says the star set is configurable, but where can one select the star set in Drupal 7? I have searched, but could not find the proper page. (I am still new to Drupal).

# Answer
> 4 votes
Having used FiveStar with Drupal 6 and knowing where the configuration is I've had a look at FiveStar on D7 and I would suggest that because it is still Alpha the team hasn't got to moving the new features across yet as I could not find the required config either.

EDIT: I tell a lie. You can configure the star set, and as an improvement you can do it per fivestar field (i.e. you could have two ratings against a node that have different star sets). To do this go to "Manage Display" of the content type that contains your fivestar field. At the right of the field there will be a "gear" icon. Clicking on this will bring up options including the star set to use.

---
Tags: rating
---


title: D7 checkbox default checked

text:
# Question
Title: D7 checkbox default checked
Shouldn't be hard, but it is - how do you make a CCK checkbox default checked?!?

I've tried various responses in the PHP Default Value box:

```
return array(0 => array('#default_value' => 1));
return array(0 => array('default_value' => 1));
return array(0 => array(1));
return array(0 => 1));
return array(1);
return 1;

```

I'm sure you get the point. None of these work?!

# Answer
I'm a bit confused where you're entering the code above? If I want a checkbox to default to checked then in the UI you can specify this. See screen shot where I've added a field with a label "Shippable".
> 3 votes

---
Tags: 7, forms
---


title: php generated URL link

text:
# Question
Title: php generated URL link
I have a menu link that is a link to another client site. This uses a single-sign-on. The users info(in Drupal) is sent via SOAP to create a URL with a authenticated ticket for them to use to login. The ticket is a one use ticket. I can't figure out where to implement this, I feel like this is something that needs to be done between jquery and hook\_menu maybe? The problem is that this SOAP code needs to be called every time a user clicks this link.

Anyone have any suggestions? I'm using drupal 7.

thanks -fw

# Answer
> 1 votes
I'm not sure jQuery is really necessary here.

If I've understood you right you could have your link pointing to a path with a menu callback which requests your token via SOAP, and then simply forwards the user on to a URL containing that token as a parameter

```
function MYMODULE_menu() {
  $items['goto-other-site'] = array(
    'title' => 'Forwarder',
    'type' => MENU_CALLBACK,
    'page callback' => 'MYMODULE_forwarder',
    'access arguments' => array('some permission')
  );

  return $items;
}

function MYMODULE_forwarder() {
  $token = MYMODULE_function_to_generate_token();

  if (!$token) {
    return 'An error occurred.';
  }

  // Add a query string containing the token.
  $options = array(
    'query' => array(
      'auth_token' => $token
    )
  );

  $url = 'http://other-site.com/';
  drupal_goto($url, $options);
}

```

Apologies if I've got the wrong end of the stick here.

**UPDATE**

Just a bit more to address your comments:

You can use `hook_menu()` to place each link in a specific menu in the system by using the `menu_name` key like so:

```
function MYMODULE_menu() {
  $items['goto-other-site'] = array(
    'title' => 'Forwarder',
    'type' => MENU_CALLBACK,
    'page callback' => 'MYMODULE_forwarder',
    'access arguments' => array('some permission'),
    'menu_name' => 'main-menu',
    'weight' => -10
  );

  return $items;
}

```

The `weight` key describes where in relation to other menu items this link should sit in the menu (a lower number means earlier in the list). When you add a menu link in this manner it will be automatically added to the correct menu so you don't need to add a custom link through the UI (you can delete the one you've already made).

Have a quick read of the Module developers guide to get familiar with that side of things, in this case you're only going to need a `.info` and `.module` file.

Hope that helps

---
Tags: 7, routes
---


title: Autocomplete textfield

text:
# Question
Title: Autocomplete textfield
I've noticed that the autocomplete textfield widget has not been ported to Drupal 7.
I'm looking for a way to provide user with suggestion for already submitted values, but I don't want to create a free-tagging vocabulary, since I don't want a page with all nodes with a particular value.
What can I do? Has this feature been ported to a separate module like Node Reference?
I've tried Autocomplete Deluxe module, but it works only with terms, not with textfields.

# Answer
> 0 votes
The References module provides autocomplete text fields for user and node references.

# Answer
> 0 votes
Since the original answer was written, some modules have appeared that do Autocomplete and/or dropdowns for textfields:

---
Tags: 7, entities
---


title: Extra node statuses

text:
# Question
Title: Extra node statuses
Working with D7, I want extra statuses for nodes, such as "unpublished," "published," "draft," but also "received," "under review," and "approved." What's the easiest way to accomplish this?

# Answer
If you want to add additional 'on/off' style switches to an entity or node like Published -\> Unpublished and Approve -\> Rejected I would recommend looking into the Flag module.
> 4 votes

# Answer
there is also the Workbench module if you need more of an editorial flow with approval processes:

> ... a customizable editorial workflow that integrates with the access control feature described above or works independently on its own
> 0 votes

---
Tags: 7, nodes
---


title: node_delete doesn't work!

text:
# Question
Title: node_delete doesn't work!
I am calling `node_delete($nid)` from inside a function callback that is called when the DELETE button is pressed, but the node is not deleted. There is no error - it just doesn't work! What can be going wrong?

In `bhl_form_alter()` I put:

```
$form['actions']['delete']['#submit']['0'] = 'delete_mem';

```

Then `delete_mem($node)` calls `node_delete($node->nid)`.

I have also tried to figure out a way to use the default callback `hook_node_delete()`, but if I put a redirect there with `drupal_goto()`, the redirect happens, but the node again does not get deleted. `drupal_form_redirect()` doesn't work in this function because `$form_state` is not passed.

# Answer
> 5 votes
The first mistake in the code is how the additional submission handler is added. You should add it with the following code:

```
$form['actions']['delete']['#submit'][] = 'delete_mem';

```

If you want to be sure that submission handler is executed first, you should use the following code:

```
array_unshift($form['actions']['delete']['#submit'], 'delete_mem');

```

The second error is the argument declared for the form submission handler that, as shown in this documentation page, should be:

```
function delete_mem($form, &$form_state) {}

```

As consequence of this, if you defined your function as `function delete_mem($node)` and you call `node_delete($node->nid)` from that function, `node_delete()` doesn't work because what you are calling `$node` is really a form array, which doesn't contain the `nid` property; what you are passing to `node_delete()` is `NULL`, and the function doesn't delete any node. Eventually, `NULL` could be converted to `0`, but there aren't nodes using `0` as node ID, and the function will not find any node to delete.
If you are using a Drupal development snapshot, you would get a warning about accessing a property of something that is not an object.

Supposing that you are altering the node edit form, the submission handler you are writing has access to the node object through `$form_state['node']`; the node ID can then retrieved with `$form_state['node']->nid`.

You can check the code executed from the default submission handler added from the Node module to the "Delete" button, which is the following one.

```
function node_form_delete_submit($form, &$form_state) {
  $destination = array();
  if (isset($_GET['destination'])) {
    $destination = drupal_get_destination();
    unset($_GET['destination']);
  }
  $node = $form['#node'];
  $form_state['redirect'] = array('node/' . $node->nid . '/delete', array('query' => $destination));
}

```

It uses `$form['#node']` to get the node object, and `$node->nid` to get its node ID. Consider the note added in node\_form() about `$form['#node']`.

```
  // @todo D8: Remove. Modules should access the node using $form_state['node'].
  $form['#node'] = $node;

```

This means that using `$form['#node']` would not working anymore on Drupal 8 (or any future version), while `$form_state['node']` would still work for Drupal 8 and any future Drupal version.

In this case, your submission handler doesn't need to call `node_delete()` as the function is already called from the submission handler added from the Node module to the "Delete" button. If you really need to delete information about a node that is being delete from a database table that your module uses, then you should implement hook\_node\_delete().

> I have also tried to figure out a way to use the default callback `hook_node_delete()`

`hook_node_delete()` is a hook that needs to be implemented. If your module is bhl.module, the function that needs to be written has the following signature:

```
function bhl_node_delete($node)

```

That hook is implemented when you need to delete data saved from your module in its own database table, where you save some custom data and the node ID. It is not required to delete a node, which a task already done from node\_delete\_multiple(), which contains the following code.

```
try {
  foreach ($nodes as $nid => $node) {
    // Call the node-specific callback (if any):
    node_invoke($node, 'delete');
    module_invoke_all('node_delete', $node);
    module_invoke_all('entity_delete', $node, 'node');
    field_attach_delete('node', $node);

    // Remove this node from the search index if needed.
    // This code is implemented in node module rather than in search module,
    // because node module is implementing search module's API, not the other
    // way around.
    if (module_exists('search')) {
      search_reindex($nid, 'node');
    }
  }

  // Delete after calling hooks so that they can query node tables as needed.
  db_delete('node')
    ->condition('nid', $nids, 'IN')
    ->execute();
  db_delete('node_revision')
    ->condition('nid', $nids, 'IN')
    ->execute();
  db_delete('history')
    ->condition('nid', $nids, 'IN')
    ->execute();
  db_delete('node_access')
   ->condition('nid', $nids, 'IN')
   ->execute();
}

```

Inside the implementation of hook\_node\_delete(), you don't call node\_delete(), or you cause an infinite loop. In fact, `node_delete()` calls node\_delete\_multiple(), which then invokes any implementation of `hook_node_delete()`, including yours that would call `node_delete()`, that would call `node_delete_multiple()`, which again would invoke any `hook_node_delete()` implementation, including yours.

As general suggestion, the functions defined from a module should always be prefixed from the short module name. In your case, if the hook function is `bhl_form_alter()`, the submission handler should be `bhl_delete_mem()`.

---
Tags: 7, nodes
---


# Question
Title: Drupal 7, GPS lat, lng closes value, is it possible?
After multiple attempts to figure out how to find the closest gps point from the lat & lng fields (field\_data\_field\_lat & field\_data\_field\_lng) I would like to ask if such is possible? Is there any module that provides a solution with which it's able to create two fields for lat/lng and use them at views to find the closest one from an exposed filter?

I assume that there is no such ready made solution. In that case, I would like to write my custom sql statement for D7. Unfortunately, D7 doesn't support the D6 sql query functions and also the pager\_query function.

Therefor I would like to write a statement that would bind the lat and lng fields and give back the nearest - closest gps points. Similar, one field statement is written at: http://www.techfounder.net/2009/02/02/selecting-closest-values-in-mysql/ where the union and ABS is used. I've found the union option but didn't figured out how to make the comparison for both fields within the D7 db sql layer.

Thank you in advance.

# Answer
Have a look at this article: Creating a Store Locator with PHP, MySQL & Google Maps. Especially the section about "Finding locations nearby with MySQL" is hinting towards your solution.

As you can read in the mentioned article, calculating the distance between 2 points given their lat/lon requires quite some math (Haversine formula). So, I guess that the performance optimization in the article you are referring to won't be possible. This because it will be hard to use an index to retrieve probable points.
> 2 votes

# Answer
There's a module for that.

Location: "\[..\] At present, it is the only module that provides the views integration necessary for implementing location-based searches and is designed for the purpose of finding points on a map within a vicinity of a user-supplied location."

If you need to have separate form fields for lat and long, and Location doesn't provide that, you could write your own widget/formatter.
> 2 votes

# Answer
I needed this myself, and implemented it for Geofield. I posted my patch here. You should be aware that I only started the functionality, and the patch *happens* to work on my site, but needs quite a bit of work to be suitable for inclusion into Geofield. Perhaps you can use it though. Bonus points for posting back an improved patch to the issue.

If you read the rest of the issue you'll also find a discussion on other ways of solving your problem.
> 2 votes

---
Tags: database, location
---


# Question
Title: Change the Drupal Commerce checkout completion page
How do I redirect the final checkout page of my Drupal Commerce install (from `checkout/%/complete`) to the actual order created (`user/%/order/%`)?

This seems easier than having to build and theme the line items in the completion message pane, not to mention I have inserted other information to the order display.

# Answer
> 1 votes
I used the Rules module to redirect on checkout completion event, and this seems to be working so far.

---
Tags: 7, commerce
---


# Question
Title: Drupal 7 - How add posfix '.html' to all paths?
is it possible to add to all path system or node path postfix '.html' for example

```
site.com/index -> site.com/index.html
site.com/user/login -> site.com/user/login.html
site.com/node/add/page -> site.com/node/add/page.html

```

pathauto

```
site.com/term-alias/hello-world -> site.com/term-alias/hello-world.html

```

and so on

Is it?

# Answer
AFAIK, it is not possible to simply configure Drupal for that. If you serve your Drupal site with Apache, you can configure `mod_rewrite` to remove the `.html` suffix. But you will not be able to configure Drupal to add it to the links it produce.

In a custom module, you could implement `hook_url_inbound_alter()` and `hook_url_outbound_alter()` to remove/add to `.html` suffix to all paths.
> 3 votes

---
Tags: uri
---


title: Print the comment form with PHP

text:
# Question
Title: Print the comment form with PHP
I'm trying to print a comment form with the following code.

```
<?php
    print drupal_get_form('comment_form', array('nid' => $row->nid), t('Post new comment'));
?>

```

All I get is the following error repeated 40 times:

> Warning: Attempt to assign property of non-object in comment\_form() (line 1845 of /home/admin/public\_html/website.com/modules/comment/comment.module).\`

The comment form is called from inside a PHP Views field. What is the proper way to add a comment for to a node in Drupal 7?

There are actually a lot more errors, most of which repeat at least once:

> EntityMalformedException: Missing bundle property on entity of type comment. in entity\_extract\_ids() (line 7501 of /home/admin/public\_html/website.com/includes/common.inc). Notice: Trying to get property of non-object in comment\_form() (line 1854 of /home/admin/public\_html/website.com/modules/comment/comment.module).

# Answer
`comment_form()` is expecting the parameter to be an object rather than an array so you should be doing something like this:

```
$comment = new stdClass;
$comment->nid = $row->nid;
$form = drupal_get_form('comment_form', $comment);

```

Note the lack of a 3rd parameter passed to `drupal_get_form()`, `comment_form()` only accepts the comment as a parameter, if you want to add a title you'll have to print that separately.

Finally `drupal_get_form()` returns a render array rather than a string so you need to pass it through the `render()` function:

```
print render($form);

```

The extra errors you're getting are just side-effects of passing an array rather than an object to the `comment_form()` function.
> 12 votes

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


title: CCK textfield with checkbox

text:
# Question
Title: CCK textfield with checkbox
How can I add a CCK field that has a checkbox and a textfield in Drupal 6? so I want to have something like this:

```
[x] Option1 _______________
[ ] Option2 _______________
[ ] Option3 _______________
[x] Option4 _______________

```

# Answer
Just define 4 checkboxes and 4 textfields. If you use a bit of CSS you can get them to look like they're compound fields by floating left and clearing after the textfields. You might need to hook into the validate functions (using hook\_form\_alter) if you want these fields to be any smarter than that.
> 0 votes

---
Tags: 6, entities
---


# Question
Title: Additional parameters to aliased panels paths
I'm trying to build a news/blog feed for each of our internal departments. I have a vocabulary with terms for each department, and have successfully created a panels page at `extranet/news/<tid>` which displays a content pane view of the most recent N posts. The departments want to be able to alias their newsfeed, to something like `hr-news`, so add a url alias `hr-news => /extranet/news/<tid-for-hr>`. This all works fine thus far.

The problem comes when I try to put a summary view in another pane on the same panel to link to previous months of posts, where the goal would be to use a path like `hr-news/2011/10` or similar. But to do this, it seems that I would have to create a url alias for each month/year/department combination.

The other option would be to use GET parameters, but I cant figure out how to load a GET parameter into a panels context so i can pass it to the view. Am I approaching this problem wrong?

# Answer
> 1 votes
I have a similar problem on a Drupal 7 site, and am posting as much to share my solution as to "subscribe" and hear from others about the potential pitfalls or alternative solutions.

In my case, I have a number of panels that display "related" content to a node.

Let's say that it's an artist node, and that I have a few panels or variants representing the

1. artist (url artist/\[artist-nid\])
2. their albums (albums/\[artist-nid\])
3. their band history (history/\[artist-nid\]).

For SEF urls, I want to alias those to something like

1. artist-name-profile
2. artist-name-albums
3. artist-name-band-history

Because pathauto doesn't "see" the panels, and because the urls are of an unusual structure (no '/' ) I wrote a custom module to do url rewriting using hook\_url\_inbound\_alter() and hook\_url\_outbound\_alter().

For Drupal 6 you can use http://drupal.org/project/url\_alter It's baked into Drupal 7.

So basically, I maintain a cck field on the artist node containing a url friendly version of the artist name. Then use code something like the following.

```
function myModule_url_outbound_alter(&$path, &$options, $original_path) {
  $parts = explode('/', strtolower($original_path));
  $prefix = array_shift($parts);

  switch($prefix) {
    case 'albums':
      if (!empty($parts[0]) && is_numeric($parts[1])) {
        $url_fragment = myModule_get_unique_url_safe_artist_name($parts[1]);
        $path = $url_fragment.'-albums';
      }
      break;
    // etc
  }
}

function myModule_url_inbound_alter(&$path, $original_path, $path_language) {
  $parts = explode('-', strtolower($original_path));

  $suffix = array_pop($parts);

  switch ($suffix) {
    case 'albums':
      $map = implode('-', $parts);
      $nid = myModule_get_nid_from_unique_url_safe_artist_name($map);
      $path = 'albums/'.$nid;
      break;
    // etc
  }
}

```

Pros,

* I get a great deal of flexibility on the url design - non-conventional urls are possible
* I do not need to have over 50,000 records in the url\_alias table.
* I can quickly and easily change the urls without having to rebuild the alias table
* I can reach those pages pathauto can't
* It works.

Cons,

* every url passes through this test and the ones that match will be slowed down by at least one db query. (this doesn't appear to be much of a performance hit by YMMV)
* url changes require developer intervention
* For large numbers of panel variants, this function can become difficult to maintain, particularly because you have to be careful not to allow conflicts to arise. See below for example.
* This doesn't smell right as an approach

Conflicts can come up based on your url matching methodology. I the above case we split on '-', this can become a problem in this specific case if the artist url were simply artist-name and the artist's name was literally "Michael-albums" since this would be interpreted as an album page for "Michael" rather than an artist page for "Michael Albums".

# Answer
> 0 votes
Path aliases are a second name for a URL call for Drupal. Drupal actually only understands several URL paths (/node/nid, taxonomy/term/tid, /user/uid...)everything else is jibberish, except when aliases are turned on, Then you can make substitutions. When a URL is passed to Drupal with aliases, it translates that alias into a URL it understands very early in the process. When you create an alias such as extranet/news/%tid-for-hr, it is quickly translated and for your purposes the alias is really not used again. You certainly cannot have two path aliases and use one to pass context information to the view or panel. In fact you cannot get a view page to read an alias at all because the URL is changed to its Drupal form before Views gets it.

If you want to filter the content further with a contextual filter, you will need do so through the content of a field or by making a relationship with a node that can pass your information to the view.

I am also wondering if you are making this to difficult. Somewhere, you are going to have to define the filter dates so that the view can be filtered. Why not do it in the view itself. This would mean only one place to make the setting. If you want, you could expose the filter so that the user could set his/her own desired date.

If I've missed the point, please let me know.

---
Tags: views, 6, panels, path-aliases
---


# Question
Title: How to allow user login only once at a time?
1. I want to allow a user login to the site only once at a time. User should not be able to login at other machine/place while he is logged in.
2. I want to user password should get destroyed once used and should promt user to "request new password".
3. I also want to show user login time,logout time, number of visits, last visit time...etc in a block for user.

How can i get these in Drupal?

# Answer
> 9 votes
You can get what you're looking for with a combination of existing modules:

1. Session limit module
2. Password policy module
3. User stats module \+ Views module

You shouldn't have to write a single bit of code using those 3 modules.

You don't mention which version of Drupal you're using but each of those modules have D6 and D7 releases (albeit a dev release for one of them).

---
Tags: users
---


# Question
Title: Drupal error. Drupal safe mode possible?
I added organic groups module to a drupal website. For some reason the website crashed and gives the following error:

```
Fatal error: Unsupported operand types in /home/content/39/7384539/html/salvare12/sites/default/modules/og/includes/og.info inc on line 115

```

I removed the organic groups module manually and disabled it in the database. But then it gives a file missing error. I have uploaded the organic groups module once again but it does not work.

How can this be fixed? Is there some **safe mode** in drupal, to which i can revert when such an error occurs?

# Answer
> 2 votes
Try deleting the row for the og module in the system table. Then run a query for each database table beginning with cache\_:

```
TRUNCATE TABLE cache_*

```

This should make Drupal forget anything it knew about organic groups (this is how to clear the cache manually).

I'd suggest keeping your modules in the standard location which is /sites/all/modules rather than /sites/default. I don't know if thats part of the problem here but it might be.

# Answer
> 1 votes
Also, I'd get to know drush and use that to disable and uninstall (where available) modules until your site is back up again.

---
Tags: 7, organic-groups
---


title: Adding CSS styles

text:
# Question
Title: Adding CSS styles
I'm using the Mimemail module with the Simplenews module to theme an email newsletter, but it's not the least bit clear to me where I can store my styles so mimemail can then add them as inline styles to the various HTML tags. From my research I understand you can create a mail.css file where styles can be added or altered but that doesn't seem to be working for me. Am I missing something here?

# Answer
> 2 votes
I suggest you don't rely on stylesheets but rather create the inline code by hand and uncheck the option: Add stylesheets. If you find this difficult install emogrifier module (not sure but you might need to install htmlmail as well) that converts the stylesheet code to inline code.

I did myself an inline coding.

You might encounter an issue with weird characters breaking your lines in the email body, I am curious if this happens to you too, if so let me know. I think I have the fix for that too.

# Answer
> 1 votes
The mail.css file should live in the root of your current theme. In fact if you're using an external stylesheet then you need to do this to avoid a WSOD as you may hit this bug.

---
Tags: theming, 6, mimemail
---


# Question
Title: Cannot see Display Suite menu under Administration
I am following this training. I have downloaded the module and have also enabled it. The video mentions a new 'Display Menu' under 'Administration'. I can't see it, though I am logged in as an administrator.

What am I doing wrong? (I am still new to Drupal)

**UPDATE**

I just tried to install the Module on a fresh install, and I don't get an issue there. Looks like my current system is corrupted. Is there any tool to 'correct' it?

# Answer
> 2 votes
Try clearing your drupal cache, or alternatively try visiting the URL directly under `admin/structure/ds`

---
Tags: 7, routes, caching, display-suite
---