# Question
Title: Enabling modules my site has been partially crashed?
When I enabled some modules (Drupal Chat, Chat room, and Node.js) my site crashed, and it reported some errors; I have removed my modules entirely, and reloaded the site, but still the errors are showing on the dashboard.

> PDOException: SQLSTATE\[40001\]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction: DELETE FROM {semaphore} WHERE (name = :db\_condition\_placeholder\_0) AND (value = :db\_condition\_placeholder\_1) ; Array ( \[:db\_condition\_placeholder\_0\] =\> menu\_rebuild \[:db\_condition\_placeholder\_1\] =\> 20854936424f460742220126.19788787 ) in `lock_release()` (line 254 of /var/www/mute/includes/lock.inc

How can I fix this?

# Answer
My guess from the general content of the message is that something went wrong while those modules were installing relating to database modifications. If you were making backups of the database, you should revert. Or are you saying that you did revert and still have the problem? If so, I am at a bit of a loss to know why. It could be a problem with the database engine and you may want to backup your current database, reinstall your database software, and restore your database.

Remember, if you installed these modules by simply copying the modules into the directory, you should run the command 'update.php' on the URL to insure that the database is configured correctly and Drupal is getting the correct information about the database and the status of all the modules.
> 0 votes

---
Tags: database
---


# Question
Title: Why doesn't the option "User:roles"  show in "Contextual Filter"?
I can't see the option "User: roles" in the contextual filter, and when I select "Relationships" I don't see "User Roles". What happens?

# Answer
You should add a relationship "Content:author"; then, the "User:role" filter will appear in "Filter criteria."
> 4 votes

---
Tags: views
---


title: User registration question

text:
# Question
Title: User registration question
I have built a new form from scratch. I was examining a code example displayed on here earlier, but I am not sure if I fully understand the syntax.

So far I have the following code:

```
$items['user/register'] = array(
    'title' => 'a large ferrret',
    'page callback' => 'redirect_custom_reg_form',
    'page arguments' => array('user_register_form'),
    'access callback' => TRUE,
    'type' => MENU_LOCAL_TASK,
);

```

I looked at a similar example in my book, and it looks like the page callback is used to build the form. I have used a similar example which uses the page callback.

Could someone please explain this function to me. I understand that this is a menu alter function. this should check to see if the user/register page is set

```
function redirect_custom_reg_form__menu_alter(&$items) {
  if (isset($items['user/register'])) {
    $items['user/register']['page arguments'] = array('mymodule_user_register_form');
  }
}

function mymodule_user_register_form($form) {
 $fields['legal_agreement'] = array (
    '#type' => 'fieldset',
    '#title' => t('Legal Agreement')
 );

 $fields['legal_agreement']['PL'] = array (
    '#type' => 'checkbox',
    '#title' => t('Legal Agreement')
 );

 $fields['legal_agreement']['decision'] = array(
    '#type' => 'radios',
    '#description' => t('By registering at %site-name, I certify that I am over 18 and have read and accepted the terms and conditions of the pravacy policy', array('%site-name' => variable_get('site_name', 'drupal'))),
    '#default_value' => 0,
    '#options' => array(t('I disagree'), t('I agree'))
 );

 return $fields;
}

```

I then made the assumption that I need a page callback method and this callback builds my page. It does not seem to be rebuilding anything.

# Answer
In Drupal 6, you implement hook\_user() to add the extra fields to the registration form implemented by Drupal.

```
function mymodule_user($op, &$edit, &$account, $category = NULL) {
  if ($op == 'register' && $category == 'account') {
    $form['legal_agreement'] = array (
      '#type' => 'fieldset',
      '#title' => t('Legal Agreement')
    );

    $form['legal_agreement']['decision'] = array(
      '#type' => 'radios',
      '#description' => t('By registering at %site-name, I certify that I am over 18, and I have read and accepted the terms and conditions of the privacy policy.', array('%site-name' => variable_get('site_name', 'drupal'))),
      '#default_value' => 0,
      '#options' => array(t('I disagree'), t('I agree'))
    );

    return $form;
  }

  if ($type == 'validate' && $category == 'account') {
    // If the user needs to always agree with the conditions, this is the place to show an error message.
  }
}

```

If you want to completely replace the registration form used by Drupal with your own, then you need to implement hook\_menu\_alter().

```
function mymodule_menu_alter(&$items) {
  if (isset($items['user/register'])) {
    $items['user/register']['page arguments'] = array('mymodule_user_register_form');
  }
}

function mymodule_user_register_form() {
  $form = array();

  // Add the form fields for the registration form.

  return $form;
}

```

In Drupal 7, as you are just adding form fields to an existing form, you need to implement hook\_form\_FORM\_ID\_alter() using code similar to the following one:

```
function mymodule_form_user_register_form_alter(&$form, &$form_state) {
  $form['legal_agreement'] = array (
    '#type' => 'fieldset',
    '#title' => t('Legal Agreement')
  );

  $form['legal_agreement']['decision'] = array(
    '#type' => 'radios',
    '#description' => t('By registering at %site-name, I certify that I am over 18, and I have read and accepted the terms and conditions of the privacy policy.', array('%site-name' => variable_get('site_name', 'drupal'))),
    '#default_value' => 0,
    '#options' => array(t('I disagree'), t('I agree'))
  );
}

```

The variable that contains the form definition is `$form`, and the hook doesn't need to return any value, as the form that needs to be modified is passed by reference.

This is very similar to the example code reported in the documentation page for `hook_form_FORM_ID_alter()`, which uses the following code:

```
  // Modification for the form with the given form ID goes here. For example, if
  // FORM_ID is "user_register_form" this code would run only on the user
  // registration form.

  // Add a checkbox to registration form about agreeing to terms of use.
  $form['terms_of_use'] = array(
    '#type' => 'checkbox',
    '#title' => t("I agree with the website's terms and conditions."),
    '#required' => TRUE,
  );

```

If you want to completely replace the registration form used by Drupal with your own, then you need to implement hook\_menu\_alter().

```
function mymodule_menu_alter(&$items) {
  if (isset($items['user/register'])) {
    $items['user/register']['page arguments'] = array('mymodule_user_register_form');
  }
}

function mymodule_user_register_form($form, &$form_state) {
  // Add the form fields for the registration form; the variable containing it is $form.

  return $form;
}

```

To notice that in the Drupal code, the form builder receives `$form` as argument. The common error when porting code from Drupal 6 to Drupal 7 is to still have `$form = array()` at the beginning of the form builder function. In both the cases, when you implement `hook_menu_alter()`, your module needs to handle all the registration process.
> 0 votes

---
Tags: forms
---


# Question
Title: How to set an openlayers preset to full screen?
I am working on one of those sites that need a fullscreen dynamic map to show up as a background. This means the preset should be set to 100% height, but I can't get this to work. Is there a module for that? A jQuery snippet?

# Answer
Looking at zzolo.org (the module mantainer's website) I learned that position:fixed (yes a CSS solution) can actually get this done.
> 0 votes

# Answer
On the OpenLayers project page, it says:

"Behaviors Map interactions like popups, zoom controls, editing, and fullscreen can be added via the UI and extended by other modules."

I don't have a site up and running with OL or I'd check it.
> 0 votes

---
Tags: 6, javascript
---


# Question
Title: Any suggestions for a adobe indesign like body field?
I'm on d7. I am looking for any suggestions on modules that can give me the functionality to have a field that acts like adobe indesign. (For the purpose of this explanation I am going to call this my "canvas" field) I would like for my canvas field to be a container that holds text/images/videos/audio instead of just text like a body field would. I would like to provide my users with the ability to write some text in a something like a text box and be able to resize and position it where they want in the "container" field along with images etc. Does anyone have any suggestions? Even a combination of modules or something to get me started would be very appreciated. Thanks.

# Answer
The WYSIWYG module http://drupal.org/project/wysiwyg will allow you to offer a rich text editor for your users. You can combine that with the Media module http://drupal.org/project/media to embed media files. It won't be like indesign exactly but will allow users to have some freedom with the content.
> 1 votes

---
Tags: 7, entities, javascript
---


# Question
Title: Change user profile image on profile page to activate colorbox
This is for Drupal 7.

Currently on the default user profile page, the profile picture just links back to their profile. I'd like to change this so it opens a colorbox. Thoughts?

**SOLUTION**

Add the following to your theme's template.php file.

```
<?php
function ccom_preprocess_user_picture(&$variables) {
  $variables['user_picture'] = '';
  $original_image = NULL;
  if (variable_get('user_pictures', 0)) {
    $account = $variables['account'];
    if (!empty($account->picture)) {
      // @TODO: Ideally this function would only be passed file objects, but
      // since there's a lot of legacy code that JOINs the {users} table to
      // {node} or {comments} and passes the results into this function if we
      // a numeric value in the picture field we'll assume it's a file id
      // and load it for them. Once we've got user_load_multiple() and
      // comment_load_multiple() functions the user module will be able to load
      // the picture files in mass during the object's load process.
      if (is_numeric($account->picture)) {
        $account->picture = file_load($account->picture);
      }
      if (!empty($account->picture->uri)) {
        $filepath = $account->picture->uri;
      }
    }
    elseif (variable_get('user_picture_default', '')) {
      $filepath = variable_get('user_picture_default', '');
    }
    if (isset($filepath)) {
      $alt = t("@user's picture", array('@user' => format_username($account)));
      // If the image does not have a valid Drupal scheme (for eg. HTTP),
      // don't load image styles.
      if (module_exists('image') && file_valid_uri($filepath) && $style = variable_get('user_picture_style', '')) {
        $variables['user_picture'] = theme('image_style', array('style_name' => $style, 'path' => $filepath, 'alt' => $alt, 'title' => $alt));
        $original_image = image_style_url('large', $filepath);
      }
      else {
        $variables['user_picture'] = theme('image', array('path' => $filepath, 'alt' => $alt, 'title' => $alt));
      }
      if (!empty($account->uid) && user_access('access user profiles')) {
        if (isset($original_image)) {
          $attributes = array(
            'attributes' => array('title' => t('View expanded image.'), 'class' => t('colorbox')),
            'html' => TRUE,
          );
          $variables['user_picture'] = l($variables['user_picture'], "$original_image", $attributes);
        }
        else {
          $attributes = array(
            'attributes' => array('title' => t('View user profile.')),
            'html' => TRUE,
          );
          $variables['user_picture'] = l($variables['user_picture'], "user/$account->uid", $attributes);
        }
      }
    }
  }
}
?>

```

# Answer
Theme API is your friend.
> 1 votes

---
Tags: 7, users, javascript
---


# Question
Title: How to add e-mails in 2 different databases in drupal 7
I used drupal 7.10 to built my website and i used 2 modules, the first is the webform to build the membership form, and the simplenews to write and send newsletter to users.

Anyone could subscribe in the newsletter even if it is not a member by enter her\his email in a newsletter subscribtion block in the home bage.

but what i wnat is that, when a user becomes a member he will join the newsletter service by adding his e-mail directly to a newsletter database, he don't need to enter his email in the newsletter subscribtion block agine.

How can i do this???

# Answer
> 2 votes
You have an option in Simplenews to subscribe the user on registration since 6-x.2.x : http://drupal.org/node/658242.

---
Tags: webforms, emails
---


# Question
Title: Drupal 6 Webforms sends duplicate emails
A user fills out a webform that I created and it gets emailed me. Sometimes I get duplicate emails when they fill it out. I'm thinking that this is because they are hitting the submit button multiple times.

Is there a way to avoid these duplicate emails from happening? I use the smtp authentication support module and gmail to send the request out. Perhaps it's taking too long connect with gmail and the user is getting impatient, thus feeling the need to press the button continuously.

# Answer
> 2 votes
Your can deactive the submit button after it was clicked with custom javascript.

I write a sample below:

```
Drupal.behaviors.FormSubmitDisable = function (context) {
  $('YOUR BUTTON ID').click(function () {
    $(this).attr("disabled", "true");
  });
};

```

---
Tags: 6, webforms, emails
---


# Question
Title: Call to a member function label() on a non-object in entity module
I created an entity type using Entity API and made it exportable. The `export` link works properly but on `Import` I have this error:

> Fatal error: Call to a member function label() on a non-object in \[...\]\sites\all\modules\entity\entity.module on line 903

I couldn't find any reason.
Here's my `hook_entity_info()`:

```
$return = array(
  'event' => array(
    'label' => t('Event'),
    'entity class' => 'EventClass',
    'controller class' => 'EventController',
    'base table' => 'calendar_events',
    'fieldable' => TRUE,
    'entity keys' => array(
      'id' => 'eid',
    ),
    'load hook' => 'events_load',
    'view modes' => array(
      'full' => array(
        'label' => t('Default'),
        'custom settings' => FALSE,
      ),
    ),
    'label callback' => 'entity_class_label',
    'uri callback' => 'entity_class_uri',
    'module' => 'events',
    'access callback' => 'event_access',
    'exportable' => TRUE,
    'admin ui' => array(
      'path' => 'admin/structure/events',
      'file' => 'events.admin.inc',
      'controller class' => 'EventsUIController',
    ),
  ),
);

```

Tell me if you need more information.

\[EDIT\]
I figured that the error has been occurred in `entity_class_label($entity)` in `sites/all/modules/entity/entity.module:903`. I printed the content of `$entity` and it seems it is `NULL`!
Why is it `NULL`?

# Answer
It looks like this is a bug in the Entity API module.

An issue with exactly the same error message was reported here to do with the Profile2 module (which uses Entity API pretty heavily).

The upshot of that post is that the problem is an Entity API bug, details of which you can see at: Load reference field when building contents.

As you can see from the above there are patches available to fix the problem. The most recent patch that passed testing was on the 16th November 2011.

When you look at the Entity API module's latest stable release you can see it's date sas the 10th November 2011. This means that the patch probably hasn't made it into the stable version yet, so won't have been fixed in your version of the module.

There are two things you can do:

* Upgrade to the dev version of the Entity API module (of course the usual amount of caution should be taken and you probably won't want to do this for a live site).
* Apply the patch to the entity.controller.inc file that seems to have solved the problem for other users.
> 2 votes

---
Tags: 7, importing-exporting, entities
---


title: Specify a template for referenced nodes

text:
# Question
Title: Specify a template for referenced nodes
I was wondering how to specify a specific template for rendering a node when it's referenced from another content type.
For example I have a content-type (product) and I use the `node--product.tpl.php` template to render nodes of this type. Then I have a content-type named `container` that have a `node reference` field that may related a number of `product` nodes.
I would like to use a different template when rendering a `product` when the product is referenced from the `container` content-type.
I just installed the `theme developer` module and check suggested templates, I then created a new template named `node-reference--product.tpl.php` in the same folder as `node--product.tpl.php` but this file is only used if `node--product.tpl.php` is removed.
I guess one approach would be to use some kind of `theme_preprocess` hook and load a node based on the `arg(1)` value and then check if the type is `container` and if it is add a template suggestion in the `$variables` parameter.

# Answer
The simplest thing you can do is provide a new "View Mode" for nodes, so that you can use it with the "Rendered Node" display option for the node reference field.

This would be done in a small custom module using `hook_entity_info_alter()` like so:

```
function MYMODULE_entity_info_alter(&$info) {
  $info['node']['view modes']['node_reference_product'] = array(
    'label' => 'Node Reference Product',
    'custom settings' => TRUE
  );
}

```

Once the module is installed you'll have a new view mode under the "Rendered Node" display format options:

Now you can simply use the same `node--product.tpl.php` template file as normal and just test for the view mode to define what you want to display:

```
<?php if ($view_mode == 'full') : ?>

  <!-- HTML output for the full view mode -->

<?php elseif ($view_mode == 'teaser') : ?>

  <!-- HTML output for the teaser view mode -->

<?php elseif ($view_mode == 'node_reference_product') : ?>

  <!-- HTML output for your new view mode -->

<?php endif; ?>

```

Of course you still have access to the view mode in any `hook_preprocess_node` function so you could put your logic in there instead:

```
function MYTHEME_preprocess_node(&$vars) {
  if ($vars['view_mode'] == 'product_node_reference') {
    $vars['content'] = array('#markup' => 'Some other content');
  }
}

```

But perhaps the best part of solving your problem this way is that Drupal honours the new view mode in the UI, so for each content type you will now have a new view mode which you can choose options for as normal:

Just like the standard `full` and `teaser` view modes you will be able to decide which fields are displayed, and the ordering and format in which they are displayed too. It's entirely possible that after writing that tiny one-function module you won't need to write another line of code to solve the problem.

You'll also have this view mode available system wide for use in, for example, Views/Panels etc.
> 5 votes

# Answer
It might be simplest to create a different field formatter for the entity reference on the container node. Instead of the default "Title(link)" or "Rendered Node" you can add one and theme it however you would theme the separate node templete you were trying to theme. See a writeup here: http://www.computerminds.co.uk/articles/creating-new-field-formatters-drupal-7 . In your hook\_theme() you could specify a template instead of a function. I would choose this over creating a check in theme\_preprocess() as it is easier to manipulate if you want to change it in the future.

I might also check out the Display Suite module if you haven't yet which will allow you to move parts of the node around in the content type settings form. It has some similar features to Panels but is much more lightweight. It might save you from creating separate node templates at all.
> 2 votes

---
Tags: 7, theming, nodes
---


title: Module release date and commit date?

text:
# Question
Title: Module release date and commit date?
I can't understand somethings about commits.

For example, for the Webform module, in its project page it is written that last version is "7.x-3.15 2011-Dec-08," but in the commits page, it is written that there is commits to 7.x-3.15 in 25 February 2012.

I also checked the releases page; one of them has been released on December 2011, and another has been released on February 2012.

Does it mean that these versions were commited to git, but not released? So it was an unstable version? Is this usage common for Drupal module releases?

# Answer
It is common in pretty much every software project. It makes no sense to release a new version for every single change unless it is critical enough (e.g. security fix). So releases are e.g done on a regular schedule (Drupal core does one every month now).

It is common practice to list the issues that where implemented/fixed as part a release in the release notes.

There are usually multiple commits every day on Drupal core, imagine there would be a new version every time.

What's somewhat uncommon with Webform is that it they don't list their development snapshot releases on the project page. Those are automatically updated twice a day if there have been any commits. In case of Webform, that snapshot still exists, but, according to the description, should only be used for testing recently fixed issues: http://drupal.org/node/730862.

The quality of development snapshots can heavily vary between projects so it's generally not recommended to use them. One exception for example is if you encounter a bug in a module then it often makes sense to test the snapshot first if there is a newer version than the last release.
> 6 votes

---
Tags: community-official-site
---


# Question
Title: What is the relationship between regions and panels?
From here, it is clear that regions contain blocks, but when working with Panels, are regions still relevant? If yes how? What is the relationship between regions and panels? Thanks.

# Answer
Panels can be thought of as self contained themes you define within a specific Drupal Theme displaying the page. Like Drupal themes, panels also contain regions, but you define them, rather than the default theme.

And to expand upon this a bit more:

Panels presents a way to display content similar to a theme, but in a more modular fashion. This site gives an excellent example of how panels can be used. A mini-panel, for instance, is used similarly to a block and can, in fact, be placed in a region of a theme just like blocks are. The advantage is that a panel/mini-panel can contain its own layout regions further breaking down the layout. For instance, the signature blocks in this Drupal Answers question layout contains the top line with how long ago the question was asked, the avatar, authors site name and reputation. Using mini-panels this configuration could be defined as a single mini-panel and placed inside a larger panel that holds other mini-blocks laying out the arrows and other graphics at the left side, the actual question, the tags and the action links such as links, edit, etc.

This larger panel construct can also be placed within a theme region such as the 'content' area giving the site display you see for your question page. Other content such as a list of the answers to your question can also be added to the main content area. Other regions such as right sidebar can hold the related questions links. In this way your panels are placed within the existing theme framework providing additional content layout flexibilities.

Panels can be laid out in prearranged formats or be user designed as custom layouts. These panel layouts contain their own regions so you are in-essence adding regions within a theme regions.

Panels can also go one step further and totally replace the theme layout using the Panels Everywhere module. This offers the user the ability to control the layout and styles directly. While contributed themes can be very flexible and sophisticated, these very capabilities can also make them very complex and difficult to modify to meet individual project demands. The more experienced you become in using Drupal, the more attractive this ability may become for you.

Panels also offer another advantage. The panels module works very well with CTools Page Manager, joining graphic control with Page Manager's content control. In this way you can intercept URL requests before Drupal responds and set rules and layouts to respond to various context conditions using 'Variants'. IN this way you can vary the content depending upon the permission levels of a user, or the content type being requested. If specific conditions are not met, then panels/page manager, returns display control back to Drupal. In addition, panels can display views and even pass its context to the view to determine what the view will show. All of this gives the designer the control necessary to duplicate the content and layout this site provides.
> 9 votes

---
Tags: 7, panels, theming
---


title: submit button not working correctly

text:
# Question
Title: submit button not working correctly
To fix the problem with the submit function I have tried clearing my cache I have also tried uninstalling the module and reinstalling the module. the code segment is below.

The submit function for some reason never is run

```
function redirect_custom_reg_menu_alter(&$items) {
  if (isset($items['user/register'])) {
    $items['user/register']['page arguments'] = array('redirect_custom_reg_user_register_form');
  }
}

function redirect_custom_reg_user_register_form() {
  $form = array();

  // Add the form fields for the registration form.

  $form['personal']['username'] = array(
    '#type' => 'textfield',
    '#title' => t('username'),
    // this is built in validation to the form api
    '#required' => TRUE,
    // control the size parameter
    '#size' => 20,
    '#prefix' => '<div id="foo">',
    '#suffix' => '</div>',
    '#description' => 'Please enter your first name',
    '#maxlength' => 25,
  );

  $form['name']['formtype'] = array(
    '#type' => 'radios',
    '#title' => t('form type'),
    '#options' => array(
      t('form1 form'),
      t('form2 form'),
      t('form3 form')
    ),
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
  );

  return $form;
}

function redirect_custom_reg_submit($form, &$form_state) {
  drupal_set_message(t('The form has been submitted. personal="@username"',
    array('@username' => $form_state['values']['username'] )));
}

```

# Answer
Your form function is called `redirect_custom_reg_user_register_form()`, so your submit function needs to be called `redirect_custom_reg_user_register_form_submit()`.

If you want to keep the same submit function name that you have currently, you need to add it manually in the form function as Drupal only looks for a function called `FORM_FUNCTION_NAME_submit()` by default:

```
$form['#submit'][] = 'redirect_custom_reg_submit';

```
> 4 votes

---
Tags: forms
---


# Question
Title: How to get width and height of user pictures?
It seems that Drupal doesn't store the width and height of uploaded user profile pictures (standard profile, not profile2).

I would like to be able to link the profile thumbnail to a larger version if the uploaded image is larger than 480 pixels.

Is that possible without jumping through too many hoops?

I can require new users to upload pictures with a minimum size but I have imported lots of profile pictures and many are smaller than 480 pixels wide or high.

# Answer
You can add an image field to the user entity. Then you can create a custom field formatter that can check if images are over a certain size and display a link to the larger size if they are. Here is an article on creating a field formater in Drupal 7: http://www.computerminds.co.uk/articles/creating-new-field-formatters-drupal-7
> 2 votes

# Answer
You should be able to so everything with Image cache. Create a layout for the user profile picture and tell fields to link to the original One.
> 1 votes

---
Tags: 7, media
---


# Question
Title: Best way to deal with node data that should only be displayed in views
> **Possible Duplicate:**
> How to prevent access to Views-only content?

Sometimes I build a content type whose data really only makes sense to display in a View. An example would be a content type called "Slide" and a View called "Slideshow". I may not want people or search engines to actually go to the node because the slideshow is displaying a series of slides, and by itself, the "Slide" is not very interesting.

So what strategies do site builders usually employee in this situation? Do they style the "Slide" node so that if someone goes there, it looks OK? Do they un-publish the "Slide" so only admins can access it, and then program the view to not filter on only published content?

# Answer
> 0 votes
A couple strategies here...

One is the obvious one you mention: Don't publish the 'Slide' content type, so it never appears on the 'live' site.

Another is that you don't make special 'slideshow' content types. You just add fields to your normal content types that will be displayed in a slideshow display mode. Then you hide them for other display uses like Default and Teaser.

Drupal's flexibility with this type of scenario is one of its major strengths. But it also means that site editors have to remember which field does what, or which type of nodes not to publish.

---
Tags: views, entities
---


# Question
Title: When using features to manage deployment, should I break my functionality into many little features or one big feature?
I'm relatively new to the features module and I've read contradictory recommendations online regarding whether it's easiest to maintain A) one big feature or B) several smaller ***features*** and then a "***feature-controller***" type module that lists all the smaller features as dependencies.

A bit about my specific situation: I'm using a `local development -> dev server -> staging server -> live server` workflow. This particular site will almost certainly be the only one of its kind that I ever develop; I do not intend to use the `features` I create for this site on any other sites.

This makes me lean toward doing everything in one big feature because I've had problems in the past where I accidentally defined the same rules in multiple features and gotten into trouble. However, in terms of structure this seems wrong to me-- there are different features/functions so they ought to be divided into separate features. On the other hand, I feel like by doing this I may just create additional work and overhead for myself that won't benefit anyone.

Which approach is easier to maintain in actual practice-- one big feature or many smaller ones?

# Answer
**Make several little Features, split by conceptual layer**.

Advantages:

1. Granularity when reviewing Overrides and performing Reverts — so you don't *have* to revert everything at once.
2. Modularity — even if you don't plan to reuse individual components, breaking things down into discrete modules will help with maintainability.

For deploying a single site from development to test to production, we use the following taxonomy (where "site" is replaced with a unique machinename for the site) —

* `site_types` Feature — declares Content Types, Fields, ImageCache settings, User Roles
* `site_structure` Feature — declares Contexts, Views, Menus and Menu Links, Blocks, User Permissions, Variables
    + depends on `site_types` Feature
* `site_content` Feature — declares Nodes
    + depends on `site_structure` Feature

If there are multiple distinct site sections (for example, Public vs Private), consider splitting things up further:

* `site_types` Feature
* `site_structure` Feature — declares structural components common to both Public and Private
    + depends on `site_types` Feature
* `site_public_structure` Feature
    + depends on `site_types` Feature
* `site_public_content` Feature
    + depends on `site_public_structure` Feature
* `site_private_structure` Feature
    + depends on `site_types` Feature
* `site_private_content` Feature
    + depends on `site_private_structure` Feature
> 7 votes

---
Tags: 7, features
---


title: Change Views Ajax speed

text:
# Question
Title: Change Views Ajax speed
I've got a view with a few exposed filters. Is there a way to change the submit speed of the ajax request? So that rather than submitting the request after every key press, it waits until no keypress has been registered for say 500ms before submitting the request? I'm having problems, especially on mobile, where you might type "ar" in the exposed filter, but end up seeing the results for "a", with the filter set back to "a".

# Answer
```
function do_search(e) {
  clearTimeout(search_timer);
  search_timer = setTimeout(function() {
    var v = $("#YOUR_INPUT_VAR_ID").val();
    p(v);
    CALL THE AJAX HERE
  }, 500);
}

```
> 3 votes

---
Tags: views, ajax
---


# Question
Title: How do I count the number of items of same product class in cart?
I'm a newbie to PHP, I and can't figure out how to do this.

I'm trying to alter the price of each items depending on the quantity of the items of same product class in the cart. Let's say I have a product class "fruit" and 10 items like "apple" ,"orange", "banana" and so on. And no matter which combination, I would like to make the first item $10, the second one $0, the third one $0. So I tried this code by using UC Custom Price but doesn't work.

```
$firstPrice = 10;
$secondPrice = 0;
$thirdPrice = 0;

if ($item->qty = 1) {
  $item->price = $firstPrice;
}
elseif($item->qty = 2) {
  $item->price = $secondPrice;
}
elseif ($item->qty = 3) {
  $item->price = $thirdPrice;
}

```

It obviously seems that `$item->qty` is the quantity of a single item (the same node). So how can I call do this with the number of the items of this product class "fruit "in the cart? `$item->price` is the final price which will be used.

# Answer
> 0 votes
Your code is wrong because, instead of comparing the value of `$item->qty`, you are setting them in each control statement. Replace `=` with `==`.

```
if ($item->qty == 1) {
  $item->price = $firstPrice;
}
elseif($item->qty == 2) {
  $item->price = $secondPrice;
}
elseif ($item->qty == 3) {
  $item->price = $thirdPrice;
}

```

The code you wrote works because an assignment statement is also an expression that have the assigned value as its value.

Instead of writing an IF-statement, you could used a SWITCH-statement.

```
switch ($item->qty) {
  case 1:
    $item->price = $firstPrice;
    break;

  case 2:
    $item->price = $secondPrice;
    break;

  case 3:
    $item->price = $thirdPrice;
    break;
}

```

# Answer
> 0 votes
Thanks to @kiamlaluno I ended up like this for my need and it works. Also this was useful

```
 // Load the current shopping cart.
      $items = uc_cart_get_contents($cid = NULL, $action = NULL);

    // Count the number of items
      $number_of_items = count($items);

    $firstPrice = 10;
    $secondPrice = 0;
    $thirdPrice = 0;

    switch ($number_of_items) {
      case 0:
        $item->price = $firstPrice;
        break;

      case 1:
        $item->price = $secondPrice;
        break;

     case 2:
        $item->price = $thirdPrice;
        break;
    }

```

---
Tags: 6, ubercart
---


# Question
Title: How can I update/revert a feature which includes page manager and mini panel components that is stuck as overriden?
I have a feature which includes page manager and mini panel components that is stuck as overriden?

I have tried reverting and updating the feature both from the web ui and also from drush to no effect. I don't get any error messages but after clearing the cache twice the feature is still marked as overriden.

Generating a diff reveals about twelve differences that look like this: +'new-6' =\> array( -'new-1' =\> array(
+'pid' =\> 'new-6', -'pid' =\> 'new-1',

I assume this is the result of the site on which I created the feature having a lot more content already in place than the site on which I have installed the feature, which has no other content.

I also tried removing the offending parts (those related to page manager and panels) from the feature, updating the feature, and then adding them back onto the feature using the web ui, but it still displays as overriden.

I found this thread but there wasn't any particularly helpful information: http://drupal.org/node/744450

Any ideas about how I can update or revert this feature?

# Answer
> 4 votes
**Attempting to answer the question:**

You should be able to simply re-export the feature to update the pane identifiers in code.

**Background info:**

There are two parts to this problem. First of all, features uses a different way of determining whether or not something is overridden, than ctools does. So Ctools consider the state to be "in code", but features, "overridden".

Secondly, the way panes are identified have recently changed. The change initially came about to solve a particular bug, but now causes other problems instead, namely the 'new-X' "overrides".

There are several different patches in the Panels queue that all have different ideas on how this problem should be solved. Currently, I'm afraid to say that I believe you can't do a great deal about this. The current behavior simply isn't optimal.

You can read more in this issue, and the ones that are linked to.

---
Tags: 7, panels, features
---


# Question
Title: How do I add an field containing image links?
I need a list of images in a view that all link to a third party page.

# Answer
> 3 votes
In the field formatting/rewriting options, you can check "Output this field as a link" and then enter your third party external link.

---
Tags: media, navigation
---


# Question
Title: Allow a user to select where to save an uploaded file
I have installed an Open Atrium, which is based on Drupal 6, but this is a rather general question towards Drupal 6.

In every content type I have an Upload File field which work just fine, but it does not quite meet my requirements. I have already defined an directory structure on my server, which I would like to maintain as is. Therefore, the functionality I am trying to achieve is to allow a user, who selects a file to upload from local computer, to be able to select the path where to store it (preferably outside of Drupal installation).

To be able to reach an outside directory I have created an alias to the necessary directory (e.g. `C:\blalbla\ --> localhost/dev`).

# Answer
> 1 votes
You could use a text input with select list, allowed values list will be generated with php code reading the directory you created, then using File (Field) Paths you will save the upload on the select list input.

# Answer
> 0 votes
You could set up a taxonomy vocabulary that stores folder names and then use filefield paths to generate the upload path from those taxonomy terms.

---
Tags: 6, files, distributions
---


# Question
Title: Create a block showing the latest of a certain content type
I am very new to drupal, so I already apologize if I ask something very simplistic...

I have a site where I would like to add a new block to the front page of the website. This block would show the companies newest available training's. I created the sub-pages of the training's. My thought process was that I create the sub-pages, then create a new type of content (with the cck) where I can add the new sub-page node names and their links. I created the new content type with two fields. field\_offeringlink and field\_offeringtext. Where the the text would be the actuall promotional text and the link directing to the sub-page. After this I wanted to create a Block that I would place on the front page, showing these two fields. I couldn't figure out this part... So how do I make the bloody block show my fields?

OR

If you have a better idea for this whole shannanigan then I am welcome to ideas.

My goal:

Create a dynamic block on the front page, that shows all the latest training's. Under dynamic I mean, that we can add-remove the links from the admin/content menu.

Thanks in advance!

# Answer
You want to create a content type for Training. Then you can add Fields for things like start and end dates, registration deadlines, difficulty ratings, whatever.

Then you want to have a View that exposes a Block, for content type Training. The view shows the 5 (or however many) newest Training nodes that you've created. You can accomplish all this on the first, 'easy' page when you create the new view.

Also, since you used Views, you can then move on to, for instance, showing only Trainings whose registration deadlines have not passed, and so forth.

But basically Views does all the heavy lifting. If you ever find yourself thinking: 'I need to make a page that lists all these nodes,' then what you really need is Views.
> 1 votes

# Answer
This definitely sounds like a job for views. I could explain how to do this exactly BUT for your own learning you should install views and go through the documentation also as you will thank me in the long run for not explaining exactly how to do it. You do not need to do it the way you have started doing it already, Views will manage everything you have already tried to accomplish with listing articles.

If you want a shortcut without going through the documentation, click this which will give you a thousand tutorials to do what you want to do.
> 1 votes

---
Tags: blocks, nodes
---


title: Uploaded image width

text:
# Question
Title: Uploaded image width
After uploading an image, it is re-sized to a width of 904 pixels; I need to keep the original file (1080 pixels).

# Answer
> 0 votes
Imagecache (drupal 6) and Image Style (drupal 7) modules copy your image from your base files directory (default is "sites/default/files") and place the resized image an a folder based off of the name of your style (thumbnail would be "sites/default/files/imagecache/thumbnail").

Both modules don't remove the original image from the base files folder. They just create a copy. So your original file that is 1600 pixels should be a available in your base files folder.

"example\_image.jpg" uploaded to example.com using Drupal 6, would be found in: http://example.com/sites/default/files/example\_image.jpg (original) http://example.com/sites/default/files/imagecache/thumbnail/example\_image.jpg (created by imageache using "thumbnail" preset).

# Answer
> 1 votes
It was my problem: I took the original dimensions wrong, then Drupal resized the original image to fit the max dimensions.

---
Tags: 7, media
---


title: Unexpected MYSQl error 1286

text:
# Question
Title: Unexpected MYSQl error 1286
I am using shared host and after some problems they restarted the server and my Drupal website shows the following error:

```
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1286 Unknown table engine 'InnoDB': SELECT

```

This is the full log

Error message

> PDOException: SQLSTATE\[42000\]: Syntax error or access violation: 1286 Unknown table engine 'InnoDB': SELECT field\_data\_media\_gallery\_expose\_block0.entity\_type AS entity\_type, field\_data\_media\_gallery\_expose\_block0.entity\_id AS entity\_id, field\_data\_media\_gallery\_expose\_block0.revision\_id AS revision\_id, field\_data\_media\_gallery\_expose\_block0.bundle AS bundle FROM {field\_data\_media\_gallery\_expose\_block} field\_data\_media\_gallery\_expose\_block0 WHERE (field\_data\_media\_gallery\_expose\_block0.media\_gallery\_expose\_block\_value = :db\_condition\_placeholder\_0) AND (field\_data\_media\_gallery\_expose\_block0.deleted = :db\_condition\_placeholder\_1) AND (field\_data\_media\_gallery\_expose\_block0.entity\_type = :db\_condition\_placeholder\_2) AND (field\_data\_media\_gallery\_expose\_block0.bundle = :db\_condition\_placeholder\_3) ; Array ( \[:db\_condition\_placeholder\_0\] =\> 1 \[:db\_condition\_placeholder\_1\] =\> 0 \[:db\_condition\_placeholder\_2\] =\> node \[:db\_condition\_placeholder\_3\] =\> media\_gallery ) in field\_sql\_storage\_field\_storage\_query() (line 577 of /home/fossisor/public\_html/techiestuffs/modules/field/modules/field\_sql\_storage/field\_sql\_storage.module).

What is wrong with the database ?

# Answer
> 1 votes
Sounds like your hosting provider does not support InnoDB. There are a few others like you, here is a discussion thread with some ideas on how to fix it http://drupal.org/node/1089724

---
Tags: database
---


# Question
Title: Displaying custom module content in a popup from other page
I have a custom module which displays listings and info about realties. How can I display realty's images in a popup from other page? In example I have info about realty on realty/566 and it's images can be viewed realtyimages/566

# Answer
You may want to use the Lightbox2 module. It will display it in the same window but look like a pop-up in page, like in Facebook.
> 1 votes

---
Tags: 7
---


# Question
Title: Store user test results against their profile in Drupal Quiz Site
I have created a drupal quiz site without depending any quiz modules. I want the user to be able to save their Test result against their profile. So they can see when they log in.

The Result will be like this usually:

> **Total Result:** 24/30.
> **Main Subject:** Main\_Subject\_Name.
> **Sub-sub1 score:** 12/15.
> **Sub-Sub2 score:** 12/15.

There can be any no. of sub-subjects depending on test. It would be great if I could be able to pull them later with views.

This is what i have in mind. Create a content type results with 2 fields. User Id and Data. User id will hold the uid and in data i will add a json(ified) version of the result for later use. Is this ok? or are there any drupal specific ways to do this?

# Answer
You can also create fields directly attached to the User entity just as you would to a content type. It may make more sense to store the information for a specific user in fields attached to their identity directly. You can create views and panels to display the information however you want and provide hook functions in a custom module to do whatever specialized calculations you desire for presenting averages, grades etc.

I also noticed that you have used the Profile tag which relates to a module that has been deprecated for D7. If you have the module enabled, I recommend not using it for any future site since it will very likely not be maintained in D8.
> 2 votes

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


# Question
Title: How do I access webform components labels on the congratulations page
Am using the following code in the Congratulations page. There is more but this is the driving force to retrieve user submissions. Its working fine but I need to retreive as well the actual component labels. How do I include the actual questions (labels) on the form. Like if I have a component:

How old are you

* 10
* 25

How do I modify the code below to show "How old are you" on the congratulations page?

```
<?php
include_once(drupal_get_path('module', 'webform') .'/includes/webform.submissions.inc');
$nid = arg(1);
$sid = $_GET['sid'];
$submission = webform_get_submission($nid, $sid);
    for ($i = 1; $i <= 2; $i++) {
        echo $submission->data[$i]['value'][0];
    }
?>

```

# Answer
> 12 votes
The loaded submission doesn't hold the label names so you'll have to get them from elsewhere. One option would be to load the webform node where they can be found. Here's an example about how this would look like in the code:

```
<?php
include_once(drupal_get_path('module', 'webform') .'/includes/webform.submissions.inc');
$nid = arg(1);
$sid = $_GET['sid'];
$submission = webform_get_submission($nid, $sid);
$node = node_load($nid);
foreach ($node->webform['components'] as $key => $component) {
  if (isset($submission->data[$key]['value'][0])) {
    if ($component['type'] == 'select') {
      $options = array();
      $items = explode("\n", $component['extra']['items']);
      foreach ($items as $item) {
        $item_parts = explode('|', $item);
        if (isset($item_parts[0]) && isset($item_parts[1])) $options[$item_parts[0]] = $item_parts[1];
      }
      $no = count($submission->data[$key]['value']);
      if ($no > 1) {
        $cont = '<p><strong>'. $component['name'] .':</strong> ';
        foreach ($submission->data[$key]['value'] as $k => $v) {
          if ($k + 1 == $no) $cont .= $options[$v];
          else $cont .= $options[$v] .', ';
        }
        $cont .= '</p>';
        echo $cont;
      }
      elseif (isset($options[$submission->data[$key]['value'][0]])) {
        echo '<p><strong>'. $component['name'] .':</strong> '. $options[$submission->data[$key]['value'][0]] .'</p>';
      }
    }
    else {
      echo '<p><strong>'. $component['name'] .':</strong> '. $submission->data[$key]['value'][0] .'</p>';
    }
  }
}
?>

```

---
Tags: webforms
---


title: Linking Custom Content Types Together

text:
# Question
Title: Linking Custom Content Types Together
I'm attempting to create a site that lists my brother's DVD releases.

I've been able to do this with Views, but I would like a more user friendly interface so I don't have to administer the site in the future, and my brother can do it himself.

Basically I have two Content Types: Releases, and Scenes.

When creating a Release, I want (my brother) to be able to select Scenes that have already been added, and *arrange them in a specific order* as though they are a Custom Field in the Releases Content Type.

I don't think Views out of the box is friendly enough for my brother.

*Any* ideas, modules, hints, or search keywords that might help me engineer a solution?

# Answer
A reference module is what you're looking for. References is the standard right now, though there are other options such as Entity Reference.

To use your reference module, add a "node reference" field to your Release content type. When configuring that field, allow it to refer only to nodes of the "Scene" content type.

For the sort order, I believe if you use the autocomplete widget for your nodereference field then it should give you sorting capabilities on the Release node-add form, without needing another field in the Scene content type or any more work in Views. Just make sure when configuring the nodereference field that you set the number of allowed node references to "unlimited".
> 2 votes

---
Tags: views, files, nodes
---


title: function to change language object

text:
# Question
Title: function to change language object
I know this question may get the dafs-adrenalin of some of you viewers going. But I'm just recently getting my head in there with php and drupal and have been searching the api and googled a possible function only to find functions that did all sorts of other stuff.

It's that I have this custom logic where I want to change the language object after I've set a `$_COOKIE['lang']`. The value of the cookie lang would be a language code like `en` or `fr`. And going `$language->language -> $_COOKIE['lang'];` is pretty rediculous.

So the question maybe then is: I Know the value of `$language->language`, now I want to use the function that Drupal uses in core to construct the entire language object. This way the language object actually changes after the cookies is set and the locale module can to it's work to load the site in the new language?

# Answer
The list of language objects is built up by the core function `language_list()`, which you can use to overwrite the global `$language` object if you need to:

```
// Get the list of languages
$languages = language_list();

// Set up the new language code
$new_lang_code = 'fr';

// Make sure the required language object is actually set
if (isset($languages[$new_lang_code])) {
  // Overwrite the global language object
  global $language;
  $language = $languages[$new_lang_code];
}

```
> 6 votes

---
Tags: 6, i18n-l10n
---


# Question
Title: When to use a module vs. writing own code?
At the risk of asking a "too open ended question" I'm giving it a try:

I'm running into more and more situations where I have to decide to either use a module that does a lot more than what I need or just writing my own code or template mod.

For example, the password policy has features that I need, but also has a lot that I don't. The 47kb zip file size tells me that it's a lot of code for my small problem. I implemented my own password policy with less than 20 lines of code in a hook.

I'm trying to limit the total amount of modules installed to a max of around 100. However, since signups don't happen that frequently this module probably won't affect the overall site performance.

Does anyone have specific recommendations on when to use a module vs. writing own code? Especially when better runtime performance and reduced overall complexity are the main goals.

# Answer
> 4 votes
The way I go about deciding whether to use a module or write my own code is roughly the following:

1. If the functionality I need can be written with a couple of lines of code I don't even start looking for a module to do it. Using a module for every little thing often gets you a good portion of extra code and other data that you don't need. All the unnecessary extras could:

* negatively affect performance
    * make the site more complex and harder to maintain
    * result in more bugs
2. If there would be a considerable amount of code to write I'll look for possibly existing modules to make the task easier. Good reasons to use a existing module in my book:

* it fits the requirements fairly well: using the module (and altering it with hooks, adding extra functionality via a custom module where needed) to get exactly what's needed is easier/faster than writing everything from scratch.
    * the site administrator needs to be able to change specific settings via the GUI and the module already offers that.

# Answer
> 0 votes
One of solution is to write your global module which will contain all your little bundles of custom code.

---
Tags: 7
---


# Question
Title: Customised user registration / sign-up forms in Drupal 7
I want to have 2 customised registration/sign-up form for different users with different fields for their account and profile (like buyer and supplier). How to make different form or multi step form for each kind of user based on role.

How can it be accomplish? Please help in this regard. As after lot of search, i could not figure it out. Is there better approach which is being used then please let me know.

# Answer
> 2 votes
When you need different set of fields for different users you should have a look at the profiles 2 module. There's a good chance that you can acomplish your requirements without any coding.

BTW: This kind of question has been asked many times here. The search functionality will give you a lot of information about this topic.

# Answer
> 2 votes
I have found an answer by using the module Profile2 Registration Path.

> This module enables administrators to set unique registration paths per Profile2 profile type.
>
> ## Overview
>
> ### The Problem
>
> By default, the Profile 2 module permits you to add fields from chosen profile types to the default user registration form. Unfortunately, there is only one user registration form. Thus, every user will be presented with these fields during registration. If you have two profile types targeted at two different audiences, you cannot have two separate registration forms.
>
> ### The Solution
>
> Profile2 Registration Path enables you to set a unique registration path for each Profile2 profile type. Users who register via that unique path will be presented with fields from the chosen profile type(s).

# Answer
> 1 votes
You need to use a hook or theming the form. See Customizing the login form.

> ### Step 1 of 2
>
> In a text editor like notepad.exe, create a file called template.php using the the following snippet. If you already have a template.php file, simply add it to your existing one.
>
> Form variables are declared as render elements in hook\_theme functions that handle form or element theming. See the hook\_theme API documentation for more information.
>
> ```
> function mytheme_theme(&$existing, $type, $theme, $path) {
>   $hooks['user_login'] = array(
>     'template' => 'templates/user_login',
>     'render element' => 'form',
>     // other theme registration code...
>   );
>   return $hooks;
> }
>
> function mytheme_preprocess_user_login(&$variables) {
>   $variables['intro_text'] = t('This is my awesome login form');
>   $variables['rendered'] = drupal_render_children($variables['form']);
> }
>
> ```
>
> ### Step 2 of 2
>
> * In a text editor paste the following snippet into your user\_login.tpl.php file
> * Edit the style sheet classes and content to suit
> * Upload your edited user\_login.tpl.php to your active theme folder
>
> ```
> <p><?php print $intro_text; ?></p>
> <div class="my-form-wrapper">
>   <?php print $rendered; ?>
> </div>
>
> ```
>
> ### Style sheet reference
>
> For controlling how your login form looks using your style sheet, this is what the rendered login form HTML and class names are by default:
>
> ```
> <div class="form-item">
>  <label for="edit-name">Username: <span class="form-required" title="This field is required.">*</span></label>
>  <input type="text" maxlength="60" name="name" id="edit-name"  size="30" value="" tabindex="1" class="form-text required" />
>  <div class="description">enter your username</div>
> </div>
> <div class="form-item">
>  <label for="edit-pass">Password: <span class="form-required" title="This field is required.">*</span></label>
>  <input type="password" name="pass" id="edit-pass"  size="40"  tabindex="2" class="form-text required" />
>  <div class="description">enter your password</div>
> </div>
> <input type="hidden" name="form_id" id="edit-user-login" value="user_login"  />
> <input type="submit" name="op" id="edit-submit" value="Log in"  tabindex="3" class="form-submit" />
> <p><a class="textlink" href="?q=user/password">Forgotten your Password?</a></p>
>
> ```

(The PHP code shown is for Drupal 7.)

---
Tags: forms, users
---


# Question
Title: Why semaphore table is not using MEMORY as storage engine?
Drupal's table "semaphore" is using MyISAM (Drupal 6). I was wondering why it's not using MEMORY as storage engine? The only thing that I could think of is that Drupal needs locking/semaphore data after MySQL restart. But the point with semaphore is that it should not have important data...

Am I missing something?

# Answer
Drupal supports multiple database backends, but both MEMORY and the concept of storage engines as a whole is MySQL specific. Therefore, the Schema API has no support for specifying the storage engine.
> 9 votes

---
Tags: database
---


# Question
Title: What does Page Content contain in Panels Everywhere when site template is enabled?
Panels Everywhere (PE) configuration allows a site template to be used to *"wrap" any page in a panels display*.

If I edit the content of this panel, for example like this:

does it mean that any (I mean all) other page will be crammed in the `Page Content` item defined in the template?

In other words:

1. Are pages always inserted in the template's page content?
2. Is there anything else than pages ever ending in the template's page content? If yes, what and when?

# Answer
> 1 votes
A page panel will be placed where the main page content is located. The page panel will be displayed only when the conditions of its Selection rules and Contexts are satisfied. You can define alternatives by creating multiple variants for the panel and modifying the settings to meet your needs. Panels will search through the variants and go with the first variant that meets the criteria so the order you place the variants in may matter. Using Panels Everywhere, you would set the overall layout for your site pages in variants to the default site panel. The various page panels would then be displayed in the regions as defined for them.

You can also create mini-panels and view content panes which act similar to blocks except that, like page panels, you can define selection rules and contexts for them and place them anywhere else on the default panel variants you desire. So you can provide content related to your main content based upon the context (users, tax terms, field settings etc.) that apply to the main content display.

I'm not sure if I've fully answered your question. What do you want to achieve in your site setup?

---
Tags: panels, nodes, 7
---


title: Quickest way to get a landing page

text:
# Question
Title: Quickest way to get a landing page
What is the quickest way to create a landing page for Drupal 7? The landing page module is currently not available for drupal 7. What sort of modules should I use?

# Answer
> 1 votes
1. For the content: Use an approriate content type or view.
2. For the URL use an URL alias to get something like www.mysite.com/landingpage .
3. If you want to hide some blocks on the landing page add a PHP snippet in the block configuration which queries `arg()` or `$_GET['q']` for the URL.
4. If you need an other theme have a look at the ThemeKey module.
5. Use the Nodewords: D6 Meta Tags module to add meta tags for SEO or Facebook open graph tags.
6. Use the statistics or Google Analytics module to track the succses of your page.

# Answer
> 0 votes
Create a node or a view with a page display. Configure site information and set the path of previous item as default front page.

# Answer
> 0 votes
How about the Login Destination module? You can force users to log-in first and then you can redirect them to where ever you want!

---
Tags: 7
---


# Question
Title: How to use leanModal for loading a node or content in Drupal 7?
I'm using this http://leanmodal.finelysliced.com.au , but unable to achieve the goal since I need that after clicking on my button the new content or a url for an instance node/3 should get load in this modal, any idea how can I do it?

# Answer
The leanmodal javascript plugin specifically states that it does not include AJAX support. That means that whatever content you want to appear in your modal needs to be already included on the page content when the page initially loads.

If you want to load a different page's content in the modal, then you will need to use an approach that includes AJAX support. I would recommend one of the many Drupal options that provide this sort of functionality, such as Simple Dialog or cTools Auto-Modal.

The exact implementation will depend on the specifics of what content you are trying to load and in what context.
> 2 votes

---
Tags: theming
---


# Question
Title: How to remove colon in a label which is not in a form - D6
How can I remove colon from the labels which is not in a form?

If it is a form, `themename_form_element()` can be used, but my question isn't related to forms.

For example, I need to remove colons from the profile view page. How can I do that?

I would like to do this the "Drupal way" (meaning not using JavaScript/jQuery)

Thanks in advance.

# Answer
> 2 votes
Drupal 6 or Drupal 7? The Drupal way to do this would be to modify the content field template in your theme to remove the colon OR create a custom node template to render the fields without the colon. For the content-field option, in Drupal 6 this file is in your cck folder under:

./modules/cck/theme/content-field.tpl.php

Copy this file to your themes folder and modify it to remove the colon at line 18:

```
<div class="field-label"><?php print t($label) ?>: </div>

```

For a node template, check out the handbook on node templates, theming, etc:

http://drupal.org/node/190815#node-suggestion

There's also this module

http://drupal.org/project/no\_colons

if you want another alternative.

---
Tags: theming
---


title: Change TPL file based on taxonomy term

text:
# Question
Title: Change TPL file based on taxonomy term
I would like to change the tpl.php file used depending on the taxonomy term applied to a node.

There is a snippet on this page that explains how to do that. However, it is written for Drupal 6, and doesn't work for Drupal 7.

The snippet is as follows:

```
// Add this to your theme's template.php
// Replace "THEMENAME" with your theme's name
function THEMENAME_preprocess_node(&$vars) {
  foreach ($vars['node']->taxonomy as $term) {
    $vars['template_files'][] = 'node-term-'. $term->tid;
  }
}

```

I have tried to update it for Drupal 7 as follows:

```
function THEMENAME_preprocess_node(&$variables) {
  foreach ($variables['node']->taxonomy as $term) {
    $variables['template_files'][] = 'node-term-'. $term->tid;
  }
}

```

However, it still doesn't work. I just get the following error message:

> Notice: Undefined property: stdClass::$taxonomy in THEMENAME\_preprocess\_node() Warning: Invalid argument supplied for foreach() in THEMENAME\_preprocess\_node()

Any help would be appreciated.

# Answer
> 4 votes
You could probably handle it with the following code:

```
function mytheme_preprocess_node(&$variables) {
  if (isset($variables['node']->field_myfield[$variables['node']->language][0]['tid'])) {
    $tid = $variables['node']->field_myfield[$variables['node']->language][0]['tid'];
    $variables['theme_hook_suggestions'][] = 'node__term_'. $tid;
  }
}

```

Now if a term with the id 6 would be referenced from a node's 'field\_myfield' Drupal would look for a template named 'node--term\_6.tpl.php' and use that if available.

# Answer
> 2 votes
Here you can find everything you need to know about template suggestion in D7.

I think in your case, the template should look like `page--taxonomy--term--1.tpl.php`. No need for preprocess functions.

# Answer
> 2 votes
Try this instead:

```
function THEMENAME_preprocess_node(&$variables) {
  foreach ($variables['node']->taxonomy as $term) {
    $variables['theme_hook_suggestions'][] = 'node-term-'. $term->tid;
  }
}

```

---
Tags: 7, theming
---


title: Facebook Connect for Drupal

text:
# Question
Title: Facebook Connect for Drupal
The readme.txt of the Facebook Connect module is seriously out-dated! It really needs a review concerning the FB updates.

Now, the real problem: I have installed the module, inserted my appID and all that, but when in /admin/config/people/fbconnect I click on 'appearance' I get this fatal error:

```
Fatal error: Call to a member function getUser() on a non-object in /customers/denotenbalkers.be/denotenbalkers.be/httpd.www/sites/all/modules/fbconnect/fbconnect.module on line 421

```

When I click on 'app settings' it shows me the notice: "Ensure that you entered valid api keys." but those keys ARE valid. Maybe I'm missing something from the readme? Ex.:

**5. Enter the Connect URL on Connect settings tab (e.g. copy value from admin/settings/fbconnect field “Connect url”).** There is no such thing as a connect settings tab!

**6. Add your server to the Server Whitelist on Advanced settings tab on Facebook or disable Session Secret Whitelist Exception.** What am I supposed to add here? Because only the url doesn't work. I suppose an IP-address but I wouldn't know which one.

I've done all the rest, so I'm guessing that that's the problem.

**EDIT / SOLUTION:** The problem was that I followed the readme that was on Facebook Connect's project page. The information in there is OUT-DATED and insufficient. The readme that comes with the module itself is the one you should read!

# Answer
> 2 votes
Did you double check that you installed the Facebook PHP library correctly per the README?

```
2. Upload facebook-php-sdk library (http://github.com/facebook/php-sdk/) into the libraries folder so that it looks like 'sites/all/libraries/facebook-php-sdk/src/facebook.php'.

```

The error you are getting looks like it is coming from a library function not in memory.

You can confirm whether this is loaded or not on your admin 'status' page. You should also check the drupal logs to see if there is any more descriptive error to share.

If its in the right place but not loading, you might want to check this thread:

http://drupal.org/node/1318296

for advice on how to get it to work with the libraries API.

---
Tags: 7, social-network
---


# Question
Title: I want to use this script in Omega subteheme
I want to use this script in my Omega sub-theme. How do I do it?

# Answer
Short Answer: themename.info or `drupal_add_js()`.

Long answer: If you always want it to load just use the info file and add a \[js\] entry. Google can help you there.

Depending on when you'd like that JS to load you might want to define it only when nodes of a certain type are displayed, etc. This changes where you put `drupal_add_js()` in your template.php.

If you want it only when you display nodes then stick it in `THEMENAME_preprocess_node()` and you can use the `$vars` in there to conditionally load it on a particular node type only, etc
> 4 votes

---
Tags: javascript, theming
---


# Question
Title: In a View, does the order of pages/blocks/attachments matter? & Why isn't my block showing up?
Views 7x3x: I have two pages & a block in my view in this order:

\[Page1\] \[Page2\] \[Block1\]

Page1: path/%
Page2: path%/%
Block1: (no path)

I have the same contextual filter on all three, Page2 has a second contextual filter. My block is not appearing as expected. I have the block in the proper region without any restrictions in the block configuration.

In the contextual filter for the block, I've set it to hide the view if the value isn't present in the url. In the view preview, arguments produce results as expected. However in the live view, nothing shows up. (I'm providing the same filter arguments in the url)

When I change the contextual filter to display all results when filter value is NOT available, everything works as expected, but this isn't the behavior I want.

What else could be hiding my block/view?
Does the lack of a path for my block mean it can't see the argument?

# Answer
You likely arent providing the argument to the view in any fashion it can use it. Try not hiding the view but echoing the args to the view title or header and see what you are getting. Please consider using panels module or providing default arguments to your view instead. This works if the arguments are simple like node/user/term id.

If you post more specifics about your actual conditions i can help.
> 0 votes

---
Tags: views
---


# Question
Title: Drupal 7 - Passing Arguments from Page Manager/Panel to embedded view/reference field
Drupal 7: I try to pass an argument (eg node:title) from panels/page manager to use as filter criteria in an embedded view.In the view I want to fetch this argument as a filter criteria to a reference field.

In Panels I can define pass arguments, but how can I fetch and compare them in the view?

# Answer
> 1 votes
It sounds like you want to pass contexts from panels to a view. If that's the case, see my answer on Send a context from a panel page to a view integrated in it?

If you want to pass arguments (dynamically added by changing the URL to your panels page) to a view, then in the view panes settings, make sure to check `Send arguments`. You can then access the arguments in the view using Contextual Filters as if it were a regular views page.

# Answer
> 0 votes
Make a display in your view of type "panel pane" and place this pane into your panel instead of the block/master view you were using.

This will allow you MUCH more control over how your arguments are pulled/pushed into the view (from context/defined on pane config/fixed, etc). They will then be available directly in contextual filters as usual.

Post any issues you run into and i can help.

---
Tags: nodes, panels, views
---


# Question
Title: How to save node text and comment text to session or cookie while typing
This site does a great job saving the text input even when a question or answer hasn't been posted.

Is there a similar feature available in Drupal?

# Answer
> 1 votes
There was by crell: module Autosave. Not ported to d7 though.

Here is a quote about it (from the module's project page):

> ... automatically saves a snapshot of your content type form using AJAX. If the user's browser or machine dies while editing a node; the edits will be presented to the user the next time they return to the node. The user may toggle back and forth between the last saved version and the version with the edits that were lost and select which of these they would like to continue with.
>
> How often a form is autosaved as well as which content types to enable autosave for are admin configurable.

---
Tags: 7, nodes
---


# Question
Title: How to suppress "new" indicator for imported content?
Drupal works off a "history" table to keep track of the content you have looked at (in the last 30 days). When you import old content that users have seen already it's shown as "new" because there is no entry in the history table yet.

I could insert records into the history table for all users and all content. I remember someone posted on d.o. about a "trick" that doesn't require inserting records into history, but I can't find the reference now.

Any suggestions?

# Answer
You could suppress this in the theme layer, by doing a rewrite on the rendered output? That might be much safer than any kind of database hack.
> 1 votes

---
Tags: 7
---


# Question
Title: How to check if filefield has a value or not by Rules
I have a cck file field "pic" users can attach up to 3 images to. I would like to set a Rule with the condition depending on whether user has uploaded at least one image or not.

I set the condition `"Saved content's field 'field_pic' has value" + "negate"` But no matter the field has a value or not (a file has been attached or not) the debug says `"Condition "Updated content's field 'field_pic' has value" evaluated to FALSE."`

I also tried this code below but again always the condition is FALSE.

```
return array(
  0 => array('fid' => 0, ),
);

```

How can I set the condition to check if the cck file field has at least one file or not?

# Answer
I believe that "has value" needs to return TRUE or FALSE. You need to do the assessment yourself, because the value that it should have might not necessarily be a one or a zero (I would use this rule if I wanted to evaluate if a field has the value of 5, say: If yes, return true.)

You can either put in a value in the text input (5) which it will match for you and return true/false, or you can use PHP to evaluate it and return true or false yourself.
> 1 votes

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


title: Google Analytics stopped tracking

text:
# Question
Title: Google Analytics stopped tracking
The Google Analytics module on a brand new Drupal 7 build just stopped tracking after 7 days. When I went to investigate, I checked the settings, all appeared fine. Then I checked the source of the page, and the analytics code was nowhere to be seen.

For now I have just added in the javascript within html.tpl.php. But I am curious why it has just stopped working for no apparent reason? A bug with the module?

This site is using a custom theme. I checked the html.tpl.php and `$header` and `$page_bottom` variables were all there.

Any ideas why this may be?

# Answer
I don't see any current bugs like this in the issue queue of the module. So let's check the following:

* What's up with the theme you're using? Have you tried this with another theme?
* What performance settings do you use? (Is Javascript aggregation enabled? Do you use page caching?)
* Is the Analytics code missing from the output when you're logged in as user 1? (If it's there, what's happened with the permissions of the module?)
> 1 votes

---
Tags: 7, google-analytics
---


# Question
Title: Manage Display of Entity Reference Field: How to link to nodes instead of plain-text?
I've got two Content-Types: Releases, and Scenes.

Releases contain Scenes as Entity reference fields. I would like to link to the Scene Nodes rather than what the current options allow. At the moment my only options for Format under Manage Display are:

* Label
* Entity Id
* Rendered Entity.

These Display:

* Plain-Text Name of Entity
* Entity Id #
* Renders Scene Nodes within Release Node

How can I make Drupal render a link to the Scene Nodes that have been selected in Entity reference fields?

Or, as an alternative, is it possible to display a Teaser instead of rendering the full Scene Node within the Release Node when using "Rendered Entity"?

# Answer
> 8 votes
On the Manage Display page for your Releases content type, select "Rendered Entity" for your entity reference field. Then, to the right of the control that contains "Rendered Entity" you will see a little gear. Click on the gear, and you will get another page with a "View mode" control. The view mode has options such as "full content" and "teaser". You can select exactly which view modes appear in this list by going to the Manage Display page for your Scenes content type, and open the "Custom Display Settings" field group. If "Teaser" is not checked, then check it and click "save". After you turn on "Teaser" in this way, you will have a "teaser" button at the top-right if the Manage Display page for your Scenes. Click on this and you can control exactly what appears in a scene teaser. If you want your scene teasers to hold different fields than scenes embedded in releases, then perhaps you could use "tokens" instead of "teaser" for your entity reference view mode.

**Edit:** Sorry, I only answered the second part of your question. If you want to render just a link to your scene, then select "Label" for your entity reference field, click the gear next to the control again, and turn on the checkbox "Link label to the referenced entity".

---
Tags: entities, nodes
---


title: Module, Block or?

text:
# Question
Title: Module, Block or?
We are building a Drupal site to replace an old ASP.Net site.

This site will show a user's view of the information we have on/by/for them, their correspondence, the grades for the courses they have taken, the list of dues that they have paid, etc.

The information we want to show is all on an Oracle DB inside our firewall. We have a web service that exposes that information to us and currently use it in a ASP.Net application that we will be replacing.

We really won't be editing the content in the Admin interface at all, all the content will be generated from calls to the web service.

Would we write a module or a block or both to show this information to the user?

We're kind of new to Drupal and not really understanding the terminology.

# Answer
> 2 votes
A **module** is a "piece of functionality" which can extend Drupal's capabilities with a lot of different things - like a *plugin/extension* in another system. It might or might not add functionality which is visible on the frontend - there are pure API modules for example.

**Blocks** are pieces of specialized displays - like *widgets*. Many times what you can see in the sidebar of a page is nothing else but blocks. For example setting up a category list or a tagcloud in a blog could be (and perhaps should be) done via blocks.

Modules and blocks are related in some way: a module can provide different blocks to use, for example the core comments module provides the *"Recent comments"* block.

If you would like to understand the complete terminology, check out Pro Drupal 7 Development \- it's a great start for developing for Drupal.

# Answer
> 1 votes
Drupal has an API called 'entities.' Entities define the relationship between Drupal content and a database and its storage. The major content types in Drupal 7 are implemented with the Entity API; node, user, taxonomy... All are entities. You can also implement your own entity types.

So, for instance, an external database could be defined in the site's `settings.php` file, named something like 'our\_oracle\_database.' Then you could define an entity by implementing `hook_entity_info()` in a module. This entity would show the table schema to Drupal, and Drupal would then be able to use that table as content. You'd then define a controller class for your entity, which would use your database for CRUD functions.

It's completely non-trivial, and not a thing to shoot off in one single answer on Drupal Answers.

---
Tags: 7, hooks, blocks
---


# Question
Title: How to display $variables in drupal 6 preprocess function?
I'm having difficulty trying to figure out what variables are within the scope of my `hook_preprocess` function. I even tried to `print_r($variables['fields'])`, but I keep getting this long recursive mess. Is there a much easier way in drupal 6 to see what values I can use?

# Answer
> 3 votes
Install the Devel module.

Once installed use the function `dpm()` like this: `dpm($variables);`

This will give you a nice print out of your variables.

---
Tags: hooks
---


# Question
Title: How to create a custom resource with Services-3.x
Drupal 7.9

I have installed Services 3.x module and can successfully access nodes etc using the rest server e.g. http://api.domain.com/api/rest/node/6.xml. I now wish to create a custom resource and am having difficulty understanding how to do that correctly. I have followed the much-quoted tutorials on this which all seem to be based on the same example: http://drupal.org/node/783460 and am struggling to understand hook\_services\_resources. For example:

```
   'note' => array(
     'retrieve' => array(
       'help' => 'Retrieves a note',
       'file' => array('file' => 'inc', 'module' => 'noteresource'),
       'callback' => '_noteresource_retrieve',
       'access callback' => '_noteresource_access',
       'access arguments' => array('view'),
       'access arguments append' => TRUE,
       'args' => array(
         array(
           'name' => 'id',
           'type' => 'int',
           'description' => 'The id of the note to get',
           'source' => array('path' => '0'),
           'optional' => FALSE,
         ),
       ),
     ),

```

Where are the available values for these arrays? For example what are the valid options for source in the args array? I've seen the following: array('path' =\> '0'), 'data', array('param' =\> 'page'), 'param'. Where can I find a reference for how this needs to be defined?

To give a bit more information about what I want to achieve, we have a custom form that accepts a series of parameters and returns a set of html-formatted data. The form calls this function: return account\_manager\_search\_accounts($billing\_party, $other\_party, $date\_from, $date\_to, $billing\_id); }

My idea is to allow users to retrieve the appropriately formatted data (e.g. json, xml) RESTfully and it seemed Services was the right way to do that.

Something like:

```
function account_manager_services_resources() {
  return array(
   'records' => array(
     'retrieve' => array(
       'help' => 'Retrieves records',
       'file' => array('file' => 'inc', 'module' => 'account_manager'),
       'callback' => '_account_manager_records_retrieve',
       'access callback' => 'user_access',
       'access arguments' => array('view records'),
       'access arguments append' => TRUE,
       'args' => array(
         array(
           'name' => 'billing_party',
           'type' => 'varchar',
           'description' => 'The billing party',
           'source' => what should go here,
           'optional' => FALSE,
         ),
         array(
           'name' => 'other_party',
           'type' => 'int',
           'description' => 'The other party',
           'source' => what should go here,
           'optional' => FALSE,
         ),
       ),
     ),
   ),
  );
}

```

Then I'm not even sure what the URL would be for this. Would it be something like: ./api/rest/account\_manager/records

Any suggestions or advice appreciated.

# Answer
All the documentation for the hook is in the services.services.api.php file included with the module. The args array is:

> an array describing the arguments which should be passed to this resource when it is called. Each element in the array is an associative array containing the following keys:
>
> * name: The name of this argument.
> * type: The data type of this argument (int, string, array)
> * description: Text describing this argument's usage.
> * optional: A boolean indicating whether or not this argument is optional.
> * source: Where this argument should be retrieved from. This can be 'data' (indicating the POST data), 'param' (indicating the query string) or 'path' (indicating the url path). In the case of path, an additional parameter must be passed indicating the index to be used.
> * default value: this is a value that will be passed to the method for this particular argument if no argument value is passed

There are a fair few examples in that file it might be worth giving them a read through, although the API documentation does actually specifically refer to the link you posted above as a *detailed example of creating a new resource*.
> 9 votes

# Answer
If you look at services.services.api.php It looks like this.

https://gist.github.com/1b4a1bdef433cad8b142
> 2 votes

---
Tags: services
---


# Question
Title: How to make a CCK field appear as single-value on one Node Type, and multi-value on another Node Type?
I have a CCK field (text, options widget, predefined value list) I'm using on two Node Types. On one Node Type, I'd like to allow an unlimited number of selections. On the other Node Type, I'd like to restrict the user to a single selection.

Currently, I've configured the CCK field to allow unlimited values, and am using this `hook_form_alter()` code:

```
/*
 * Implementation of hook_form_FORM_ID_alter().
 */
function custom_form_custom_node_form_alter(&$form, &$form_state) {
  // http://drupal.org/node/726282
  $form['#after_build'][] = 'custom_after_build';
}
function custom_after_build($form, &$form_state) {
  $form['field_custom' ]['value']['#multiple'] = false;
  return $form;
}

```

So far, so good: the field shows up as single-value on one Node Type, and multi-value on the other.

But when I click Save, the data doesn't end up in the node — I presume this is because the single-value and multi-value fields store data differently, and CCK's submit handler is expecting the data in a different format.

What do I need to do to get the single-value field data into a format CCK will understand for a multi-value field?

So far I've tried:

* implementing a `#validate` handler to alter the `$form_state` array to match the `$form_state` array produced by submitting a multi-value field — no effect
* implementing `hook_nodeapi()` `$op==='validate'` to alter the field values in the `$node` object — no effect

# Answer
You need to implement the hook\_nodeapi and use the operation "**presave**"

Presave will have all the data submitted from the form and you can then alter it here just before it goes into the database.

If you have the devel module do a dpm($node); to see what data you are getting.

the important thing is that the field for multi values will be expecting an array so it may be as simple as grabbing the data from the form and adjusting it to pass it as an array.

**EDIT**

Aah ok validation....

I would probably turn off validation for that item by using the: `'#element_validate'` property, this way you can target validation for that specific element see the fapi docs on drupal. http://api.drupal.org/api/drupal/developer!topics!forms\_api\_reference.html/6#element\_validate
> 1 votes

# Answer
A working, but ugly, solution — manually remove the form validation errors:

```
/*
 * Implementation of hook_form_FORM_ID_alter().
 */
function custom_form_custom_node_form_alter(&$form, &$form_state) {
  // http://drupal.org/node/726282
  $form['#after_build'][] = 'custom_after_build';
  $form['#validate'][] = 'custom_validate';
}
function custom_after_build($form, &$form_state) {
  $form['field_custom' ]['value']['#multiple'] = false;
  return $form;
}
function custom_validate($form, &$form_state) {
  // since we're now rendering a single-value-field, we need to move the data back into the multivalue-field format CCK expects
  $selectedValue = $form['field_custom']['#value']['value'];
  $form_state['values']['field_custom'][0]['value'] = $selectedValue;

  // clear related form errors set by other validation handlers
  $errors = form_get_errors();
  form_set_error(NULL, '', TRUE);
  foreach ($errors as $k => $v) {
    if ($k !== 'field_custom][value') {
      form_set_error($k, $v);
    }
  }

  // clear related messages set by other validation handlers
  $errors = drupal_get_messages('error');
  foreach($errors['error'] as $error) {
    if ($error !== 'Custom field is required.') {
      drupal_set_message($error, 'error');
    }
  }
}

```
> 0 votes

---
Tags: 6, entities
---


# Question
Title: Taxonomy page by views with two arguments?
I'm not sure if I have understood correctly how views override taxonomy page. What I would like to do is to let taxonomy page have two arguments and each of them are taxonomy terms from different vocabularies. For example, I have two vocabularies and like below. Node can be tagged with multiple terms from but just with one term from

```
<Color>
 Blue
 Red
 Grey

<Car>
 GM
 BMW
 Toyota

```

I would like to make URLs like this.

```
/Blue/GM
/Blue/BMW
/Blue/Toyota
/Red /GM
/Red /BMW
/Red /Toyota
/Grey/GM
/Grey/BMW
/Grey/Toyota

```

And when user taxonomy link on node page view for example, If the node is tagged with "Blue" "Red" "GM"

```
Click "Blue" takes to /Blue/GM
Click "Red" takes to /Red/GM
Click "GM"  takes to all the node list of "GM" maybe URL /GM

```

I've been playing with taxonomy views but still can't figure out hot to achieve this.

# Answer
> 0 votes
Based upon my read of your question there may be several things to address here.

1. View is not overriding your URL. The address you have in the URL should be unique and intended to call the view just as if it is any other piece of content. Do not have more than one piece of content with the same address, can only confuse things. Ignoring aliases for a moment, that means you cannot create a view with the path of `taxonomy/term/tid`, but you can create one called `taxonomy/term/tid/facts`. adding the fourth level of the URL makes it a unique address.
2. You are not defining a taxonomy page with terms from two vocabularies. To provide the content you desire you should create a view with the desired URL name.
3. A taxonomy page has a URL of `taxonomy/term/tid`. You can provide it with an alias, but that can confuse your thinking. The first thing Drupal always does with an alias is convert it back to the original path. So anything that uses the URL, such as Views will not see the alias, it only sees the original path. That means that that if the paths you desire, such as red/gm are aliases, they will not be seen by the view.
4. A view can have multiple paths using the % wildcard. If you created a view with a path of `/cars/%/brand` Then your view will be called by Drupal for any value placed in the % location of the path.
5. A view path should always have a static name for the first and last positions of the path. In your examples above for `red/GM` you basically have an URL of `%/%`which would be assigned to just about everything.

To create your desired View content you may want to try the following:

* Define two vocabularies for brand and color, and/or anything else you want in the categorization.
* Create a content type that includes fields for these two vocabularies and give the content URLS following the formula similar to \`cars/%(color)/%(brand)/
* Create a view with a path something like `cars/%/%/view` The word 'view, in the path can be anything you desire.
* Define the view to display whatever content you want.
* Create two contextual filters, the first defined to read a term from the color taxonomy and the second to read the brand. Views will use the value of the first % for the first contextual filter and the second % for the second filter.

That should get you started, although I suspect you will have at least one more round of questions before it works for you (It always does.) There are a lot of previous questions on this site whose answers will help solve the details for you. There is also an excellent video series 'Taming the Beast' that can show you everything you need to know about views.

---
Tags: 6, taxonomy-terms, path-aliases, views
---


# Question
Title: Best way to register a new Drupal user via a 3rd party application
We have a Java application on our server, when users provide their email and username to it I want it to send the username and email to our Drupal site to register them for an account. And I'd like them to still receive Drupal's welcome email containing their password.

What's the best way to achieve this, I was thinking possibly the services module? But wasn't sure if there'd be a better solution because the Java code and Drupal site are on the same server and therefore we could have some pretty direct integration.

# Answer
> 1 votes
I may be biased b/c I am the Services module maintainer, but, You don't want to be directly inserting things into the database.

You could REALLY break Drupal by doing this.

If you didn't want to use services module(which why wouldn't you?) you should really use Drupal's apis to put things in the database, like, node\_save, or drupal\_form\_submit(which is what services does).

This ensures that Drupal actually enters the data and will lead to a cleaner overall integration with less problems.

In Drupal 6.x this json actually creates a user when POSTed to SERVER/ENDPOINT/user.

```
{"uid":"1","name":"admin","pass":"1a1dc91c907325c69271ddf0c944bc72","mail":"kyle@workhabit.com","mode":"0","sort":"0","threshold":"0","theme":"","signature":"","signature_format":"0","created":"1286571725","access":"1294792121","login":"1293782855","status":"1","timezone":null,"language":"","picture":"","init":"kyle@workhabit.com","data":"a:0:{}","roles":{"2":"authenticated user"}}

```

---
Tags: users, services
---


# Question
Title: What do you set in the "column" field for adding a minimum words validation via the Field Validation module?
I'm creating a validation rule on a text field via the Field Validation module. On the create screen it asks for "Column" and includes this description:

> A column defined in the hook\_field\_schema() of this field.

I do not understand what I need to enter here. Can anyone explain?

# Answer
> 3 votes
This may help you out....

**Field \> Appropriate column value**

* Normal field \> "value"
* Taxonomy field \> "tid"
* Date field \> "value" and "value2"
* Node reference field \> "nid"
* User reference field \> "uid"
* Link field \> "url","title","attributes"

---
Tags: 7, entities
---


title: theming a CCK input form

text:
# Question
Title: theming a CCK input form
How do I theme a CCK input form? I tried the approach given in this page, but it is not working even after I clear the cache. Here are the steps.

Suppose your content-type is: "account\_registration" and you theme is "bluemarine".

I edited template.php and added this code:

```
function bluemarine_theme($existing, $type, $theme, $path) {
  return array(
    'account_registration_node_form' => array(
      'arguments' => array('form' => NULL),
      'template' => 'node-account_registration-edit'
    )
  );
}

```

I created node-account\_registration-edit.tpl.php:

```
<?php
  $form['buttons']['submit']['#value'] = 'Done';
  $form['buttons']['preview']['#access']= FALSE;
?>

```

I cleared cache and edited a node, but the above changes are not showing up.

# Answer
Your steps are right. I tested it on my local environment, and it works.

For example, for the content type "companynews", add the function to the template.php:

```
function garland_theme($existing, $type, $theme, $path) {
  return array(
    'companynews_node_form' => array(
      'arguments' => array('form' => NULL),
      'template' => 'node-companynews-edit'
    )
  );
}

```

Create the node-companynews-edit.tpl.php file and put the test code.

```
<?php
  echo 'it works!";
?>

```

Clear the cache, and access http://example.com/node/add/companynews: it shows "it works."

**PS:** You can also use hook\_form\_alter() to alter the form, and then use CSS to style it.
> 2 votes

# Answer
The reason the code is not working is that a template file is supposed to render the form fields, not to alter the `$form` array.
I would not suggest to use a template file for a form, and I would instead use a theme function.

As example of theme function used to render a form, look at the code of theme\_node\_filter\_form(), which renders the node filter fields that appear in http://example.com/admin/content/node/overview.

```
function theme_node_filter_form($form) {
  $output = '';
  $output .= '<div id="node-admin-filter">';
  $output .= drupal_render($form['filters']);
  $output .= '</div>';
  $output .= drupal_render($form);
  return $output;
}

```

Drupal core modules don't use a template file for rendering a form, and you would not find examples of template files used in such way looking on api.drupal.org.
> 1 votes

# Answer
To find the appropriate theme or template name to overrride formatting the theme developer moduld is very handy. You can just point and click on whatever you like to change and it tells you what part of drupal is doing the rendering and all the possibilties to override and adjust it to your needs.
> 0 votes

---
Tags: theming, forms, 6
---


# Question
Title: How to show drupal error messages in batch scripts?
I'm using a few scripts for one-time data checking and scrubbing. They load the Drupal bootstrap but not the UI:

```
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

```

How can I display any error messages that they generate?

# Answer
You should really be using Drush. It handles bootstrapping and reporting error messages, etc. In particular, the command `drush php-script` will be useful to you.

```
$ cd /path/to/drupal/sites/mysite
$ drush php-script /path/myscript.php

```

Write your script as usual. Drush will bootstrap for you, so you may simply start calling Drupal APIs. Any error messages generated will be printed to stderr. See the readme file, http://drush.org, and `drush topic` for all sorts of advice on getting started.
> 3 votes

# Answer
It's actually eays to write you're own drush commands. Have a look at the sandwich example code in the drush source code.
> 1 votes

---
Tags: 7
---