# Question
Title: How does Feeds decide if it is going to create a new (or update an existing) entity?
I am using Feeds to map a CSV file to user entities and have the "Update existing users" setting in place. Everything is going great, except for the Telephone field... as it currently stands, the Telephone module doesn't have support for Feeds.

There is a patch that works for saving a telephone number when creating a new user, but not when updating an existing user.

Here's a CSV example (excluding headers for simplicity) for a new user:

```
demo,demo@demo.com,1234567890

```

Here's a CSV example for updating that same user:

```
demo,demo@demo.com,4567890123

```

When changing the value of the telephone number in the CSV file, and running it through the importer again, Feeds (or someone else?) doesn't see any incoming changes to be applied, so it skips the import entirely saying:

```
"There are no new users."

```

I've been looking at the Feeds API to see what hooks are available, and thought `hook_feeds_presave()` would be a nice one, since it talks about "skipping" an entity, but this hook only gets fired when creating a new user.

The hook\_feeds\_before\_update() function gets called each time, but I'm not seeing a way to indicate to Feeds whether or not a value has changed, and to proceed or skip.

I'm guessing I need to expand upon the patch with hook(s)/other to make a simple decision for Feeds, *pseudo code* e.g.

```
...
// If telephone number has changed, tell feeds its OK to update.
if ($feed_item_value != $entity->{$field_name}['und'][o]['value']) {
  $feeds->update = TRUE;
}
else {
  $feeds->update = FALSE;
}
...

```

How does a module, that provides a field, tell Feeds that it detects a change with the field's value and to update an entity? Or does feeds and the internal entity system automatically do this?

# Answer
The Feeds module uses the FeedsProcessor object to define what it calls mapping targets for an entity to determine what fields are unique and what can be optionally be set unique in the feeds importer mapping settings UI. It then uses the method existingEntityId to determine if the mapping targets are unique.

In the case of users, the hook\_feeds\_plugins method for the feeds module tells feeds to use the class FeedsUserProcessor. This class has a method named getMappingTargets to say that the optional unique fields can be name and mail. In the mapping ui for the user feeds importer (admin/structure/feeds/user/mapping), you can set name and/or mail to be unique. The existingEntityId method in FeedsUserProcessor.inc determines if it has found a unique value. If so, and the importer is set to replace or update existing users, then the feeds record will be updated.

If you really wanted to work with telephone number as a unique field attached to a user, then you use implement hook\_feeds\_plugins, define your own FeedsProcessor and extend FeedsUserProcessor, and overwrite the getMappingTargets to add the field as an optional\_unique entry, and overwrite existingEntityId to find other users with a matching telephone number.

However, it sounds like you don't need to do that. Make sure your user feeds import is set to update existing users, and that it is reading the csv file properly.

I went ahead and enabled telephone, installed the patch you mentioned, and was able to see a user be created, and then be updated with a different telephone number. My import file looked like this:

```
name,mail,telephone
demo,demo@demo.com,1234567890

```

and then this:

```
name,mail,telephone
demo,demo@demo.com,4567890123

```

And here is an export of the feed import:

```
$feeds_importer = new stdClass();
$feeds_importer->disabled = FALSE; /* Edit this to true to make a default feeds_importer disabled initially */
$feeds_importer->api_version = 1;
$feeds_importer->id = 'user';
$feeds_importer->config = array(
  'name' => 'User import',
  'description' => 'Import users from CSV file.',
  'fetcher' => array(
    'plugin_key' => 'FeedsFileFetcher',
    'config' => array(
      'direct' => FALSE,
      'allowed_extensions' => 'txt csv tsv xml opml',
      'directory' => 'public://feeds',
      'allowed_schemes' => array(
        0 => 'public',
      ),
    ),
  ),
  'parser' => array(
    'plugin_key' => 'FeedsCSVParser',
    'config' => array(
      'delimiter' => ',',
      'no_headers' => 0,
    ),
  ),
  'processor' => array(
    'plugin_key' => 'FeedsUserProcessor',
    'config' => array(
      'bundle' => 'user',
      'roles' => array(
        3 => 0,
      ),
      'update_existing' => '1',
      'status' => '1',
      'mappings' => array(
        0 => array(
          'source' => 'name',
          'target' => 'name',
          'unique' => 0,
        ),
        1 => array(
          'source' => 'mail',
          'target' => 'mail',
          'unique' => 1,
        ),
        2 => array(
          'source' => 'telephone',
          'target' => 'field_telephone:url',
          'unique' => FALSE,
        ),
      ),
      'defuse_mail' => 0,
      'update_non_existent' => 'skip',
      'input_format' => 'plain_text',
      'skip_hash_check' => 0,
    ),
  ),
  'content_type' => '',
  'update' => 0,
  'import_period' => '-1',
  'expire_period' => 3600,
  'import_on_create' => 1,
  'process_in_background' => 0,
);

```
> 3 votes

---
Tags: 7, feeds
---


title: Commerce Import From Ubercart Sales Tax

text:
# Question
Title: Commerce Import From Ubercart Sales Tax
Does anyone have any examples of importing Sales Tax data from Ubercart 2 into Drupal Commerce?

The two systems seem to use -very- different schemas (Ubercart uses separate line items and Commerce attaches tax to the product/line item. I looked at the commerce\_migrate\_ubercart module and it doesn't even try to handle this.

The problem is that we have historical data where rates have changed over time so it's not accurate to simply recalculate based on current rates.

We could live with simply being able to override the tax on the entire order, but I can't find a hook to override that in the commerce\_orders table.

Edit: I could use commerce\_tax\_rate\_apply('state\_sales\_tax', $line\_item);

```
     $tax_price = commerce_tax_rate_apply('state_sales_tax',  $line_item);
    // <--- Now what? I don't understand how to apply $tax_price back to the original line item before saving.

     // Save the line item to get its ID.
     commerce_line_item_save($line_item);

```

Or: After saving the line item, how do I hook into the standard Rules for tax calculation? (Which work fine for new orders.)

# Answer
> 0 votes
The best solution here is a "dumb" migration, one that simply retains the data model of the prior system without trying to shoe horn it into the data model of the new. The reason I changed the tax data model from Ubercart to Commerce is because taxes are actually necessarily tied to the products and services that are being taxes. When we had all taxes added up and stored in a single line item, it's then impossible to do things like refund the taxes collected for one particular product on an order if it's returned. You also cannot generate a very meaningful tax report, though nowadays I'd look to third party systems to do that anyways.

You're going to need to define your own line item type via hook\_commerce\_line\_item\_type\_info() and then setup your migration to create the line item on migration. I'd call it "Ubercart tax record" or something similar. New taxes going forward should actually become part of the relevant line items when they're calculated.

When you create these tax line items, make sure that you both set the unit price amount / currency code values and update the unit price's components array to match. Look to commerce\_product\_line\_item\_populate() around line 1376 where you see the comment about adding the base price to the components array. In your case, you wouldn't use the 'base\_price' price component for taxes - you'd either want to define a generic price component type via hook\_commerce\_price\_component\_type\_info() or if you know the types of the taxes map to price components for tax rates you've defined on the new site, you can use those.

---
Tags: commerce, ubercart, importing-exporting, migrations
---


title: CKeditor via CDN optional plugins

text:
# Question
Title: CKeditor via CDN optional plugins
The latest Drupal Ckeditor Module 1.14 loads the Ckeditor library via CDN. The table on http://ckeditor.com/presets-all shows the 5 possible packages to be used via CDN. I am using the Full-all package. This package has a lot of optional plugins.

How can I activate these optional Ckeditor plugins in Drupal ????

# Answer
In the CKEditor profile area if I am hearing you correctly:

> admin/config/content/ckeditor
> 0 votes

---
Tags: wysiwyg, cdn
---


title: Search by product with punctuation

text:
# Question
Title: Search by product with punctuation
I'm starting to configure frontend search for user search, and I can't find a product if it has a puctuation sign. For example, a product called

The world today: a new adventure

In search box, if I enter *world today:*, the search doesn't find the product.

Anybody could help me with that?

# Answer
Drupal Core Search is designed to deal with many punctuations, but not all. Take a look at either of these modules:

Punctuation Preprocessor:

> This module implements a punctuation pre-processor that provides special handling for punctuation characters when they are encountered within word strings during searching and indexing.

Fuzzy Search:

> This module provides drupal sites with a fuzzy search engine to allow for broader keyword matches including partial or misspelled keywords.

or any of the other core search alternatives - they may pick up the punctuation better.
> 0 votes

---
Tags: search, commerce
---


# Question
Title: Drush remote with switching shell users (sudo)
Problem: I have a remote server with SSH access where the Drupal site can only be accessed as another user (www-data). My own shell user is not able to use drush directly for security reasons.

So how can I run all drush remote commands as www-data? I have sudo priviledged to execute commands as root.

My aliases.drushrc.php:

```
<?php

$aliases['accounting-phd'] = array(
  'root' => '/var/www/example/docroot',
  'uri' => 'example.com',
  'remote-host' => 'server.example.com',
  'ssh-options' => '-t',
  'path-aliases' => array(
    '%drush-script' => '/home/klausi/drush-remote.sh',
  ),
);

```

And in drush-remote.sh on the server:

```
#!/bin/bash
sudo su www-data -c "drush $@"

```

This prompts me for my password successfully, but then fails with

```
su: unrecognized option '--root=/var/www/example/docroot'
Usage: su [options] [LOGIN]

```

How can I separate the options from the su command?

# Answer
> 4 votes
Set 'remote-user' =\> 'www-data' in your site alias, and Drush will exec the remote Drush as the www-data user. `ssh-copy-id www-data@server.example.com`, and you'll be all ready to go.

# Answer
> 0 votes
I'm having a similar issue I'm working with, and got a basic shell wrapper working with this code:

```
#!/bin/bash
sudo -u www-data -c 'drush6 $@'

```

I think the double quotes may have been your issue.

---
Tags: drush
---


# Question
Title: How to set rel="alternate" hreflang="x"?
I am trying to set my hreflang links with this code:

```
$langcode= $GLOBALS['language']-> language;
//Get enabled languages
$langcode= array_pop(language_list('enabled'));
unset ($languages[$langcode->language]);

// Get path
$path1 = drupal_is_front_page() ? '<front>' : $_GET['q'];
//Get Urls
$links = array();
foreach ($languages as $lang) {
  $links[$lang->language] = array(
    'href'=> $path1,
    'language'=>lang,
    'absolute'=> TRUE,
  );
}
drupal_alter('translation_link', $links, $path1);

//Set head tags
foreach($links as $link) {
  drupal_set_html_head('<link rel="alternate" hreflang="'.   $link['language']->language .'" href="'. url($link['href'], $link) .'" />');
}
//Update head
$vars['head'] = drupal_get_html_head();

```

with no luck.

While researching I have found this module Internationalization contributions but it doesn't do anything. Or I don't know how to use it.

# Answer
You tagged your question as Drupal 7 so I'm guessing the only problem is that you're using `drupal_set_html_head()` which doesn't exist in Drupal 7.

It's been replaced with `drupal_add_html_head()`, which you can use like so:

```
$element = array(
  '#tag' => 'link',
  '#attributes' => array(
    'hreflang' => 'some_language',
    'rel' => 'alternate',
  ),
);
drupal_add_html_head($element, 'mymodule');

```
> 2 votes

# Answer
Just use the mentioned module http://drupal.org/project/i18n\_contrib and enable the sub-module **i18n\_hreflang**, this will provide the hreflang in the head section of your website automatically across your translated pages. **(clear cache!)** Use the latest state (dev-release) to have some improvements already in. Sure I will create soon an new stable release too.
> 2 votes

# Answer
Another option for adding the hreflang tag is this module: Alternate hreflang

> Alternate hreflang is a simple module that automatically adds these tags to your pages. It has no dependencies, but works well with Entity Translation.
> 2 votes

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


# Question
Title: Add a remove button to a custom unlimited value field?
I'm working on a custom compound field that includes a text value and an entity reference id. The field will contain multiple values, so the widget needs to provide "add new value" functionality, and a way to remove values already added (i.e. a "remove" button).

Following the (older) thread here: https://drupal.org/node/1143880, it seems that "add new value" is provided automatically, but not "remove" existing values? Is that still the case?

The thread above also links to a sandbox project here: https://drupal.org/sandbox/daggerhart/1363702. I tried this code, and it does seem to work, although the formatting is a little different.

What's the current best practice for adding a "remove" button to an unlimited value field widget?

Edit: here is a link to a feature request for this functionality in D8: https://drupal.org/node/1038316

# Answer
> 3 votes
there are two modules already

1. Multiple Fields Remove Button
2. Field Remove Item

# Answer
> 0 votes
For now, I'm using a sandbox project called "unlimitedfield\_remove", available here: https://drupal.org/sandbox/daggerhart/1363702. The code is working fine, but the formatting of the remove button is a little different than the standard (I haven't looked into why that is).

After you install the unlimitedfield\_remove module, you need to select which unlimited value fields should get a remove row button.

I'd still like to confirm a current best practice, so I'd be interested in other approaches.

---
Tags: 7, entities
---


title: Boost not refreshing views page

text:
# Question
Title: Boost not refreshing views page
I am using Drupal 7.32 and the latest Boost, Boost Crawler and Cache Expiration modules. My 'normal pages' refresh fine with boost when i amend them ie. articles, Basic Page, Content Type node, but if I change a node which belongs to a Views page (e.g. a News item on a News Blog page contructed with a View), then it does not pull in the latest news item i have just created i.e. does not expire the News Blog page. Within the documentation at https://www.drupal.org/node/545908 it shows the option

```
[x] Clear all cached views pages associated with a node on update/delete

```

But I cant see where to set this in the Boost module settings. I think that would fix my problem. Maybe that is referring to old documentation, perhaps the new module does it in a different way.

Can anyone help?

# Answer
> 1 votes
After a bit of digging around I found that this is resolved by adding the URL to the Cache Expiration setting as follows. Go to » Administration » Configuration » System \>\> Cache Expiration, the under Node Expiration tab, then in the section 'What URLs should be expired when node action is triggered?', tick Custom Pages, then add the URL of your pages that are created with Views, in my case its just the word News. There may be a way to add conditioning on this so it only expires the News page when nodes relating to it are amended. If anyone finds that out, can they let me know. You can also tick under Module Status in the Debug section at the bottom 'Watchdog + site message ', it will display a message show which urls have been expired (cleared).

---
Tags: caching
---


# Question
Title: Which hook to use in a custom module for tracking access to one particular page?
I'm probably not fully awake this morning because it seems so trivial but I cannot figure it out.

I need a hook to track when user access a certain page (path = '`export-csv`'). This page is not a node neither a View and neither a form... It is just a "path". And I need a hook that I could use in my custom module's file, not in templates.

I thought of something like `hook_preprocess_page` or but it doesn't seem to work.

I need a hook called before the page is fully loaded because the page is never truly displayed (it is a page for downloading a file and it just shows the download popup).

If you need precisions about my code or something, just ask. But I don't think that it is necessary.

Thanks in advance of course.

**edit**: I found a part of solution here but I still have trouble because of the nature of the page. I never truly land on the page and I think the hook is not called before the popup happens.

The callback function of this page looks like this:

```
function grap_contact_export_csv_page() {
  header("Cache-Control: public");
  header("Content-Type: application/octet-stream");
  header("Cache-Control: no-store, no-cache, must-revalidate");
  header("Cache-Control: post-check=0, pre-check=0");
  header("Content-Disposition: attachment; filename=\"grape-export.csv\";" );
  header("Content-Transfer-Encoding: binary");
  $fp = fopen('export.csv', 'r') or die('Impossible d\'accéder au fichier');
  echo fread($fp, filesize('export.csv'));
  fclose($fp);
  drupal_exit();
}

```

# Answer
That's how I achieved that:

```
function grap_contact_export_csv_page() {
  grap_log_export(); // Calling another function to record tracking in DB
  header("Cache-Control: public");
  header("Content-Type: application/octet-stream");
  header("Cache-Control: no-store, no-cache, must-revalidate");
  header("Cache-Control: post-check=0, pre-check=0");
  header("Content-Disposition: attachment; filename=\"grape-export.csv\";" );
  header("Content-Transfer-Encoding: binary");
  $fp = fopen('export.csv', 'r') or die('Impossible d\'accéder au fichier');
  echo fread($fp, filesize('export.csv'));
  fclose($fp);
  drupal_exit();
}

```
> 0 votes

---
Tags: hooks, theming, 7
---


# Question
Title: Change taxonomy term field into text field in content-type
Is there a way to transform a taxonomy term field into a simple text field? I need to keep all the terms present in the taxonomy field and have them separated by a comma.

# Answer
Eventually, I simply used a PHP script I execute in `mysite/devel/php` to copy my taxonomy term field value to my new text field:

```
$nodes = node_load_multiple(array(), array('type' => 'contact'));
foreach($nodes as $node) {
  if ($node != NULL) {
    $tid = $node->field_title['und'][0]['tid'];
    $term = taxonomy_term_load($tid);
    $name = $term->name;
    $node->field_function_title['und'][0]['value'] = $name;
    $node = node_submit($node);
    node_save($node);
  }
}

```
> 0 votes

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


title: Store Drupal 7 webforms in code

text:
# Question
Title: Store Drupal 7 webforms in code
I am wondering if there is any solution to store webforms in code. So that you can easily duplicate them on other sites and bundle them with your own modules. I am looking into something similair as the views API.

If it is not available how many people are interested in such functionality? I might develop a module which could handle storing of webforms in Code. And do you have any concerns in creating such a module?

Thanks, Jaap

# Answer
> 1 votes
# Not really, and there is no need for it

1. If you need form available from code, Form API forms are not that hard to write from scratch. Contrary to Views, you can only theme Webforms bu their node ID, and that would change from site to site, so Webform forms bundled with module will not be convenient.
2. If you want to bundle forms with your modules, and for any reason you can't use Form API, UUID Features Integration and Webform share provide ways to do it. It will not be a *code* in pure sense, but it should work.
3. It's relatively easy to use `hook_form_alter` to obtain Form API representation of particular webform. Of course, you won't be able to change it easily in future, but again, contrary to views, it is good. Module is not hurt if some data is not displayed. Data not provided, or provided in a way module does not expect, may break things. So **if module needs a form, it should not be easy to edit**. Edits to form would require edits to module's code anyway, so Form API code makes things easier, not harder in the long run, in such situations.

---
Tags: webforms
---


title: Where is my AJAX call going?

text:
# Question
Title: Where is my AJAX call going?
I'm very new to Drupal so I hope you'll forgive the silly question: where is the server-side code for my AJAX call?

I've read the documentation on the Ajax Framework, but I can't find any instances of `#ajax` or `callback` in my code.

Capturing the `/system/ajax` request yields some interesting form variables:

* **form\_build\_id:** `form-cBW24WCJRFxgW5TMHSa-9hQ_tVenToYkx2ObzTgnQKM`
* **form\_id:** `commerce_checkout_form_ip_info`
* **\_triggering\_element\_name:** `ief-36484c27df589bd88b009b3e91d079f24f9559cc-add`
* **\_triggering\_element\_value:** `%2B+ADD+MEMBER`

(There are lots of others, but those seem like the relevant ones.) I gather that this is a form using the Commerce module, but that doesn't help me much.

Finally, here's the line of code setting up the value of the button that triggers the AJAX call:

```
$form['customer_profile_ip_info']['field_company_ip_customer_info']['und']['actions']['ief_add']['#value'] = "+ ADD MEMBER";

```

Hopefully this is enough information to determine what's happening here.

# Answer
> 1 votes
IEF = Inline Entity Form; you should find what you're looking for in that module. If you're new to Drupal the layers of abstraction might make it difficult to understand what's going on though. If there's something in particular you're looking to find out how to alter or understand just update the question.

If you install the Devel module and add

```
dpm($form['customer_profile_ip_info']['field_company_ip_customer_info']['und']['actions']['ief_add']);

```

to your alter hook you should find the #ajax property.

---
Tags: 7, ajax
---


# Question
Title: D7 - Syntax of js custom file added directly to theme
Alright, so I've read the documentation of JS framework in Drupal and there is a simple example how the syntax of JS file should look:

```
Drupal.behaviors.myModuleBehavior = {
  attach: function (context, settings) {
    $('input.myCustomBehavior', context).once('myCustomBehavior', function () {

    });
  }
};

```

I can't figure out what should I put instead of "myModuleBehavior" when js file is added directly to theme, not by custom module. Any help?

# Answer
> 1 votes
It just needs to be unique (otherwise you'll overwrite something existing, this is JS after all). So it would make sense to go with

```
Drupal.behaviors.myThemeBehavior = {

```

But it doesn't really matter as long you're not elbowing an existing behaviour out of the way.

---
Tags: theming, javascript
---


# Question
Title: How to give a user the rights to "clear cache"
I need to give a user the ability to "clear cache" since he sometimes does some changes to the menus, etc... How can I give him a right to do that, or can I just send him a URL or post something on his admin toolbar? With the roles and rights I've given him so far he can only go to one thing on the Configuration page and that's "URL aliases." I recall that I used to have a way to accomplish this for the authenticated users with a little block at the bottom of the footer, but I can't find it or remember how I did it..

Help please, and thanks in advance.

Dave N

# Answer
> 1 votes
You may try UI Cache Clear.

Project page says:

> * Clears specific cache bin without flushing the whole site cache.
> * Allows to clear cache without full administrator permissions.
> * Provides setting to clear current page cache automatically when clearing Block, Views or Panels cache.
> * Admin menu and Shortcut integration

# Answer
> 0 votes
I have good experiences with CacheFlush. I especially liked the option that I can define permissions on the cache preset level for a specific role. It integrates in the admin toolbar, so if your user has access to that, it is a simple click on the preset to flush the caches you specified.

Description from project page:

> It ships with a predefined set of actions, but it's biggest strength lays in it's configuration, where one can build any number of custom presets to fit almost any need on both development and production environments.

---
Tags: caching
---


# Question
Title: Multilingual settings form using i18n variable
I'm using a settings form for my module and I'm trying to make some of the fields multilingual.

I've declared the multilingual variables with hook\_variable\_variable\_info (and with hook\_variable\_group\_info for my custom group):

```
function MYMODULE_variable_info() {
  $variable['my_variable_name'] = array(
    'type' => 'string',
    'title' => t('My title'),
    'default' => MY_DEFAULT_VALUE,
    'description' => t('My description.'),
    'localize' => TRUE,
    'group' => 'my_group'
  );

  return $variable;
}

```

I've added my settings form (one field for example)

```
function MYMODULE_settings_form() {
  $form = array();

  $form['my_variable_name'] = array(
    '#type' => 'textfield',
    '#title' => t('My title'),
    '#title_display' => 'before',
    '#default_value' => variable_get_value('my_variable_name'),
  );

  return system_settings_form($form);
}

```

And as you can see I've used system\_settings\_form($form) to save my form fields as variables.
I've checked my new variable at 'admin/config/regional/i18n/variable' and the form shows that it's a multilingual form and multilingual field, but when I'm switching to another language the value isn't saved. (Only the English version saves and changes the value for all languages)

Thanks.

# Answer
Not sure if it's the best solution at all, but one way would be getting the langcode from the url parameters:

```
$langcode = !empty($_GET['variable_realm_key_language']) ? $_GET['variable_realm_key_language'] : $GLOBALS['language']->language;

```

And then you can use i18n\_variable\_get() using the $langcode as the second parameter.
> 1 votes

# Answer
I was in a need to create translatable strings for text entered using **Page title** module and I used the following code to create variable

```
function module_variable_info($options) {
    $variables['page_title_type_news_and_event'] = array(
    'type' => 'text',
    'title' => t('Page title CT New Events', array(), $options),
    'default' => '',
    'description' => t('Module : Page title', array(), $options),
  );

  return $variables;
}

```

Now I can see them in others tab at **admin/config/regional/i18n/variable** and I enabled the check box there

Then I can translate my string at **admin/config/system/variable** and at **others tab**
> 3 votes

---
Tags: 7, forms, i18n-l10n
---


# Question
Title: How to make a taxonomy vocabulary overview page with Drupal 7
I have a simple vocabulary named **knowlegde** with several terms. This vocabulary is localized and can be used in many languages. My question now is how can i make a simple page where i can display all content tagged with that vocabulary. The important thing is that the (localized ) vocabulary is part of the url.

For example in german the url should look like

http://example.org/wissen

and in english it should look like

http://example.org/knowledge

# Answer
If you refered that taxonomy term in a content type then a listing page is created by default.

For example if you created a taxonomy named **Category** and terms inside it are

1. Knowledge
2. courage

If you created a content type and refered category taxonomy then listing page will be at **category/knowledge** , **category/courage** and so on

**To display all the contents of the vocabulary** then

> Create a view of type Node
>
> Add a display of type block or page according to your need
>
> Add your desired fields(CCK) along with a field Taxonomy: Term
>
> Add a filter Taxonomy: Vocabulary and select is one of operator and choose the particular vocabulary name.

This solution will include taxonomy terms associated with content node but filter according to the defined vocabulary in filter.
> 1 votes

---
Tags: taxonomy-terms
---


# Question
Title: Set the site display language based on browser's default language
I have my site in two languages i.e. English and French, I want that whenever a user visits the site, it must be displayed in the browser's default language. How to do it ?

# Answer
1. Goto Admin -\> Module -\> Locale
2. Click on Configuration (Locale)
3. Enable Radio button as per you want to set default language.
> 0 votes

# Answer
You could do it something like this:

* create a module (theme independant) that inserts some javascript into the page
* using php, insert the current site language into the javascript as a variable
* check the browser language against the site current language
* if it matches, nothing happens, if not, create a redirect to mysite.com/fr/ or however you have it setup to differentiate the languages
> 0 votes

---
Tags: i18n-l10n
---


title: How to use Basic Cart module?

text:
# Question
Title: How to use Basic Cart module?
I have installed and activated basic cart module.
then I went to admin/config/basic-cart
their I selected my content type.
Then in view I added a field `content:Add to cart`
When I viewed my view result their I wasn't able to see button for add to cart.
How to use that module so that it show me that button
Basic Cart I an using Drupal 7

# Answer
Make sure your field output has the correct format in the view - select the 'Add to cart button' in the field formatter.
> 1 votes

---
Tags: 7
---


# Question
Title: Can´t create more than one content type group
I am using Drupal commons for a community social network. I am trying to create a second group based on a content type named Leagues. In order to create that group I went to: /admin/structure/types/add, gave the group a name and selected the group check box (as the example given on this page: https://www.drupal.org/node/2014777).

But for some reason every time I try to create a new league and save it, I get this error:

> EntityMetadataWrapperException: Unknown data property `field_og_subscribe_settings`. in `EntityStructureWrapper->getPropertyInfo()` (line 335 of /home2/jane/public\_html/devpage/profiles/commons/modules/contrib/entity/includes/entity.wrapper.inc).

It seems that the field field\_og\_subscribe\_settings is attached to the content type group which I am not exactly sure what it means, but it seems I can´t create more than one group based on a content type.

# Answer
> 1 votes
It seems this solves your issue : EntityMetadataWrapperException

You probably need to add field\_og\_subscribe\_settings field to your new content group type, and make it required.

You can take a look at

`/admin/structure/types/manage/group/fields/field_og_subscribe_settings`

to see how it's been configured for the default group content type.

Refer this link for detailed details about this issue: EntityMetadataWrapperException errors due to features not being reverted

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


# Question
Title: Drupal Commerce, Search API DB and Views | How to display the product variation accordingly to the attribute being applied as filter?
**SCENARIO:**

1. A Size attribute field has been added to a Product Type at **/admin/commerce/products/types/PRODUCT-TYPE/fields** and "Enable this field to function as an attribute field on Add to Cart forms." option has been checked.
2. Two products have been created at **admin/commerce/products/add/PRODUCT-TYPE**. Size attribute Large at a price of $20 and Small at a price of $10 respectively.
3. One Content Type display node has been created at **node/add/CONTENT-TYPE**. The two sized product variants were attached to the Product Reference field.
4. A Search API Index for the product nodes has been created at **admin/config/search/search\_api/index/PRODUCT-INDEX**.
5. A Search API - Product Index View has been created at **admin/structure/views/add**.
6. The Size Attribute has been added as an Exposed Filter Criteria to the view. One could also use the Size Facet.

**ISSUE:**

The filtering works just fine. The issue lies on the product field values displayed, like price for instance, that do not align with the filtering criteria.

Regardless of which size has been applied as filter, the price displayed on the view represents the first product attached to Product Field reference on the product display node.

In our case scenario, the Large size product is first on the list of products attached to the Product Field Reference. If size Small is applied as filter, it displays the price of $20 on the view display. This is troubling because $10 should be displayed instead.

Is there a way to fix it? That is, the price + other product fields will display the variant values accordingly to size attribute being applied as filter?

**UPDATE:**

This question here addresses the same issue wrapped into a different context.

# Answer
Feature request here

This is not the ideal solution but will do for now. There are 2 steps to it:

1. At Views UI:

1. Add all the fields you need into your view and Exclude them from display.
    2. At last add a Global Custom Text field for building your row display. This is my example:

    \< div class="image"\>\[field\_image\]\< /div\> \< h3 class="title" \>\[title\]\< /h3\>\< div class="price"\>\< span class="old"\>\[field\_old\_price\]\< /span\>\< span\>\[commerce\_price\]\< /span\>\< /div\> \< div class="addtocart"\>\[add\_to\_cart\_form\]\< /div\>
2. In your template.php file:

.

```
/**
 * Implements THEME_views_view_field__VIEWID__DISPLAY__FIELD().
 */
function mytheme_views_view_field__myview__page__nothing($vars) {
  $nid = $vars['row']->entity;
  $size_attibute_tid = myvalue;
  $row_product_id = $vars['row']->_entity_properties['field_product_reference:entity object']->product_id;

  $query = db_select('commerce_product', 'p');
  $query->join('field_data_field_size_attribute', 't', 't.entity_id = p.product_id');
  $query->join('field_data_field_product_reference', 'pr', 'pr.field_product_reference_product_id = p.product_id');

  $query
    ->fields('p', array('product_id'))
    ->condition('field_size_attribute', $size_attibute_tid)
    ->condition('pr.entity_type', 'node')
    ->condition('pr.entity_id', $nid);
  $query = $query->execute()->fetchAssoc();

  $query_product_id = $query['product_id'];
  if (isset($query_product_id) &&
      $query_product_id != $row_product_id) {

    $node_title = $vars['row']->_entity_properties['entity object']->title;
    $node_url = $vars['row']->_entity_properties['url'];
    $product = commerce_product_load($query_product_id);

    $line_item = commerce_product_line_item_new($product, 1, 0, array(), $product->type);
    $line_item->data = array(
      'context' => array(
        'product_ids' => array($query_product_id),
      ),
    );
    $add_to_cart_form = drupal_get_form("commerce_cart_add_to_cart_form_$query_product_id", $line_item);
    $add_to_cart_form = drupal_render($add_to_cart_form);

    $price = commerce_currency_format($product->commerce_price['und'][0]['amount'], $product->commerce_price['und'][0]['currency_code']);
    $old_price = commerce_currency_format($product->field_old_price['und'][0]['amount'], $product->field_old_price['und'][0]['currency_code']);

    $image_variables = $product->field_image['und'][0]['image_dimensions'] += array(
      'style_name' => 'my-image-style',
      'path' => $product->field_image['und'][0]['uri'],
    );
    $image = theme_image_style($image_variables);
    // You should install https://www.drupal.org/project/commerce_product_urls module
    $image = "<a href='$node_url?id=$query_product_id'>$image</a>";

    $vars['output'] = "<div class='image'>$image</div>
      <h3 class='title'>$node_title</h3>
      <div class='price'>
        <span class='old'>$old_price</span><span>$price</span>
      </div>
      <div class='addtocart'>$add_to_cart_form</div>";
  }

  return $vars['output'];
}

```
> 0 votes

---
Tags: views, commerce, search
---


# Question
Title: Pathauto is prepending <front> to the urls
In my pattern for pathauto I'm using `[nodesymlink:menu-link:parent:url:path]/[nodesymlink:menu-link:title]` and for menu items that are children of the front page it is prepending `<front>` to the beginning of the url instead of just leaving it blank.

Perhaps it's an issue with the nodesymlinks module. Has anyone had this issue before? The urls still work, but I don't want the text `<front>/` in front of my urls.

# Answer
As stated in my comment above, the issue is with pathauto and not with nodesymlinks.

Basically, pathauto is replacing the standard `[node:menu-link:parent:url:path]` or your `[nodesymlink:menu-link:parent:url:path]` with the `<front>` slug instead of just removing it when the parent menu item is the front page.

I have been looking into a fix and couldn't find any. This is why I wrote a custom module to remove the front slug from the paths generated by pathauto. I'm including the link to future proof the answer in case the post gets updated and I'll also copy/paste the full code at the end of this answer.

Also, if you're a beginner, follow the link for more info on how to create a custom module in Drupal 7 and the like. Otherwise, just drop this code into your custom module and it should fix the situation you're describing. The function's code is well commented in case you need extra info.

Good luck.

```
<?php

/**
 * Implements hook_pathauto_alias_alter().
 *
 * Needed so that we remove the buggy slug <front> from paths when their
 * nodes are a sub-menu-item of the front page while using this pathauto
 * pattern: [node:menu-link:parent:url:path]/[node:title]
 *
 * If the parent is the homepage, all menu child entries will get <front>
 * added to the beginning of their URL alias which looks really ugly and
 * doesn't work on all operating systems. We need to remove it.
 *
 * Pathauto 7.x-1.2 doesn't handle this properly. Maybe later versions will.
 */
function yourmodule_pathauto_alias_alter(&$alias, array &$context) {
    //Init the slashed front slug value
    $front_slug_slashed = '<front>/';

    //If the alias contains the slashed front slug, remove it
    //Note that pathauto will later check if the generated slug is a duplicate
    //and append an incrementing number to it so no need to worry about this
    if(strpos($alias, $front_slug_slashed) !== false) {
        //Save the non-modified alias for logging
        //Note: no better way to clone a string in PHP?
        $original_alias = $alias . '';

        //Remove the front slug from within the alias
        $alias = str_replace($front_slug_slashed, '', $alias);

        //Log to Drupal's watchdog as notice
        $msg = '';
        $msg .= 'Altered pathauto alias from "' . check_plain($original_alias);
        $msg .= '" to "' . check_plain($alias) . '"';
        watchdog('sk', $msg, array(), WATCHDOG_NOTICE);
    }
}

```
> 2 votes

---
Tags: path-aliases
---


title: Multiple Separators! How?

text:
# Question
Title: Multiple Separators! How?
I've got a field called Name (Entity Reference) that sometimes has 2 values. It would require some kind of Rules I guess. Just not sure how it can be done. I created a taxonomy which has 3 values: "none", "backslash", "and".

So what I wan't to do is if there are 2 values and I've chosen "backslash" the output will be "Name1" / "Name2".

If there are 2 values and I've chosen "and" the output will be "Name1" & "Name2".

Am I on the right track here?

# Answer
This doesn't sound like a Rules problem. (yet) To re-state the issue: you are trying to output display the values, and use a delimiter when there are multiple values. Correct?

If so, where is the display taking place, of for example, "Name1" / "Name2" Is this in a Node, View, Module ... or elsewhere? Please be as specific as possible.

A Rules problem would sound like "for Trigger X I expect Action Y to take place".
> 0 votes

# Answer
If we are talking about node display then it sounds like problem for the Custom Formatters module.

You can define a formatter in code that iterates through all values and joins them with '/' and then use this formatter in your node display settings (additionally to the default options)
> 0 votes

---
Tags: taxonomy-terms, rules
---


# Question
Title: Combing View Formatters with Custom Formatter
So I'm tearing out my eyes for a solution here. I have a view,and all I want to do for the image content is to use two different formatters effects. Example I want to use Adaptive Image formatter and Lightbox2 formatter. I started tinkering with custom formatter html+token but I guess I'm not that advance to figure out how to combine html + token variable to create a custom formatter of two formatter effects.

Are there any examples of combing two formatter effects to create a Custom Formatter?

# Answer
Custom Formatters module is a (another) good way for this, you can check more samples in official website at: http://customformatters.com.

You probably need to use PHP code for this and get all advantages of powerful Drupal API, tokens are limited uses for simple outputs without rewrite.

Example for render image fields (do NOT include ):

```
$output = '';
foreach ($variables['#items'] as $item) {
    $output .= theme('file_link', array('file' => (object) $item));
}
return $output;

```
> 0 votes

---
Tags: views, media, tokens, entities, theming
---


# Question
Title: Custom formatter for a multi-valued field
I have a multi-valued image field and I'd like to use its delta value with the Custom Formatters module. What I want to do would be really simple with html+tokens if it were to work:

```
<div id="cf">
  <a href="[node:url]"><img class="bottom"  style="border:0;"src="[node:field_image:0]" alt="[node:title]" ></a>
  <a href="[node:url]"><img class="top"  style="border:0;" src="[node:field_image:1]" alt="[node:title]" ></a>
</div>

```

However, I don't see the option for the delta value available in the list of tokens available, and using that code would just end up with `[node:field_image:0]` and `[node:field_image:1]` being replaced as `src=""`

Could you please advice me on how to do this? I think I need to use php but I don't know how. Thank you very much!

# Answer
here a sample for rendering (image) fields but you can easily access to other fields of entity:

```
$output = '';
foreach ($variables['#items'] as $item) {
  $output .= theme('file_link', array('file' => (object) $item));
}
return $output;

```

Another line example for manual image rendering:

```
$output .= '<img typeof="foaf:Image" src="'.image_style_url('YOUR_IMAGE_STYLE', $your_entity->your_field['und'][0]['uri']).'" alt="'.$your_entity->your_field['und'][0]['alt'].'"/>';

```
> -1 votes

---
Tags: 7, tokens, entities
---


# Question
Title: Drupal installation profile: menu_link_save() doesn't work for "import" path
In my installation profile, I am trying to add a menu link for the `/import` path (from *feed\_import module*). `menu_link_save()` works for all my menu paths with the exception of `/import`. Anyone have ideas why?

So, this works and creates a menu path to `/user`:

```
$link = array('menu_name' => 'menu-authenticated', 'link_path' => 'user', 'link_title' => 'Account');
menu_link_save($link);

```

But this does not:

```
$link = array('menu_name' => 'menu-authenticated', 'link_path' => 'import', 'link_title' => 'Import');
menu_link_save($link);

```

After installation is finished, `/import` path works (*feeds\_import* is installed and enabled in the installation profile), but the menu link was not created.

Any help would be much appreciated. Thanks!

# Answer
> 1 votes
As tvl advised, "import" path is not yet defined in when MYPROFILE\_install() is called in MYPROFILE.install. So moved the code over to MYPROFILE.profile and used hook\_install\_tasks() as explained here: https://www.drupal.org/node/1022020

```
/**
 * Implements hook_install_tasks().
 */
function MYPROFILE_install_tasks($install_state) {
  $tasks['add_import_link'] = array(
    'display_name' => st('Adds import link to menu-administrator'),
    'display' => TRUE,
    'type' => 'normal',
    'run' => INSTALL_TASK_RUN_IF_NOT_COMPLETED,
    'function' => 'callback_add_import_link',
  );

  return $tasks;
}

function callback_add_import_link() {
  // Add the menu link
  $link = array('menu_name' => 'menu-administrator', 'link_path' => 'import', 'link_title' => 'Import', 'weight' => 5);
  menu_link_save($link);
  menu_rebuild();
}

```

# Answer
> 0 votes
1. Enable the *Feeds* module in your `my_installation.info` file.

```
dependencies[] = feeds
dependencies[] = feeds_ui

; I also use:
dependencies[] = feeds_xpathparser
dependencies[] = feeds_tamper
dependencies[] = feeds_tamper_ui

```
2. Edit the `my_ installation.profile` and add there your menu link:

```
function my_ installation_install_finished(&$install_state) {
  // Flush all caches to ensure that any full bootstraps during the installer
  // do not leave stale cached data, and that any content types or other items
  // registered by the installation profile are registered correctly.
  drupal_flush_all_caches();

  // Add the menu link
  $link = array('menu_name' => 'main-menu', 'link_path' => 'import', 'link_title' => 'Import');
  menu_link_save($link);

  // This is not a correct - full install_finished(&$install_state).
  // Copy the Drupal's function and then edit it.
}

```

Remember you must login to see the `/import` link.

---
Tags: routes, installation-profiles
---


# Question
Title: Send contact form results to google drive spreadsheet
Is it possible, after form submission (Webform), that the data is immediately sent to spread-sheet in `Google drive` or some kind of similar application?

Simple fields like : date, time, first name, last name, webform title.

# Answer
> 1 votes
There is a module that claims to do so (I haven't used it myself but this would be a good starting point): Webform to Google Docs

> This module inserts Webform submissions as new rows in a Google Docs spreadsheet. In the future it may handle updating of entries as well as saving submissions into "docs" as well as "spreadsheets".

---
Tags: 7, emails
---


title: How to use condition with multiple term

text:
# Question
Title: How to use condition with multiple term
I try to get all the node that belong to 2 taxonomies terms (term 1 AND term 2).

I try with this :

```
    $select = db_select('node', 'n')
      ->fields('n', array('nid','title'))
      ->condition('n.status', 1);
    $select->fields('n', array('nid'));
    $select->fields('n', array('title'));
    $select->orderBy('n.title', 'ASC');
    $select->join('field_data_field_sous_theme', 'ss', 'ss.entity_id = n.nid');
    $select->condition(db_and()->condition('ss.field_sous_theme_tid', 517)->condition('ss.field_sous_theme_tid', 514));
    $results = $select->execute()->fetchCol();

```

or this :

```
$select = db_select('node', 'n')
  ->fields('n', array('nid','title'))
  ->condition('n.status', 1);
$select->fields('n', array('nid'));
$select->fields('n', array('title'));
$select->orderBy('n.title', 'ASC');
$select->join('field_data_field_sous_theme', 'ss', 'ss.entity_id = n.nid');
$select->condition(db_and()->condition('ss.field_sous_theme_tid', 517)->condition('ss.field_sous_theme_tid', 514));
$results = $select->execute()->fetchCol();

```

But there is no result.

And when i try this :

```
$select = db_select('node', 'n')
  ->fields('n', array('nid','title'))
  ->condition('n.status', 1);
$select->fields('n', array('nid'));
$select->fields('n', array('title'));
$select->orderBy('n.title', 'ASC');
$select->join('field_data_field_sous_theme', 'ss', 'ss.entity_id = n.nid');
$select->condition('ss.field_sous_theme_tid', array(517,514), 'IN');
$results = $select->execute()->fetchCol();

```

I've all the nodes that belong to the term 1 OR the term 2.

I've you got an idea to solve my problem ?

Ps: sorry for my bad english, i'm french :-)

# Answer
> 0 votes
What about getting the arrays of `nids` for each of the `tids` you want to search with `taxonomy_select_nodes($tid)` and then intersect the lists with `array_intersect`. There should be a more Drupalistic way however...

# Answer
> 0 votes
Join your field\_data\_field\_sous\_theme table a second time using a different alias:

```
$select = db_select('node', 'n')
  ->fields('n', array('nid','title'))
  ->condition('n.status', 1);
$select->fields('n', array('nid'));
$select->fields('n', array('title'));
$select->orderBy('n.title', 'ASC');
$select->join('field_data_field_sous_theme', 'ss', 'ss.entity_id = n.nid');
$select->join('field_data_field_sous_theme', 'ss2', 'ss2.entity_id = n.nid');
$select->condition(db_and()->condition('ss.field_sous_theme_tid',517)->condition('ss2.field_sous_theme_tid', 514));
$results = $select->execute()->fetchCol();

```

This is how I would do it in strict SQL. I agree there might be a more Drupally way to do it, if you are willing to share the rest of the problem.

---
Tags: database
---


# Question
Title: How to hide the comment form label (not title)?
I have tried a number of different modules that claim to do this but none have worked, I have also tried changing the comment.tpl file, and I even tried using CSS "Display:none"; however nothing has worked. So how can I hide the "Comment" label on a comment form box? I am not talking about the comment title here, as this can be easily disabled in the content type settings. This is what I am talking about:

I originally thought that this could be done in the manage display settings, by setting the comment label to hidden. So I did this but it didn't change the label of the comment box:

So how can this be done? I simply want to hide the word "Comment" and the "\*" after it of course.

# Answer
> 1 votes
You can easily do this with CSS. Looking at dev tools, I see that the label is called **edit-comment-body-und-0-value** (yours might be different). So what we need to do is, simply edit the CSS file and put in the line `label[for*="edit-comment-body-und-"] { display:none; }` and clear the cache at /admin/config/development/performance.

That's all there is to it.

K.

# Answer
> 0 votes
```
 /* Remove the "your name" elements for authenticated users */
function YOURTHEME_form_comment_form_alter(&$form, &$form_state) {
if ($form['is_anonymous']['#value'] == false) {
$form['author']['#access'] = FALSE;
$form['comment_body']['und']['0']['#title'] = FALSE; //Remove the user name
$form['comment_body']['und']['0']['#title'] = FALSE;
$form['comment_body']['und'][0]['#required'] = FALSE;
 }
}

```

---
Tags: comments, entities
---


title: Organizing search in Drupal Commerce.

text:
# Question
Title: Organizing search in Drupal Commerce.
I have site (e-shop) that uses Search API. Just Search API, Search Autocomplete, Display Suite Search and Database Search are enabled. It was not configured by me.

However, we have big problem. Search returns strange results, we cannot use search by brand cause when we choose brand on Exposed Filter with AJAX and catalog reloads, add to cart product's forms wont work cause forms were rebuild and there's no workaround for this issue.

Can you tell best (and modules) way to organize search in Commerce shop?

Do I need to use Facets and Apache Solr - technologies, which are not used now?

# Answer
You can use the Search\_api\_db to avoid Apache Solr. Facets come in many flavors, there's no standard tutorial but some googling will get you started...
> 0 votes

---
Tags: commerce, search
---


# Question
Title: Why page-view counters not working (displayed)?
I have set up to display the page-view (hit) counter, using the Drupal 7 core `statistics` module, following the standard procedure (see, for example, the summary here).

However, (A) only English contents show the counter but none of the other languages on a site, and (B) none of the contents show the counter on another site.

The structure and installed modules in those sites are slightly different. However, as far as the settings (configuration, permission etc) of the `statistics` module is concerned, they are the same.

What is happening? Where should I look for to investigate?

# Answer
I suppose the cause can vary. However, it seems multilingual sites may have additional factors that contribute to make this counter-related stuffs go wrong. Here are a couple of example cases for multilingual sites.

I assume you are using the path-prefix based language negotiation as the high(est) priority. In your case (A), is the English the default language and no path-prefix is defined for English? In your case (B), are the path-prefixes defined for all the enabled languages, including the default language? In those cases, it is suspicious some module(s) that use i18n are causing a trouble.

First, check the database table `node_counter`. If a node has a non-zero `totalcount`, and if you don't see the page-view counter when you view the node, then it is likely to be down to either the permission or your theme, which may not show the counter in the first place.

If the `totalcount` column has zero count, despite you (preferably as a non-authenticated user) have viewed the node (and have flushed all caches), then the `statistics` module is not working, either due to its own failure or other module(s) fail to access the `statistics` module.

Have a look at "Recent log messages" `/admin/reports/dblog`. If you see (probably plenty of) "page not found" for `modules/statistics/statistics.php`, then the latter is the case, or at least is contributing.

In that case,

1. Confirm `modules/statistics/statistics.php` does exist, and the file permission is set to be readable to any one, as well as all the parent directory permissions are set to be readable and executable to any one.
2. In the table of "Recent log messages" `/admin/reports/dblog`, click the links (for TYPE: page not found) `modules/statistics/statistics.php` in the Message column. What do you see? Does the LOCATION include the language prefix (like `/fr/`)?
3. If that is the case, your module(s) try to access the non-existing page like `fr/modules/statistics/statistics.php` instead of the correct path without the language prefix. Best figure out which module is causing the trouble and fix the module. If that is not practical, alternatively you can control the path at the server level: read the answer to Why so many “page not found” for statistics.php?.
> 1 votes

---
Tags: 7, i18n-l10n, nodes, log-messages
---


# Question
Title: Allow a user to upload a PDF file to a specific block within a page
Wondering if anyone can help with a problem:

I have created a content type called 'Brochures' and added a 'file' field with a pdf format. I want the user to be able to upload pdf file(s) then select a particular page for the pdf to populate having them display in a block-view on that specific page.
So the user process would be:

-add content
-select 'Brochure' content type
-browse/upload PDF
-select a page for the PDF to populate \<-----This is the part that is giving me grey hair. ;)
-save

Hope I am making sense.

Always, Jason

# Answer
You could use the Entity Reference module to add the "Select a page for the PDF to populate" field (in the "Brochure" content type).

Then, create a View block that filters on "content type = brochure" and which pulls the PDF file field only. Set up a Contextual Filter for the entity reference field (the one that you selected the node/page for the PDF to populate on) and provide a default value of the nid of the page being viewed.

Placing this block in a region should pull related PDFs for pages that have been referenced. Should work!
> 0 votes

---
Tags: views, nodes
---


title: Security Update?

text:
# Question
Title: Security Update?
Drupal gives me the following message:

> There is a security update available for your version of Drupal. To ensure the security of your server, you should update immediately! See the available updates page for more information and to install your missing updates.

But when I click on available updates, it says:

> Manual updates required
>
> Updates of Drupal core are not supported at this time.

So what should I do?

# Answer
> 2 votes
You can update modules directly through the admin panel, but Drupal cannot update itself (at least not yet). So you will have to do that upgrade through the filesystem by uploading the new Drupal core files in place of the old ones, or (preferably) the command line with Drush.

Here is an instructional page:

You can also find guidance in the UPGRADE.txt file in the Drupal core package.

If you are familiar with the command line, you can use Drush to do updates which makes it very quick and easy. If you are not familiar with Drush, here is a beginner's guide.

---
Tags: updating
---


# Question
Title: Attach shipping courier selection at drupal cart commerce line item
Anyone have Idea how to attach shipping courier selection at drupal commerce cart? As seen at capture bellow, I want to attach shipping courier selection at cart, so I can pick shipping courier for each order line item. Anyone have Idea?

https://lh3.googleusercontent.com/-OMoDWmIZcyo/VFkLxBQGcWI/AAAAAAAACtc/lCidjfXgeSI/w1043-h396-no/Capture.PNG

# Answer
> 0 votes
I think Commerce Delivery module solved your problem.

Or you need to add Shipping plugin.

Please check this two links. I think this may help you.

Link 1

Link 2

---
Tags: commerce
---


# Question
Title: Autocomplete Field in View Exposed Filter
I have created an index Using the Search Api. and integrate with View. And in filter criteria i have indexed vocabulary. then i want to expose that filter criteria with auto complete field instead of select list.

# Answer
> 1 votes
I think you created a **indexed view** in which the dropdown option will not appear in filters. you can alter the form by the following steps

> Alter the type of the field as text
>
> Provide a ajax callback for that field by creating a menu. I provide you with a sample code for it :)

eg: `$form['location']['#autocomplete_path'] = 'location_autocomplete';`

**Sample Code** :

```
function mymodule_menu() {
     $items = array();
      $items['location_autocomplete'] = array(
    'page callback' => 'location_autocomplete_callback',
    'type' => MENU_CALLBACK,
    'access arguments' => array('access content'),
  );
}

function location_autocomplete_callback($string = "") {
  $matches = array();
  // apply sql queries to get the field values
  drupal_json_output($matches);
}

```

---
Tags: views, taxonomy-terms, ajax
---


title: Problem with change position of Sidebar

text:
# Question
Title: Problem with change position of Sidebar
I am using the **Droupon** theme of Drupal. I am facing problem while changing the sidebar from right to left. Using CSS I can change it. But I want to know if I can change the position of the sidebar from admin panel without any modification in the CSS.

Thanks Subha.

# Answer
> 0 votes

---
Tags: blocks
---


# Question
Title: taxonomy with image field is not translating
I have a taxonomy term with an image field in it.

The problem is when I try to translate the taxonomy term and choose an image, the term is not translated and the language is set back to Language Neutral on save action.

Here is the message who came up when I hit the save button

```
Created new term testtttttt.
You are not authorized to access this page.

```

It's only happened when I fill the Image field, otherwise the taxonomy is translated correctly.

It's seem to be a new bug in drupal https://www.drupal.org/node/2227181

Thanks

# Answer
As a temporary solution, when you add the image don't upload it, just select it and save the term, it will translate correctly.

I will update the answer once I find why it is not working when the image is uploaded first.

**Update :** The problem is that when you upload the image the `$form` gets cached without the translation details. Use the following code as workaround.

```
function MYMODULE_form_alter(&$form, &$form_state, $form_id){
   if(($form_id=='taxonomy_form_term') && (!isset($form_state['triggering_element']) || $form_state['triggering_element']['#id']!='edit-delete')){
       $form['#after_build'][] = 'MYMODULE_after_build';
}

function MYMODULE_after_build($form, &$form_state) {
     if(!isset($form_state['storage']['rebuilding'])){
        $form_state['storage']['rebuilding']=TRUE;

     }
     else{
        $form_state['no_cache']=TRUE;
     }

}

```
> 0 votes

# Answer
I tried wolverine's answer but it didn't worked for me, it caused error "#build\_id not defined" so I changed it a little, I don't know if it's right solution but it worked for me.

Add only this code in your module:

```
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
    if (($form_id == 'taxonomy_form_term') && (!isset($form_state['triggering_element']) || $form_state['triggering_element']['#id'] != 'edit-delete')) {
        if (!isset($form_state['storage']['rebuilding'])) {
            $form_state['storage']['rebuilding'] = TRUE;

        } else {
            $form_state['no_cache'] = TRUE;
        }
    }
}

```

Hope it's helpful for someone.
> 1 votes

---
Tags: taxonomy-terms, i18n-l10n
---


# Question
Title: Any way of not to render the pane in panel using custom module?
I dont want to use `PHP visibility rule` to add a custom condition but I want to hide a pane based on some condition. How can I do that?

# Answer
> 3 votes
What you're looking for is called a `access plugin`, those are how Page manager (and by extension Panels) control both access and visibility settings.

This question: What are Ctools plugin (content type, access, etc), and how does one create them? has a lot more details and implementation examples.

---
Tags: 7, panels
---


title: Running drush from a minimal shell

text:
# Question
Title: Running drush from a minimal shell
My goal is to pipe mail with Postfix into a drush command. I made a simple bash script that redirects stdin to the drush command, and I configured Postfix to pipe mail to the script. But executing drush from the script does not work, as it cannot connect to the database. I assume there is some environment/bootstrapping missing but I cannot figure out what.

Bash script, `postfix-filter.sh`:

```
#!/bin/bash

# Enter Drush environment
cd `dirname $0`

# Redirect stdin to Drush command, log any ouput
/usr/local/bin/drush my-command <&0 &> my_command.log

```

Running the script from terminal works fine:

```
$ ./postfix-filter.sh < test.eml

```

But when triggered by Postfix receiving a mail, the following is printed to the log file:

```
The drush command 'inmail-process' could not be found.  Run `drush       [error]
cache-clear drush` to clear the commandfile cache if you have
installed new extensions.
Drush was not able to start (bootstrap) the Drupal database.             [error]
Hint: This may occur when Drush is trying to:
 * bootstrap a site that has not been installed or does not have a
configured database. In this case you can select another site with a
working database setup by specifying the URI to use with the --uri
parameter on the command line. See `drush topic docs-aliases` for
details.
 * connect the database through a socket. The socket file may be
wrong or the php-cli may have no access to it in a jailed shell. See
http://drupal.org/node/1428638 for details.

Drush was attempting to connect to:
 Drupal version        :  8.0.0-dev
 Site URI              :  http://default
 Database driver       :  mysql
 Database hostname     :  127.0.0.1
 Database port         :
 Database username     :  root
 Database name         :  drupal
 PHP executable        :  /usr/bin/php
 PHP configuration     :  /etc/php.ini
 PHP OS                :  Darwin
 Drush version         :  7.0-dev
 Drush temp            :  /tmp
 directory
 Drush configuration   :
 Drush alias files     :  /Users/mdi/.drush/aliases.drushrc.php
 Drupal root           :  /usr/local/var/www/d8/www
 Site path             :  sites/default
 Active config path    :  sites/default/files/config_FTG0_Sy-OJ0Mco
                      1c4ZlOBwJ3Ia-sMX0PcQiIiaGcsRufMWfFBWwSWLu
                      lhB83nL0hF9Dl9Y24-w/active
 Staging config path   :  sites/default/files/config_FTG0_Sy-OJ0Mco
                      1c4ZlOBwJ3Ia-sMX0PcQiIiaGcsRufMWfFBWwSWLu
                      lhB83nL0hF9Dl9Y24-w/staging

```

As you can see from the output, I have already tried setting the database host to 127.0.0.1, as suggested by various discussions I found.

Any ideas on what is missing?

# Answer
> 0 votes
Adding the following line to the beginning of the script fixed it:

```
PATH=/usr/local/bin:$PATH

```

I assume Drush uses the `$PATH` in turn to call other commands.

---
Tags: drush, 8
---


# Question
Title: Drupal 7 Homebox module and Twitter Bootstrap theme
I am using Drupal Homebox module (https://drupal.org/project/homebox, version 7.x-2.0-beta6) to create a dashboard. I've found an issue that the save function to keep the status/location of blocks on the dashboard (closing or moving) doesn't work when using Twitter bootstrap theme. But there is no problem when using Batik theme. I could not find any clues of what cause this issue.

Any help would be greatly appreciated!

# Answer
> 1 votes
Hi make this change found on sites/all/modules/homebox/hombox.js on line 16.

```
Drupal.homebox.$pageSave = $homebox.find('#homebox-save-form button[type=submit]');

```

*Why?* bootstrap changes the input type in the page.tpl so you need to reflect the changed

---
Tags: 7, theming, dashboard
---


# Question
Title: Why doesn't drupal_render work, but render does?
I've a piece of code what is rendering a custom table (see var\_dump below) what is shown on for specific states of the node. The data of the table is for both states the same.

```
array(1) {
  [0]=>
  array(5) {
    ["#theme"]=>
    string(5) "table"
    ["#header"]=>
    array(2) {
      [0]=>
      string(4) "test"
      [1]=>
      string(9) "geen test"
    }
    ["#rows"]=>
    array(2) {
      [0]=>
      array(2) {
        [1]=>
        string(6) "e1a1r1"
        [2]=>
        string(6) "e1a2r1"
      }
      [1]=>
      array(2) {
        [1]=>
        string(6) "e1a1r2"
        [2]=>
        string(6) "e1a2r2"
      }
    }
    ["#prefix"]=>
    string(38) "<h3>Table</h3>"
    ["#attributes"]=>
    array(1) {
      ["class"]=>
      array(1) {
        [0]=>
        string(15) "previous-scheme"
      }
    }
  }
}

```

The custom states of the node are determined by a condition what prints one of the following gathered variables.

For the variable at the line below works with both drupal\_render and render.

```
$kickoff_deadline .= '<h2>Between kickoff and deadline</h2>'.drupal_render($table);

```

For the variable at the line below only works with render, without it wont show anything.

```
$after_deadline .= '<h2>After the deadline</h2>'.render($table);

```

So what is happening? Why doesn't drupal\_render work for a similar printed variable what does work?

# Answer
> 7 votes
Once you've done this:

```
$kickoff_deadline .= '<h2>Between kickoff and deadline</h2>'.drupal_render($table);

```

The render array is marked as `#printed`, and won't be rendered again. So this

```
$after_deadline .= '<h2>After the deadline</h2>' . drupal_render($table);

```

Will do nothing.

If you take a look at the code for `render()`:

```
function render(&$element) {
  if (is_array($element)) {
    show($element);
    return drupal_render($element);
  }
  else {
    // Safe-guard for inappropriate use of render() on flat variables: return
    // the variable as-is.
    return $element;
  }
}

```

You can see it runs `show($element);`, making it available for rendering again. Which is why this works:

```
$after_deadline .= '<h2>After the deadline</h2>'.render($table);

```

# Answer
> 3 votes
If you look at the documentation for those functions there are hints to this.

drupal\_render() will only render the element if it has not already been printed and has not been hidden using hide().

render() on the other hand will always render the element because it calls show() on the element before then calling drupal\_render() on it.

---
Tags: 7, theming
---


# Question
Title: Change the url parameter 'search_api_views_fulltext' used in views exposed filter
Im trying to modify the url parameter 'search\_api\_views\_fulltext' so that it becomes nicer to read.

i would like something like "s" or "search"

Im using search\_api + search\_api\_db + facet\_api modules, with views.

Ive been looking every where but couldn't find any way to do this

Maybe someone among you guys could have an idea ?

# Answer
> 7 votes
There is a settings "Filter identifier" under More fieldset when you expose a field.

---
Tags: views, search
---


# Question
Title: How to check Drupal distribution version from CLI?
I have OpenAtrium2 instance and I want to check it version from CLI.

How can I do it?

# Answer
> 3 votes
Just run the following command from the root directory of your Open Atrium installation:

```
drush status-report

```

This should give you the output similar to the status report screen in the standard Drupal backend. In my Open Atrium installation, one of the lines reads:

```
Install profile            Info      OpenAtrium (openatrium-7.x-2.18)

```

So in this case I'm running Open Atrium version 2.18.

---
Tags: drush
---


# Question
Title: Alter field (multiple values) to add more items/values of another field
In my case, I use Drupal Commerce *(Kickstart 2x distribution)* with a images field (multiples/unlimited values).

I need to **display all images of parent product AND images of their childrens** (variations).

Another case are to display images of a field but if empty, I want to display images of another images field.

**What's the good way for this?**

1. Relation module
2. hook\_field\_load()
3. hook\_query\_alter()
4. hook\_node\_load()
5. hook\_load()

---

*Related questions:*

How to create a single slideshow combining several image fields?

# Answer
Here my current solution but I think it is better to use hook\_preprocess\_field()?

```
/**
 * Implements hook_node_load().
 */
function MY_MODULE_entity_load($entities, $type){
    if('commerce_product' === $type && !path_is_admin(current_path())){
        foreach($entities as $entity){
            if(in_array($entity->type, array('MY_PRODUCT_TYPE')) && property_exists($entity, 'sku') && !empty($entity->sku)){
                $query = new EntityFieldQuery;
                $query->entityCondition('entity_type', 'node', '=')
                  ->propertyCondition('type', $entity->type)
                  ->fieldCondition('field_product', 'product_id', $entity->product_id, '=')
                  ->range(0, 1);

                if ($result = $query->execute()) {
                    reset($result['node']);
                    $nid = key($result['node']);
                    $parent_product = node_load($result['node'][$nid]->nid);
                    $parent_product_images = field_get_items('node', $parent_product, 'MY_IMAGES_FIELD');
                    if (is_array($parent_product_images)) {
                        $pos = count($entity->field_images['und']);
                        foreach($parent_product_images as $ppi_field){
                            $entity->field_images['und'][$pos++] = $ppi_field;
                        }
                    }
                }
            }
        }
    }
}

```
> 0 votes

---
Tags: entities, media
---


# Question
Title: Change the default timezone variable_get from views
What I want is to change the way **drupal views** get the site's timezone setting. I want to set it manually in code.

Searching through the files I noticed that the function "`views_get_timezone()`" in `sites/all/modules/views/includes/handlers.inc @1182` (drupal 7) is responsible for getting the timezone and setting the `session.time_zone` in mysql, but when I change it nothing happens.

Any suggestion anyone for this or any similar solution? I just want to make a site with multiple timezones for anonymous users so I want to change the session.time\_zone in mysql according the user location.

Thanks

# Answer
If you want to change the time zone, the option is available in admin menu in:

* admin/settings/date-time in Drupal 6
* admin/config/regional/settings in Drupal 7

And it can be defined in **settings.php** as **date\_default\_timezone**

It can be accessed in Database in variables table too

```
SELECT *  FROM variable WHERE name LIKE  '%timezone%'

```
> 0 votes

---
Tags: 7, views, datetime
---


# Question
Title: How to include PHP code in welcome email?
I need PHP (for some logic) inside the welcome email, the welcome email structure is defined in `admin/config/people/accounts` (in the text box)

How can I place PHP code there? I tried to put some PHP but I only get a blank email. Or if I can\`t execute PHP code inside the email box what module can I use to do this?

# Answer
> 1 votes
Updated :

Use PHP mailer module to send the email in the format of php

---
Tags: 7, emails
---


# Question
Title: I have Created a form to upload images, where i should display error message if i upload more than 3 images and should disable submit button
I have Created a form to upload images, where i should display error message if i upload more than 3 images and should disable submit button to delete already uploaded image if i want to upload more images

# Answer
> 2 votes
Follow the steps

Go to image field settings of you content type.

Then Go to Image Field Settings and select '3' for number of values for the image

That's it. When user reaches their upload limit (3) the submit button will be disappeared automatically. and display like follows.

---
Tags: ajax, javascript
---


title: Warning message when patch is applied?

text:
# Question
Title: Warning message when patch is applied?
I applied a patch and I get a Warinig message.

Then it states that the patch was applied cleanly.

Can I trust this?

This is the complete code:

```
example@d565:~/www$ git apply -v SA-CORE-2014-005-D7.patch
Checking patch includes/database/database.inc...
warning: includes/database/database.inc has type 100755, expected 100644
Hunk #1 succeeded at 733 (offset -3 lines).
Applied patch includes/database/database.inc cleanly.
example@d565:~/www$

```

# Answer
> warning: includes/database/database.inc has type 100755, expected 100644

You can trust that the file has been applied successfully, but not that the file was in the expected state to begin with.

`755` and `644` refering to numeric notation of unix-system file permissions.

What the warning says is that the patch lists the file as being not executable, but it found the file to be executable. This had no effect on applying the contents of the patch to the file though.
> 2 votes

---
Tags: version-control
---


# Question
Title: How to save a free text views query entered into an exposed filter by the user?
I would like to save the entered exposed filter text by the user possibly into its own content type. Would I have to look at the url path for this via $\_GET vars?

# Answer
Use hook\_form\_alter and add an extra submit handler:

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

```

In your callback function use node\_save to save the values you extracted from `$form_state['values'];`
> 1 votes

---
Tags: 7, views, nodes
---


# Question
Title: Facet Blocks are not appearing in indexed views
I have created Index with apache solr server using search API.

Created a view using that index in page display and facets are appearing as rendered in side bar.

Now I Created another block display in the same view but now the facets are not displaying in the block display.

What would be the problem with block display and facets?

# Answer
I figured out what the problem was... I rendered that block in sidebar region.. That was it..

When your search isn't the main content on the page then the facets does not appear now I rendered the block view it in **Content Region**.

Now the facets appear!!!
> 0 votes

---
Tags: views, search
---


# Question
Title: Is it possible to add a CiviCRM API to the Webform CiviCRM integration module and how would I do that?
If I have created a specific CiviCRM API entity/action for a project, can I then add that API to the Webform CiviCRM integration module so that I can use the API in the Webform? And how would I do that?

# Answer
> 3 votes
I found this old link for plans to add arbitrary api calls to the module, but it doesn't appear to have ever been implemented: http://forum.civicrm.org/index.php?topic=22304.0

But it appears that I could use hook \_webform\_submission\_presave to execute the api call when the webform is submitted.

---
Tags: webforms, civicrm
---


# Question
Title: return other indexed fields using SearchApiQuery($index)
I created an index that indexes taxonomy terms. I indexed the term name + field\_skill type text. The current result shows only the term id + score.

I want to show also the field\_skill.

```
 $term = 'drupal';

 // Select an index.
 $index = search_api_index_load("terms");
 $query = new SearchApiQuery($index);

 // Conditions.
 $query->condition('name', $term, '=');
 // $query->condition('language', $language->language, '=');

 // Fetch results.
 $results = $query->execute()['results'];
 dpm($results); // returns only ids and score I want to return other indexed fields

```

# Answer
If you are using Solr, on server configuration (admin/config/search/search\_api/server/YOUR\_SERVER\_NAME/edit), under "Advanced" fieldset, you should enable the "Retrieve result data from Solr" option:
> 3 votes

---
Tags: 7, search
---


# Question
Title: How to reference a Current Node URL Prior/After a User submits a Rules Link trigger
Maybe I'm way off mark here. I have an Node 'application' page and require that the current view page be referenced within a following page after a logged in user has clicked the 'Apply' link (a Rules Link). The above node allows a user to apply for an advertised role say a musician for a bands project guitarist vacancy, but basically its like any other Jobsboard type process.

I can get my Nodes related with the Relation model, but that's not the issue. The issue is that I need to get the relation of the current viewed page so that once the User applies, the said Node will be referenced for later recall in any applicant or Advertiser's dashboard. At the moment, all that happens is that the Rules link takes an Applicant user to a custom vacancy complete form page (which I have made using Panel Pages) and it fires off fine, but there is no link to either parties involved for me to then manage back-end and build further functionality on.

I want to grab the Job Node URL so that after a user hits an 'Apply' Rules Link button (shown on the Job node page bottom) it then makes a note of the said Node (URL) so that a number of Rules Actions such as create a new Node number; create a relationship to the Applicant; saved a new entity as an Application Node. I can manage to get the 'Submit' to trigger to the application page, and 'send it' but I'm not sure at what stage or where temporarily the said Node url path needs to be set prior to Rules then taking it and working through it's Rules actions (ie, post application, send email to application, send message to Advertiser you have a 'new' applicant whereas after they can do further tasks (outside of this question posted here).

Or, maybe my approach is completely off goal. Maybe the only important point is to get the Rules Link to relate to the currently viewed Node (job position in question offered) which when triggered will then relate the user to any other uses. I'm not sure, but even looking at first loading any Node, is it possible that the Rules Link has to already pull in the Node ID once the user clicks to view the Node on screen, then the Rules Link will have already built a relationship?

Hope the above is not too confusing! but I've tried to express my mental ideas. I would like to do this in Rules. (I'm using Rules, Rules Link, Views).

Failing all of that, how do I link in a User application to relation to the original post so that the advertiser can see who has applied to the said vacancy advertised?

Please, where am I going wrong in my approach and what am I missing?
Much appreciated. Thanks.

Revised question: 21/05/14.

# Answer
> 0 votes
A custom way to do it... Sorry not using Rules but it might help.

So you have two main node types ? And advert and an application ? And the link to the application needs to contain the node ID of the advert. I would use a custom link and hook\_form\_alter. For example;

If the apply link is only seen on the advert node page then you can use:

```
$nid = arg(1);
print l(t("Apply"), "node/add/application/$nid");

```

either in a node.tpl.php or in a preprocess function.

This will take the user to the node add form. In a custom module you use hook\_form\_alter to get the $nid from the URL and add it to the form in the in the right field such as :

```
/**
 * Implements hook_form_alter().
 */
function custommod_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#id'] == 'application-node-form') {
    if (isset(arg(3))) {
      $form['field_advert_relation'][LANGUAGE_NONE][0]['target_id']['#default_value'] = arg(3);
    }
  }
}

```

This is for a normal entity reference field. And the field could be disabled or hidden also.

---
Tags: rules, workflows
---


# Question
Title: Slideshow with views - Make slideshow title optional
Hopefully this is an easy task and I am just too much a beginner to solve it ...

I use a slideshow that can be configured using views. Slideshow uses the following fields: Title, nid, and Slideshow image.

Is it possible to introduce an extra field (checkbox -\> boolean) to page/article and then to exclude the title from being displayed if the boolean checkbox is checked? To be precise; intrudicing the checkbox is easy, but I do not know how to evalute it then to exclude title in slideshow if checkbox is checked.

# Answer
> 5 votes
Yes. Assuming your view is displaying fields (under Format \> Show), you'd follow these steps:

1. Install the views\_php module.
2. Edit your view, adding the fields you wish to display all the time.
3. Add the boolean field to the view, checking the "exclude from display box."
4. Add the title field to the view, checking the "exclude from display box."
5. Add a new field "Global: PHP" to the view. In the "output code" field, enter in the following code:

---

```
<?php
$title = NULL;
if ($data->field_field_show_title[0]['raw']['value'] === "1") {
  $title = $row->title;
}

echo $title;
?>

```

This code assumes your boolean field is called field\_show\_title. Note that, for whatever reason, $row-\>field\_show\_title reports the node ID instead of the value of the field, so I had to dig it out of the data object instead.

Beneath the "output code" field you'll find an "available variables" section which describes the data that views makes available to your PHP snippet.

You may order the fields however you like, of course.

# Answer
> 2 votes
The very simple way of doing this without using `views_php` module is in following steps :

1. Add `Title` field in View and exclude it
2. Add the `Boolean` type field in view
3. Rewrite `Boolean` field value and use title token there
4. Select `hide if empty` and `count 0 as empty` from `No Result Behaviour` fieldset of boolean field

and It is done in very simple steps. :)

# Answer
> 0 votes
Probably the only way to do precisely what you want is to exclude all of the fields from the display and use Global PHP instead.

However, I think an easier way to accomplish this might be to add a text field to your content type called something along the lines of “Slideshow Title.” Use this field to type in whatever you want the slideshow to use for the title, and just leave it blank if you do not want it to use one. (You of course do not need the Boolean field if you use this method.) Then tell Views to use that field rather than the proper Title field.

This wouldn’t be as elegant as the Boolean checkbox solution, but these slideshows can get complicated when you have to display them with Global PHP. This solution would also allow you to use something other than the title of the node if you ever want to customize what is displayed in the slideshow.

---
Tags: views
---


# Question
Title: CiviCRM Email Record appearing in other members profile Information
We have a Drupal module that allows users to sign up and create their own personal fundraising page. Every Drupal user is matched to their equivalent CiviCRM profile where the information is stored. The Drupal module then reads information from CiviCRM to display custom reports such as how much they have raised and their contact info.

There is one email that is in the system and is getting overlaid somehow into other members profiles. The owner of the email has not created a page, I'm not sure how their email even got into the system. It has happened twice already. On a mailing the owner of the email account responded saying they were not the correct person.

Any ideas how this happened and how to correct it?

# Answer
CiviCRM has a table `civicrm_uf_match`, which links CiviCRM contacts to Drupal (or Wordpress or Joomla) users. Here is its structure:

```
CREATE TABLE `civicrm_uf_match` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'System generated ID.',
  `domain_id` int(10) unsigned NOT NULL COMMENT 'Which Domain is this match entry for',
  `uf_id` int(10) unsigned NOT NULL COMMENT 'UF ID',
  `uf_name` varchar(128) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'UF Name',
  `contact_id` int(10) unsigned DEFAULT NULL COMMENT 'FK to Contact ID',
  `language` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'UI language preferred by the given user/contact',
  PRIMARY KEY (`id`),
  UNIQUE KEY `UI_uf_name_domain_id` (`uf_name`,`domain_id`),
  UNIQUE KEY `UI_contact_domain_id` (`contact_id`,`domain_id`),
  KEY `FK_civicrm_uf_match_domain_id` (`domain_id`),
  KEY `I_civicrm_uf_match_uf_id` (`uf_id`),
  CONSTRAINT `FK_civicrm_uf_match_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE,
  CONSTRAINT `FK_civicrm_uf_match_domain_id` FOREIGN KEY (`domain_id`) REFERENCES `civicrm_domain` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4997 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

```

'UF' stands for Underlying Framework, i.e. the Drupal, Wordpress or Joomla installation to which CiviCRM is linked.

Sometimes entries in this table can get out of sync, e.g. if the Drupal database has been copied from a development server to a test server without also copying the CiviCRM database.

Perhaps that is what has happened in this case. You could check by examining the `civicrm_uf_match` records for the relevant email addresses, which are stored in the `uf_name` field.

It can also be useful to join `civicrm_uf_match` to the Drupal `users` table and check for any records where the email in `civicrm_uf_match` differs from the email in `users`. Also a left join from `civicrm_uf_match` to `users` can highlight orphan `civicrm_uf_match` entries.
> 5 votes

---
Tags: civicrm
---


title: Add a small javascript/HTML to a page

text:
# Question
Title: Add a small javascript/HTML to a page
So I have a small bit of HTML and Javascript that I want to embed in a basic page. I go to edit the page, turn off rich text editing, and paste the HTML/javascript. I save, and then the javascript portion gets deleted while the HTML stays.

Is there any reason for this?

It is worth noting that the site is maintained and run by the university, although I have full permissions.

Other people say just add a bit of php and add\_jscript(), but don't say where that goes, or how to get to that file.

EDIT: So I contacted the IT department and they suggesting adding the script as a block, and then adding the block to the page. Thanks for all your help!

# Answer
> 9 votes
It looks like what's happening is your text format settings are stripping the JS out of the page. You can edit the formats by going to /admin/config/content/formats, or you may just need to select a different format for the node in question (under the body field when you edit the node).

If you need the JS available on several pages, have a look at: https://www.drupal.org/node/304255.

---
Tags: javascript, theming
---


# Question
Title: Why does Drupal webform civicrm returns DB Error: syntax error when trying to add a new organization type contact?
I've setup a webform wherein all logged in users can create new organization contacts on civicrm via webform civicrm integration module. Not sure if this is a bug or I'm missing something important from the setup.

Note: Current module and versions used.

Civicrm version 4.4

Webform civicrm integration version 7.x-4.9

Webform version 7.x-4.1

# Answer
Might want to ensure that you are using the latest versions of all the above modules. There have been significant improvements in the newer releases

Also can the user create non-organization contacts? What is the error message?

lobo
> 5 votes

# Answer
I found a similar question on the webform\_civicrm issue queue: https://www.drupal.org/node/2356741 . If this is your question too, then based on the further information you provide there of the MySQL query and error message...

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY id1, id2 ON DUPLICATE KEY UPDATE weight = weight + VALUES(weight)'"

... here's one possible explanation, if you are on a very old version of MySQL. The VALUES() function was added in MySQL 4.1.1. If you're on an older version than that, it would explain the syntax error.
> 5 votes

---
Tags: civicrm
---


# Question
Title: How can I create a "show full article" button that bypasses smart paging?
I am using smart paging currently but would like to create a button above my articles that would show the entire article on a single page (canonical link) that would also have no pagination (bypass smart paging entirely for that link). I'm not finding any solutions on how to do this. Is it even possible? These links are for search engine indexing so that the non paginated version would serve as a landing page for search results traffic.

# Answer
I have never used smart paging, but from looking at the docs and the code I would say this is currently not possible. My suggestion in this case would be to create a feature request in the modules issue queue.
> 0 votes

# Answer
My work around was to modify the smart\_paging-pager.js by adding an option tag. So right
before ....

`js_box += '</select></li>';`

add...

`//Create option to view full article
 js_box += '<option> ' + selected + ' value="' + base_url + '/' + current_url + '?nopaging=1' + '"' + Drupal.t('Page: Full Article ') + '</option>';`

Problem though if you update the module be sure to add the option back into the js file
> 0 votes

---
Tags: uri
---


# Question
Title: How to set body content using preprocess_node?
I need to alter the body html for a specific content type which will be processed by the Pagination module. I think preprocess\_node will work, but I'm having trouble figuring out how to change the body content.

```
function mytheme_preprocess_node(&$vars) {

  // Collect / create / adjust new body content
  $new_body = $vars[??];
  $new_body = _mytheme_do_stuff();

  // Assign to output
  $vars[??] = $new_body;
}

```

When I look into `$vars` I see many options (`$vars['body']`, `$vars['content']`, `$vars['node']`, etc). I'm probably close, but I haven't been able to affect the output yet. Anyone know what I should be targeting?

If there's a better approach, I'd love to hear that too.

# Answer
An alternative way is to create a new variable and assign your function output to it like below

```
$new_body = _mytheme_do_stuff();

// Assign to output
$vars['new_body'] = $new_body;

```

new\_body variable will now be available in your template file. So instead of printing body print $new\_body in your template (tpl.php)
> 0 votes

# Answer
It is as simple as altering `$vars['content']`:

```
function mytheme_preprocess_node(&$vars) {

  // Collect / create / adjust new body content
  $new_body = $vars['content'];
  $new_body = _mytheme_do_stuff();

  // Assign to output
  $vars['content'] = $new_body;
}

```

The content does appear to have already been altered by the Pagination module at this point. For my case, though, that's ok.
> 0 votes

---
Tags: 6, theming, nodes
---


# Question
Title: Preventing users from registering with xxx@yyy format email address
Drupal seems to let users register with emails like `xxx@yyy`

I heard that this kind of email address can exist. But I want users to register with only emails like `xxx@yyy.zzz`

Is there any way to validate this type of email format and prevent users from registering with it?

# Answer
There is a core function named: function valid\_email\_address that will check that the syntax is valid.

Example of use:

```
$mail = $form_state['values']['submitted_tree']['email_address'];
if (!valid_email_address($mail)) {
  form_set_error('[submitted][email_address]', t('The email address appears to be invalid.'));
}

```
> 2 votes

---
Tags: 6, emails, forms
---


title: Changing Account password using rules

text:
# Question
Title: Changing Account password using rules
I'm using rules module in my site (drupal 7), i want to create a small form to the user to change his password without going to (account editing page).

This form contain 3 textbox (old passowrd, new password, confirm new password).

Can i make this form using rules?
or is there another module can help me with that?
Thanks a lot.

# Answer
> 1 votes
The best way would be to make a custom page using hook\_menu(), and have a submit function on that page that would check the user's authentication, and if it was correct, change the current password.

If you need a bit more information on that, I'm happy to help.

# Answer
> 0 votes
Rules won't help you build a user interface, however the password\_policy module provides a dedicated user profile tab for changing password and may be of interest.

> ...a password tab available to users instead of the usual user/#/edit screen for password changes.

---
Tags: 7, rules
---


# Question
Title: how to upgrade drupal 7 site to universal analytics
what happens if a user upgrades to universal analytics on their google analytics admin page, yet we are still using the drupal 1.4 module, which according to the documentation does not support universal analytics

# Answer
I found out that there will be no effect in the meantime on the existing google analytics behaviour, just that the new UA functionality will not be available.
> 0 votes

---
Tags: google-analytics
---