# Question
Title: How do I save and retrieve CKEDITOR media (images and video) on a CDN?
I am using CKeditor, and I need to add media in content. I have enabled the media in the CKeditor configuration.

Then I upload an image:

The image is being added:

Checking the path for the image :

It gets saved in the local server, while I want it to be saved in a CDN.

I am also using the Media module and CDN old S3 module. which saves all the media in the CDN, but the images for CKeditor are saved on the local server.

Currently, it is saved in the base path (eg. https://drupal.stackexchange.com/). I want it to be saved and retrieved from my CDN.

I did find the Uploadcare : Add media from anywhere plugin, but I don't understand how to use it; I think it has its own CDN, but I want it to use my own CDN.

Modifying the core is not recommended and it is not the best practice, how do I achieve it in efficient way. How do I save images added from CKeditor on a CDN instead of the local server?

# Answer
Until CKEditor developers implement the functionality, you could create a custom module that:

* on node add/edit you loop thru all fields using CKEditor and crawl each images/videos
* detect if the images are already on the CDN
* if not, upload the images/videos on the CDN
* replace the images links with your new CDN links
* save the node

I hope it will help you.
> 1 votes

---
Tags: files, wysiwyg, media, cdn
---


# Question
Title: I want to subscribe an user to a Mailchimp list as soon as their account is activated
I want to subscribe an user to a Mailchimp list as soon as their account is activated. I've created a module to use hook\_user\_presave() and am trying to call mailchimp\_subscribe\_user() after that.

```
function mymodule_user_presave(&$edit, $account, $category) {
  if ($account->uid // user is not new
      && $account->status === "0" && $edit['status']==1) { // user is being activated
        $list_id = 1;
        $list = mailchimp_get_list($list_id);
        $mergevars = mailchimp_lists_load_user_mergevars($account, $list);

        watchdog('mymodule_log', 'account->uid '.$account->uid);
        watchdog('mymodule_log', 'list->id '.$list_id);

        mailchimp_subscribe_user($list, $account->mail, $mergevars, FALSE);

        watchdog('mymodule_log', 'got this far!');
  }
}

```

`$account-uid` has a valid value and so does `$list_id`. The problem that does show is up is this

```
Notice: Trying to get property of non-object in mailchimp_subscribe_user()
            (line 103 of .../sites/all/modules/mailchimp/mailchimp.module).
Notice: Trying to get property of non-object in mailchimp_subscribe_user()
            (line 105 of .../sites/all/modules/mailchimp/mailchimp.module).
Notice: Trying to get property of non-object in mailchimp_subscribe_user()
            (line 116 of .../sites/all/modules/mailchimp/mailchimp.module).

```

The lines-

```
$double_optin = $list->settings['doublein']; //line 103

$success = $mcapi->listSubscribe($list->mc_list_id, $email, $merge_vars, 'html', $double_optin, TRUE);  //line 105

mailchimp_cache_clear_user($list->mc_list_id, $email); //line 116

```

And is there any better way to achieve this?

# Answer
> 0 votes
Try below code ... You are missing 5th argument in mailchimp\_subscribe\_user

```
function mymodule_user_presave(&$edit, $account, $category) {
  if ($account->uid // user is not new
      && $account->status === "0" && $edit['status']==1) { // user is being activated

        $mcapi = mailchimp_get_api_object();
        $list_id = 1;
        $list = mailchimp_get_list($list_id);
        $mergevars = mailchimp_lists_load_user_mergevars($account, $list);

        watchdog('mymodule_log', 'account->uid '.$account->uid);
        watchdog('mymodule_log', 'list->id '.$list_id);

        mailchimp_subscribe_user($list, $account->mail, $mergevars, TRUE, $mcapi);

        watchdog('mymodule_log', 'got this far!');
  }
}

```

---
Tags: 7, users, emails
---


# Question
Title: Hide a div on webform submission using ajax
I am new to drupal i am using webform ajax module to submit my webform , its submiting values properly after validating them , but along with this i want to hide a div also on submit . what is the best way to do this

# Answer
The most effort-free way to hide something i can think to goes trough some CSS.

Inspect the div you want to hide for its id, then just add a rule in your theme CSS

```
#id { display: none; }

```
> 0 votes

# Answer
Your best option is probably to add an ID to the submit button, or get the ID thats already assigned to it, and stick a bit of jQuery into the header of that page.

```
(function ($) {
$('#SubmitButton').click(function() {
     $('#DivYouWantToHide').hide();
});
})(jQuery);

```

Just replace the ID names with the ones you want to use.
> 0 votes

---
Tags: 7, ajax, webforms, javascript
---


# Question
Title: Views: Modify filter/argument when no results occur
I currently have a "store locator" proximity search setup very similar to the one detailed here: http://www.youtube.com/watch?v=AxeskzN8BAc.

The user enters a postcode, and receives results or no results as the case may be, for a given rectangular distance (say 100km around the entered postcode). Both postcode and distance are exposed filters.

If a node/marker isn't within the zone, I get no results. How can I dynamically modify or widen the distance so there are always some results? ie. How can I hook onto the exposed filter arguments and re-run the view for the no-results case?

# Answer
> 3 votes
I think the logic you should follow is to filter the results always with a maximum distance you want to show and sort the results by the distance and then limit the results to a specific number. That way you will always have results and you won't need to call the same view twice, which would impact the performance.

# Answer
> 4 votes
You can call the view programatically and if no result are found call it again with new filter arguments.

For example: $view\_id = 'your view id'; $display\_id = 'your display id';

```
$view = views_get_view($view_id);
$view->preview($display_id, $views_args);

if (!count($view->result)) {
  // No results, call view again with other filter value.
  $filter_name = 'your filter name';
  $filter_value = 'your filter value';

  $view = views_get_view($view_id);
  $view->preview($display_id, $views_args);
  $view->display['default']->display_options['filters'][$fiter_name]['value'] = $filter_value;
  $view->preview($display_id, $views_args);
}

```

You will have to adapt it using your current filter name and right values. You can rewrite this example to modify the view all the times you need.

Put this code in a hook\_menu callback returning the view.

# Answer
> 1 votes
I have a similar venue proximity search set up on my site, and when a customer searches for a venue and gets no results, I display a secondary view in the no results behaviour, showing all venues, with a message below saying "There were no results for the area you selected, please widen your search parameters, or manually browse for a venue near you using the map"

---
Tags: views, search
---


# Question
Title: How to create node in hook_node_insert without triggering it recursively
I have a situation where I need to create node(s) in hook\_node\_insert for certain dates.

Details: There is a content type with date field (start and end-date enabled). The requirement is to create the node with same contents for those many dates.

For example, if the date is from Mar5, 2014 to Mar8, 2014. I need to create node with Startdate & Enddate: Mar5 for one node and Startdate & Enddate: Mar6 for the next node and so on till Mar8 is assigned as start & enddate for the last node.

I got stuck with infinite loop. How do I solve this?

# Answer
> 2 votes
Why not add a second submit handler using hook\_form\_alter to the node add form and put your functionality in there as opposed to using hook\_node\_insert?

That way the code will run everytime the node add form is submitted, but you won't get into the endless loop scenario...

# Answer
> 1 votes
You can solve your infinite loop issue with one simple condition...

In hook\_node\_insert before you are creating new nodes check if start date and end date are not equal.. Because new nodes you are creating carry same start and end dates... So that you don't run into infinite loop situation.. If yes then only run a loop for N + 1 times where N = different of start date and end date and create N + 1 nodes.. That's it :-)

---
Tags: 7, nodes
---


# Question
Title: Is it possible to attach discussion board to a node?
I have a content type called "Movies". I would like to create discussion threads under it similar to discussion threads in imdb.com under a movie. I have tried the advanced forum module and also brain forum module. They don't seem to do that I have in my mind.

Is there a module which does this job? I think I will have to use advanced forum module and use a content type for forum discussion and then use entity reference and entity reference prepopulate to link it to the other content type. Is there a better and cleaner way to do this?

# Answer
Use the core comment module.

(If you want to order the newest comments at the top then see Comment goodness)
> 0 votes

---
Tags: 7, comments, nodes
---


title: Alter Registration Form Text

text:
# Question
Title: Alter Registration Form Text
I am trying to alter the email description text on my user registration page. I have added the following to the bottom of my template.php file but nothing is happening. It seems like the function isn't even being called. Any suggestions?

```
function theme_form_alter(&$form, &$form_state, $form_id){
    switch($form_id) {
        case 'user_register_form':
            $form['account']['mail']['#description'] = t('E-mail Address');
    }
}

```

# Answer
> 0 votes
you need to call the function YOURTHEME\_form\_alter(), where YOURTHEME is the name of your theme. Eg, the Bartik theme would have such a function called bartik\_form\_alter() ... you must also clear your drupal cache for the changes to take affect.

**EDIT**

you make your code like this:

```
function YOURTHEMENAME_form_alter(&$form, &$form_state, $form_id){
    switch($form_id) {
        case 'user_register_form':
            $form['account']['mail']['#description'] = t('E-mail Address');
    }
}

```

if you call your theme "sky" it would be `sky_form_alter`.

---
Tags: users, forms
---


# Question
Title: including js through module info file is not working
mymodule.info:

```
name = custom
description = custom module

core = 7.x
version 7.x-0.1

scripts[] = custom.js

```

created the file custom.js in the same folder as custom.module file I have the `$scripts` variable in html.tpl.php cleared all caches

Still cannot see custom.js in page sources. What else it might be?

# Answer
The problem is with a typo in the info file. It's missing a "=" on the version line. Correct info file here:

```
name = custom
description = custom module

core = 7.x
version = 7.x-0.1

scripts[] = custom.js

```

Also note that the version properties is discouraged
> 1 votes

---
Tags: 7
---


title: Adding sitewide JS file in module

text:
# Question
Title: Adding sitewide JS file in module
I have a module that will provide a dropdown when creating a new block. Selecting either none, option 1 or option 2 will add a corresponding class to that block. That class will be targeted by a small (\>4kb) jquery file. The file needs to be able to access every page since blocks can be put anywhere on the site.

I have seen multiple methods of adding JS files to websites, including editing the theme .info file. What is the best way to accomplish what I am trying to do? If the info file is the best way to go, is there a way to programmatically add the JS file to the info file?

# Answer
You can add the file to a theme's or module's .info file using `scripts[]`:

```
scripts[] = js/my-script.js

```

The path should be relative to your module root.

See also Writing theme .info files and Writing module .info files.
> 0 votes

---
Tags: 7, hooks, javascript
---


# Question
Title: Customizing webform results submission page
I'm new to drupal. I'm using the Drupal 7 version. I have created one webform with Name, gender, program, branch, district, college..etc fields. And now I want to customize the webform result submissions page. I want to display the submission list based on the district selected. Can anyone help me with this? I will be very thankful.

# Answer
> 1 votes
Look at EntityForms to have more control over submissions and selecting what submissions to view.

```
Features
Ability to attach any Drupal Field to the Forms
Ability to use most field based and entity aware modules.
You can download submitted data to XML and / or CSV data files using View Data Export.
Rules based form submission notifications. Allows for complex notifications logic.
Rules based form access control. Allows for complex access logic.
Use Views to create to create an administrative listing of each Entityform type Submissions for fine grain control.

```

# Answer
> 0 votes
I believe we have fewer options left while displaying webform submission results but we can always do it with node form and can easily enjoy cck fields flexibility. You can create a content type with the same set of fields s on webform and can allow permissions to create node of that content type for user roles as per your requirement, the simply create a view of that content type and you will have all options over there to filter, group your results to any field you want.

---
Tags: 7, views, webforms
---


# Question
Title: ImageFlow module doesn't find its library in Drupal 7
I have downloaded and installed ImageFlow module and also the library library from here and placed its content in `\sites\all\libraries` . this is screenshot:

but when I'm trying to enable ImageFlow it reports this error:

**You need to install the Imageflow library. The js file should be readable at sites/\*/libraries/imageflow/imageflow.js. You can find the library at http://finnrudolph.de/ImageFlow/Download. (Currently using Imageflow library Library required for Imageflow)**

`imageflow.js` is in the directory. I have tested both uppercase and and lowercase for ImageFlow directory but it doesn't work. why it doesn't find the ImageFlow directiry in /libraries?

# Answer
Try using the dev version of the module. I was having the same problem, found this issue: https://drupal.org/node/2042787 Seems the maintainer fixed it in dev but did not in the point release.

If you find documentation on getting this to work after installation, please link!
> 1 votes

# Answer
**"The js file should be readable at sites/\*/libraries/imageflow/"**

From your screenshot it seems the library is stored in sites/\*/libraries/**Imageflow**/

If it's a linux box your's running the site from, it will differentiate between **/imageflow/** and **/Imageflow/**. Try renaming the folder to use a lower case "i" in the word imageflow.

Hopefully that should fix it :)
> 0 votes

---
Tags: views, installation, theming
---


title: LDAP Query View Errors for RSS

text:
# Question
Title: LDAP Query View Errors for RSS
I'm trying to add an RSS feed to a LDAP Query view, but I keep getting and error message.

"***Row style plugin requires specifying which views fields to use for RSS item.***"

Is there a way to show an RSS feed from LDAP in Views?

UPDATED WITH IMAGE

# Answer
> 0 votes
LDAP lets you query an LDAP service, create a View of an ldap query, process an ldap result using Feeds, or import/update Users to your site.

An RSS view, provided by Views RSS, is simply a contributed View type from a community module. You must tell Views what `fields` should show up in the RSS feed you're creating. Typically there is a `Settings` option next to the `Row Style` to set what fields to display.

See the attached settings options (which is using an LDAP Query View). You need to make your LDAP Query first using the LDAP module, then add a new `Display Type` of type `Feed` in Views and then configure the `Fields` settings for the RSS feed.

---
Tags: views, 7, feeds, authentication-authorization
---


# Question
Title: Multiple condition in Conditional Field doesn't work
I am using Conditional Fields Module to show and hide fields according to the condition selected.

At first, I have a **Select List** with **3** Values (***Mind, Body, Soul***)

When I select ***Body*** the two fields (*Body, What are your diet Plans?*) shows up, like in Picture:

When I select Soul another Two fields Show up:

But When I select Mind, I get only one field, even though I have configured it to show two fields.

My Conditional Field Configuration is:

The issue here is, ***What are your prayers?*** field is configured to show when either ***Mind*** or ***Soul*** is selected from that Select List

I have configured it correctly using **OR** in the field condition but it(what are your prayers?) only shows while selecting *Soul* from the select list.

Any ideas what is wrong here?

# Answer
> 0 votes
I was in the same trouble.

I just found that you can use one condition and use "Values input mode" to Only one of these values (XOR) and Set of Values to the ID or Text of the value of the field you want.

Check that : http://www.interworks.com/blogs/gbivens/2010/06/04/tricking-drupal-webforms-allowing-multiple-options-same-key-value

EDIT : Here a picture

---
Tags: 7, entities
---


title: How to customize download filename?

text:
# Question
Title: How to customize download filename?
Drupal version: 7.14

Currently drupal save the downloaded filename as the last part of the URL, just like a file link "http://example.com/system/files/abc.txt", the default saved filename is "abc.txt".

I want to ask is how to change "abc.txt" to other filename such as "xyz.txt" while downloading.

# Answer
For this issue there's a prerequisite,that is, your download method must be 'private', otherwise there's no chance for drupal to call your 'hook\_file\_download', it's important!

Here's an example from drupal's file module, change $file-\>filename to what you want, then return to HTTP headers.

/\** * Implements hook\_file\_download().
*
* This function takes an extra parameter $field\_type so that it may
* be re-used by other File-like modules, such as Image.
\*/

> function file\_file\_download($uri, $field\_type = 'file') {
> global $user;
> // Get the file record based on the URI. If not in the database just return.
> $files = file\_load\_multiple(array(), array('uri' =\> $uri));
> if (count($files)) {
> foreach ($files as $item) {
> // Since some database servers sometimes use a case-insensitive comparison
> // by default, double check that the filename is an exact match.
> if ($item-\>uri === $uri) {
> $file = $item;
> break;
> }
> }
> }
> if (!isset($file)) {
> return;
> }
>
> //...........................other codes.........................
>
> // Access specifically denied.
> if ($denied) {
> return -1;
> }
>
> // Access is granted.
> $headers = file\_get\_content\_headers($file);
> return $headers;
> }
> 2 votes

# Answer
For Drupal 7, when implementing Justin's solution, my download name was still the original filename, not the custom name I assigned to `$file->filename`. At the time of this writing Drupal 7's file\_get\_content\_headers() sets

```
$name = mime_header_encode($file->filename);

```

but never uses the variable `$name`.

I found a few patches, but instead of patching core, I did the following:

```
$headers = file_get_content_headers($file);
$headers['Content-Disposition'] = 'attachment; filename="'. $file->filename .'"';
return $headers;

```

For my purposes, I needed the file to be downloaded, which is why I used 'attachment'. But if you need the disposition to be 'inline', then the following snippet could get you started (copied from this patch):

```
$inline_types = variable_get('file_inline_types', array('^text/', '^image/', 'flash$'));
$disposition = 'attachment';
foreach ($inline_types as $inline_type) {
  // Exclamation marks are used as delimiters to avoid escaping slashes.
  if (preg_match('!' . $inline_type . '!', $file->filemime)) {
    $disposition = 'inline';
  }
}

```
> 0 votes

---
Tags: files
---


# Question
Title: Drush does not download modules correctly
Drush says it downloads a module successfully but instead of putting it in sites/all/modules it puts it in the current directory: $ drush dl module\_filter Project module\_filter (7.x-2.0-alpha2) downloaded to \[success\] /drupal/module\_filter. The folder doesn't exist, but if you run the command again the following happens: $ drush dl module\_filter Install location drupal/module\_filter already exists. Do you want to overwrite it? (y/n):

drush version 7.x

# Answer
Drush will put downloaded modules in the current directory if it cannot bootstrap a Drupal site. Run `drush status` to determine whether or not the Drupal site you think you are operating on is recognized by Drush. You might need to use the --uri option to specify the name of the folder that contains the settings.php file, or set up a Drush alias file.
> 2 votes

---
Tags: drush
---


# Question
Title: Get id of an organic group inside a view
How can i get the organic group id inside a view? I tried to get it like this:

```
function HOOK_preprocess_views_view(&$vars) {
  if ($vars['view']->name == 'MYVIEWSNAME') {
    $nid = $vars['view']->result[0]->nid;
    $node = node_load($nid);
    $og_id = $node->og_group_ref['und'][0]['target_id'];
    dpm($og_id);
  }
}

```

This is printing the correct id to my devel debug, but i cant access $og\_id in my view-template.

Or maybe you got an other solution to create the /node/add/document .. link.

# Answer
Do you have a corresponding template file in your sub-theme?

Themes cannot have a preprocess function without a corresponding .tpl.php file

https://drupal.org/node/258089
> 0 votes

---
Tags: views, nodes, organic-groups
---


# Question
Title: How to have various 'access denied' pages depending on URL
I'm trying to make multiple access denied pages and show the relevant one based on the page attempted to view.

Use case:

User is limited to only one "CV" node. If they try to create another, they get an access denied page. I want to display a custom page that says something like, "You can only create one CV". A different access denied page, resulting from a different url, would display a different message.

Is this possible? The only solutions I've found seem to create a single page for all access denied notifications.

Cheers, Oliver

# Answer
> 1 votes
I think you what you need is: hook\_node\_access($node, $op, $account) https://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook\_node\_access/7

Parameters

$node: Either a node object or the machine name of the content type on which to perform the access check.

$op: The operation to be performed. Possible values:

"create" "delete" "update" "view" $account: The user object to perform the access check operation on.

Base on the return values, you can redirect them to custom error page. Example:

```
function hook_node_access($node, $op, $account) {
  $type = is_string($node) ? $node : $node->type;

  if (in_array($type, node_permissions_get_configured_types())) {
   if ($op == 'create' && user_access('create ' . $type . ' content', $account)) {
    $query = drupal_get_destination();
    drupal_goto('node/custom-error-page',$query);
   }
 }

```

---
Tags: users
---


# Question
Title: What do I have to do to get the Modernizr module to work in Drupal?
I would like to use modernizr in drupal to take adcvantage of css media queries, box-shadow and border-radius. I have followed the installation instructions perfectly. I have installed the Drupal Modernizer module and created and properly placed my customized Modernizer build to include support for these three features. Does modernizr just pick up my already existing media queries and css3 styles automatically or do I have to do something else?

# Answer
> 1 votes
Modernizer detects feature support in browsers and adds css classes to the HTML element based on those features. You use those css classes to target newer features to browsers that support them. While it will add HTML5 support to older browsers via the HTML5Shiv, it will not add CSS3 support.

To add support for CSS3 features in older browsers, you'll need to add a polyfill Modernizer has a method called Modernizr.load() that lets you load the polyfill only when you need it.

# Answer
> 1 votes
Modernizr does not add support for any HTML or CSS feature; it simply tests the browser's support for the feature. Of the three features you listed, I would strongly **recommend against polyfills for border-radius and box-shadow**, and only recommend a polyfill for CSS media queries. Both `border-radius` and `box-shadow` have natural fallback values: 0px/none.

If you'd like to know more about using `Modernizr.load()` within Drupal, I've written documentation for the module. My apologies, but the examples should be updated since they reference `boxshadow` and that is precisely what I just said to avoid :) However, the example code is still valid.

https://drupal.org/node/1913830

Here are some slides explaining all of the features of the Modernizr Drupal module, including the Test API, the Modernizr.load() API, and some thoughts regarding the future of how we discuss browser compatibility:

http://rupl.github.io/meet-modernizr/

---
Tags: 7, theming
---


# Question
Title: Using Drupal.settings.basePath in Modernizer / yepnope.js loads
I am currently starting development of drupal sites on Acquia. Using git and working locally is a new workflow for me. When building locally and trying to utilize Modernizr load / yepnope, my JS in my script.js file typically looks like this..

```
Modernizr.load([
    {
    test: Modernizr.mq('only all'),
    nope: '/sitename/docroot/sites/all/themes/theme/js/libs/polyfill.js'
    },
    ....

```

So that works locally on my machine, but when I commit my changes and push to my acquia development server the file path for the loaded scripts is incorrect, since it's not the same setup I guess.

http://mysite.devcloud.acquia-sites.com/mysite/docroot/sites/all/themes/theme/js/libs/polyfill.js

It needs to be the below, without the mysite/docroot in the URL.

http://mysite.devcloud.acquia-sites.com/sites/all/themes/theme/js/libs/polyfill.js

So that brings me to Drupal.settings.basePath. If I print this out it gives me /mysite/docroot/ on my local setup. If I do it on the dev server, it would print out something different (probably just / ).

So me being the amateur assumed I could do something like this.. (forgive the poor sample, I know it can be done better)

```
var myroot = Drupal.settings.basePath

Modernizr.load([
{
test: Modernizr.mq('only all'),
nope: myroot + 'sites/all/themes/theme/js/libs/polyfill.js'
},
....

```

And this of course does not work. Just returns query1 is not defined.

So I am sure there are faults in many of my attempts to make this work.. so if anyone can suggest something to me, either workflow related or how to fix my setup / code, that would be great.

Thanks

# Answer
> 1 votes
Your local environment seems to be misconfigured. If you're running apache with vhosts then your `VirtualHost` definition should look like this:

```
<VirtualHost *:80>
  ServerName whatever-you-choose-for-a-dev-domain.com
  DocumentRoot "/path/to/the/drupal/root/directory"
</VirtualHost>

```

Where the `DocumentRoot` should also include `/sitename/docroot`

Alternatively you may be able to edit .htaccess in the Drupal root directory to RewriteBase /sitename/docroot Which there should already be a commented definition of `RewriteBase` in there that you simply would uncomment. But I think the VirtualHost path would be the best one.

# Answer
> 0 votes
Here is what I do

```
Modernizr.load([
    //first test need for polyfill
    {
        test: window.matchMedia,
        nope: (Drupal.settings.basePath + Drupal.settings.pathToTheme + "/js/polyfills/matchMediajs/matchMedia.js")
    },

    //and then load enquire
    (Drupal.settings.basePath + Drupal.settings.pathToTheme + '/js/enquirejs/dist/enquire.min.js')
]);

```

In my template.php I have the following in my \_preprocess\_page function:

```
drupal_add_js(array('pathToTheme' => path_to_theme()), 'setting');

```

# Answer
> 0 votes
As far as I can tell this is a Drupal core bug in drupal\_get\_js(). The issue seems to be that the Drupal.settings information is actually inserted after all library, module, and theme JavaScript. According to the documentation of drupal\_add\_js(), Drupal.settings should be added to the `JS_LIBRARY` group which has a weight of -100, whereas theme javascript has a weight of 100 and should go after the settings in the source order.

There is a one line patch at http://drupal.org/node/1710002 or you can try this workaround. The workaround assumes that your JavaScript will still work as expected in the footer (just before the `</body>`.

1. Remove the `scripts[] = js/myscript.js` from your theme's .info file.
2. In template.php, add the `drupal_add_js()` line to your existing `hook_preprocess_page()` or add this new function:

```
/**
 * Implements hook_preprocess_page().
 */
function MYTHEME_preprocess_page(&$variables) {
  drupal_add_js(path_to_theme() . '/js/myscript.js', array('scope' => 'footer'));
}

```

# Answer
> 0 votes
If you use the APIs available inside the Modernizr Drupal module, it takes care of requesting the proper path for you. Here are some docs:

https://drupal.org/node/1913830

---
Tags: 7, javascript
---


# Question
Title: how to create domain specific domain admin
I am using domain access module to create different sites using subdomain. I want to create domain specifc admins so that they can view only listing of their own domain and want to able to install modules,themes etc all action on their specific domains.

Only Super admin should able to see all listings without any restricitons .

How can I achieve this ?

Thanks

# Answer
> 1 votes
I have used Access Domain module.

What you have to do is:

A- Create a user role. Example: \[domain A admin\]

B- Give that \[domain A admin\] user permission to access the admin menu system as well as other permission you want.

C- Go to domain module settings - admin/structure/domain/roles Now restrict the \[domain A admin\] to the domain you want.

# Answer
> 0 votes
You can try Domain Admin module

> The granularity of the assignable permissions can be determined by the site admin - some site admins will just want to delegate all power over a domain to their domain managers and don't want their permissions page cluttered up with lots of checkboxes, whereas others may want to delegate some aspects of domain administration and withhold others. Hence there is a setting that allows the admin to choose between having one "administer own domains" permission or a lot of smaller permissions.

---
Tags: domain-access
---


# Question
Title: Custom webform components are not getting stored in database?
I am using webform of version "7.x-3.18+24-dev" and I have altered the webform to add my custom fields like date drop-down(for day,month and year) but these components are not getting stored in database. Does anyone know why its happening. I am attaching my code here for reference .

```
   function scfhp_grievanceform_form_alter(&$form, &$form_state, $form_id) {
    switch ($form_id) {
    /* for chinese */
     case 'webform_client_form_71989':
        $form['submitted']['dob'] = array(
            '#type' => 'fieldset',
            '#title' => t('出生日期'),
            '#weight' => 4,
            '#prefix' => '<div class="chinese_dob" id="webform_chinese_dob">',
            '#suffix' => '</div>',
            '#required' => 'true'
        );

        $form['submitted']['dob']['dob_month'] = array(
            '#type' => 'select',
            '#default_value' => array('month' => '月'),
            '#options' => array('month' => t('月'),
                1 => t('1 月'), 2 => t('2 月'), 3 => t('3 月'), 4 => t('4 月'), 5 => t('5 月'), 6 => t('6 月'), 7 => t('7 月'), 8 => t('8 月'), 9 => t('9 月'), 10 => t('10 月'), 11 => t('11 月'), 12 => t('12 月'),
            ),
            '#description' => t('Select month.'),
            '#required' => true,
        );

        /* for 31 days */
        $form['submitted']['dob']['dob_day_31'] = array(
            '#type' => 'select',
            '#default_value' => array('day' => '日'),
            '#options' => array('day' => t('日'), 1 => t('1'), 2 => t('2'), 3 => t('3'), 4 => t('4'), 5 => t('5'), 6 => t('6'), 7 => t('7'), 8 => t('8'), 9 => t('9'), 10 => t('10'), 11 => t('11'), 12 => t('12'),
                13 => t('13'), 14 => t('14'), 15 => t('15'), 16 => t('16'), 17 => t('17'), 18 => t('18'), 19 => t('19'), 20 => t('20'), 21 => t('21'), 22 => t('22'), 23 => t('23'), 24 => t('24'),
                25 => t('25'), 26 => t('26'), 27 => t('27'), 28 => t('28'), 29 => t('29'), 30 => t('30'), 31 => t('31')),
            '#description' => t("Thirty-One Days."),
            '#required' => true,
        );

        $form['submitted']['dob']['dob_year'] = array(
            '#type' => 'select',
            '#default_value' => array('year' => '年'),
            '#options' => array('year' => t('年'), 1 => t('2013'), 2 => t('2012'), 3 => t('2011'), 4 => t('2010'), 5 => t('2009'), 6 => t('2008'), 7 => t('2007'), 8 => t('2006'),
                9 => t('2005'), 10 => t('2004'), 11 => t('2003'), 12 => t('2002'), 13 => t('2001'), 14 => t('2000'), 15 => t('1999'), 16 => t('1998'), 17 => t('1997'),
                18 => t('1996'), 19 => t('1995'), 20 => t('1994'), 21 => t('1993'), 22 => t('1992'), 23 => t('1991'), 24 => t('1990'), 25 => t('1989'), 26 => t('1988'),
                27 => t('1987'), 28 => t('1986'), 29 => t('1985'), 30 => t('1984'), 31 => t('1983'), 32 => t('1982'), 33 => t('1981'), 34 => t('1980'), 35 => t('1979'), 36 => t('1978'), 37 => t('1977'), 38 => t('1975'),
                39 => t('1974'), 40 => t('1973'), 41 => t('1972'), 42 => t('1971'), 43 => t('1970'), 44 => t('1969'), 45 => t('1968'), 46 => t('1967'), 47 => t('1966'),
                48 => t('1965'), 49 => t('1964'), 50 => t('1963'), 51 => t('1962'), 52 => t('1961'), 53 => t('1960'), 54 => t('1959'), 55 => t('1958'), 56 => t('1957'),
                57 => t('1956'), 58 => t('1955'), 59 => t('1954'), 60 => t('1953'), 61 => t('1952'), 60 => t('1951'), 61 => t('1950'),
            ),
            '#description' => t('Select year.'),
            '#required' => true,
        );

        /* Add dropdown for Date Of Problem Field */

        $form['submitted']['dop'] = array(
            '#type' => 'fieldset',
            '#title' => t('出现问题的日期'),
            '#weight' => 12,
            '#prefix' => '<div class="chinese_dop">',
            '#suffix' => '</div>',
        );

        $form['submitted']['dop']['dop_month'] = array(
            '#type' => 'select',
            '#default_value' => array('pmonth' => '月'),
            '#options' => array('pmonth' => t('月'),
                1 => t('1 月'), 2 => t('2 月'), 3 => t('3 月'), 4 => t('4 月'), 5 => t('5 月'), 6 => t('6 月'), 7 => t('7 月'), 8 => t('8 月'), 9 => t('9 月'), 10 => t('10 月'), 11 => t('11 月'), 12 => t('12 月'),
            ),
            '#description' => t('Select month.'),
            '#required' => true,
        );

        /* for 31 days */
        $form['submitted']['dop']['dop_day_31'] = array(
            '#type' => 'select',
            '#default_value' => array('pday' => '日'),
            '#options' => array('pday' => '日', 1 => t('1'), 2 => t('2'), 3 => t('3'), 4 => t('4'), 5 => t('5'), 6 => t('6'), 7 => t('7'), 8 => t('8'), 9 => t('9'), 10 => t('10'), 11 => t('11'), 12 => t('12'),
                13 => t('13'), 14 => t('14'), 15 => t('15'), 16 => t('16'), 17 => t('17'), 18 => t('18'), 19 => t('19'), 20 => t('20'), 21 => t('21'), 22 => t('22'), 23 => t('23'), 24 => t('24'),
                25 => t('25'), 26 => t('26'), 27 => t('27'), 28 => t('28'), 29 => t('29'), 30 => t('30'), 31 => t('31')),
            '#description' => t("Thirty-One Days."),
            '#required' => true,
        );

        $form['submitted']['dop']['dop_year'] = array(
            '#type' => 'select',
            '#default_value' => array('pyear' => '年'),
            '#options' => array('pyear' => '年', 1 => t('2013'), 2 => t('2012'), 3 => t('2011'), 4 => t('2010'), 5 => t('2009'), 6 => t('2008'), 7 => t('2007'), 8 => t('2006'),
                9 => t('2005'), 10 => t('2004'), 11 => t('2003'), 12 => t('2002'), 13 => t('2001'), 14 => t('2000'), 15 => t('1999'), 16 => t('1998'), 17 => t('1997'),
                18 => t('1996'), 19 => t('1995'), 20 => t('1994'), 21 => t('1993'), 22 => t('1992'), 23 => t('1991'), 24 => t('1990'), 25 => t('1989'), 26 => t('1988'),
                27 => t('1987'), 28 => t('1986'), 29 => t('1985'), 30 => t('1984'), 31 => t('1983'), 32 => t('1982'), 33 => t('1981'), 34 => t('1980'), 35 => t('1979'), 36 => t('1978'), 37 => t('1977'), 38 => t('1975'),
                39 => t('1974'), 40 => t('1973'), 41 => t('1972'), 42 => t('1971'), 43 => t('1970'), 44 => t('1969'), 45 => t('1968'), 46 => t('1967'), 47 => t('1966'),
                48 => t('1965'), 49 => t('1964'), 50 => t('1963'), 51 => t('1962'), 52 => t('1961'), 53 => t('1960'), 54 => t('1959'), 55 => t('1958'), 56 => t('1957'),
                57 => t('1956'), 58 => t('1955'), 59 => t('1954'), 60 => t('1953'), 61 => t('1952'), 60 => t('1951'), 61 => t('1950'),
            ),
            '#description' => t('Select year.'),
            '#required' => true,
        );

        return $form;
        break;

    /* for vietnamese */
    case 'webform_client_form_71990' :
        $form['submitted']['dobv'] = array(
            '#type' => 'fieldset',
            '#title' => t('Ngày Sinh'),
            '#weight' => 4,
            '#prefix' => '<div class="vietnamese_dob" id="webform_vietnamese_dob">',
            '#suffix' => '</div>',
            '#required' => 'true'
        );

        $form['submitted']['dobv']['dob_monthv'] = array(
            '#type' => 'select',
            '#default_value' => array('month' => 'Tháng'),
            '#options' => array('month' => t('Tháng'),
                1 => t('tháng 1'), 2 => t('tháng 2'), 3 => t('tháng 3'), 4 => t('tháng 4'), 5 => t('tháng 5'), 6 => t('tháng 6'), 7 => t('tháng 7'), 8 => t('tháng 8'), 9 => t('tháng 9'), 10 => t('tháng 10'), 11 => t('tháng 11'), 12 => t('tháng 12'),
            ),
            '#description' => t('Select month.'),
            '#required' => true,
        );

        /* for 31 days */
        $form['submitted']['dobv']['vdob_day_31'] = array(
            '#type' => 'select',
            '#default_value' => array('day' => 'Ngày'),
            '#options' => array('day' => t('Ngày'), 1 => t('1'), 2 => t('2'), 3 => t('3'), 4 => t('4'), 5 => t('5'), 6 => t('6'), 7 => t('7'), 8 => t('8'), 9 => t('9'), 10 => t('10'), 11 => t('11'), 12 => t('12'),
                13 => t('13'), 14 => t('14'), 15 => t('15'), 16 => t('16'), 17 => t('17'), 18 => t('18'), 19 => t('19'), 20 => t('20'), 21 => t('21'), 22 => t('22'), 23 => t('23'), 24 => t('24'),
                25 => t('25'), 26 => t('26'), 27 => t('27'), 28 => t('28'), 29 => t('29'), 30 => t('30'), 31 => t('31')),
            '#description' => t("Thirty-One Days."),
            '#required' => true,
        );

        $form['submitted']['dobv']['dob_yearv'] = array(
            '#type' => 'select',
            '#default_value' => array('year' => 'Năm'),
            '#options' => array('year' => t('Năm'), 1 => t('2013'), 2 => t('2012'), 3 => t('2011'), 4 => t('2010'), 5 => t('2009'), 6 => t('2008'), 7 => t('2007'), 8 => t('2006'),
                9 => t('2005'), 10 => t('2004'), 11 => t('2003'), 12 => t('2002'), 13 => t('2001'), 14 => t('2000'), 15 => t('1999'), 16 => t('1998'), 17 => t('1997'),
                18 => t('1996'), 19 => t('1995'), 20 => t('1994'), 21 => t('1993'), 22 => t('1992'), 23 => t('1991'), 24 => t('1990'), 25 => t('1989'), 26 => t('1988'),
                27 => t('1987'), 28 => t('1986'), 29 => t('1985'), 30 => t('1984'), 31 => t('1983'), 32 => t('1982'), 33 => t('1981'), 34 => t('1980'), 35 => t('1979'), 36 => t('1978'), 37 => t('1977'), 38 => t('1975'),
                39 => t('1974'), 40 => t('1973'), 41 => t('1972'), 42 => t('1971'), 43 => t('1970'), 44 => t('1969'), 45 => t('1968'), 46 => t('1967'), 47 => t('1966'),
                48 => t('1965'), 49 => t('1964'), 50 => t('1963'), 51 => t('1962'), 52 => t('1961'), 53 => t('1960'), 54 => t('1959'), 55 => t('1958'), 56 => t('1957'),
                57 => t('1956'), 58 => t('1955'), 59 => t('1954'), 60 => t('1953'), 61 => t('1952'), 60 => t('1951'), 61 => t('1950'),
            ),
            '#description' => t('Select year.'),
            '#required' => true,
        );

        /* Add dropdown for Date Of Problem Field */

        $form['submitted']['dopv'] = array(
            '#type' => 'fieldset',
            '#title' => t('Ngày xảy ra vấn đề'),
            '#weight' => 11,
            '#prefix' => '<div class="vietnamese_dop">',
            '#suffix' => '</div>',
        );

        $form['submitted']['dopv']['dop_monthv'] = array(
            '#type' => 'select',
            '#default_value' => array('month' => 'Tháng'),
            '#options' => array('month' => t('Tháng'),
                1 => t('tháng 1'), 2 => t('tháng 2'), 3 => t('tháng 3'), 4 => t('tháng 4'), 5 => t('tháng 5'), 6 => t('tháng 6'), 7 => t('tháng 7'), 8 => t('tháng 8'), 9 => t('tháng 9'), 10 => t('tháng 10'), 11 => t('tháng 11'), 12 => t('tháng 12'),
            ),
            '#description' => t('Select month.'),
            '#required' => true,
        );

        /* for 31 days */
        $form['submitted']['dopv']['vdop_day_31'] = array(
            '#type' => 'select',
            '#default_value' => array('day' => 'Ngày'),
            '#options' => array('day' => t('Ngày'), 1 => t('1'), 2 => t('2'), 3 => t('3'), 4 => t('4'), 5 => t('5'), 6 => t('6'), 7 => t('7'), 8 => t('8'), 9 => t('9'), 10 => t('10'), 11 => t('11'), 12 => t('12'),
                13 => t('13'), 14 => t('14'), 15 => t('15'), 16 => t('16'), 17 => t('17'), 18 => t('18'), 19 => t('19'), 20 => t('20'), 21 => t('21'), 22 => t('22'), 23 => t('23'), 24 => t('24'),
                25 => t('25'), 26 => t('26'), 27 => t('27'), 28 => t('28'), 29 => t('29'), 30 => t('30'), 31 => t('31')),
            '#description' => t("Thirty-One Days."),
            '#required' => true,
        );

        $form['submitted']['dopv']['dop_yearv'] = array(
            '#type' => 'select',
            '#default_value' => array('year' => 'Năm'),
            '#options' => array('year' => t('Năm'), 1 => t('2013'), 2 => t('2012'), 3 => t('2011'), 4 => t('2010'), 5 => t('2009'), 6 => t('2008'), 7 => t('2007'), 8 => t('2006'),
                9 => t('2005'), 10 => t('2004'), 11 => t('2003'), 12 => t('2002'), 13 => t('2001'), 14 => t('2000'), 15 => t('1999'), 16 => t('1998'), 17 => t('1997'),
                18 => t('1996'), 19 => t('1995'), 20 => t('1994'), 21 => t('1993'), 22 => t('1992'), 23 => t('1991'), 24 => t('1990'), 25 => t('1989'), 26 => t('1988'),
                27 => t('1987'), 28 => t('1986'), 29 => t('1985'), 30 => t('1984'), 31 => t('1983'), 32 => t('1982'), 33 => t('1981'), 34 => t('1980'), 35 => t('1979'), 36 => t('1978'), 37 => t('1977'), 38 => t('1975'),
                39 => t('1974'), 40 => t('1973'), 41 => t('1972'), 42 => t('1971'), 43 => t('1970'), 44 => t('1969'), 45 => t('1968'), 46 => t('1967'), 47 => t('1966'),
                48 => t('1965'), 49 => t('1964'), 50 => t('1963'), 51 => t('1962'), 52 => t('1961'), 53 => t('1960'), 54 => t('1959'), 55 => t('1958'), 56 => t('1957'),
                57 => t('1956'), 58 => t('1955'), 59 => t('1954'), 60 => t('1953'), 61 => t('1952'), 60 => t('1951'), 61 => t('1950'),
            ),
            '#description' => t('Select year.'),
            '#required' => true,
        );

        return $form;
        break;
    /* for spanish */
    case 'webform_client_form_71991' :
        $form['submitted']['dobs'] = array(
            '#type' => 'fieldset',
            '#title' => t('Fecha de nacimiento'),
            '#weight' => 4,
            '#prefix' => '<div class="spanish_dob" id="webform_spanish_dob">',
            '#suffix' => '</div>',
            '#required' => 'true'
        );

        $form['submitted']['dobs']['dob_months'] = array(
            '#type' => 'select',
            '#default_value' => array('month' => 'Mes'),
            '#options' => array('month' => t('Mes'),
                1 => t('enero'), 2 => t('febrero'), 3 => t('marzo'), 4 => t('abril'), 5 => t('mayo'), 6 => t('junio'), 7 => t('julio'), 8 => t('agosto'), 9 => t('septiembre'), 10 => t('octubre'), 11 => t('noviembre'), 12 => t('diciembre'),
            ),
            '#description' => t('Select month.'),
            '#required' => true,
        );

        /* for 31 days */
        $form['submitted']['dobs']['sdob_day_31'] = array(
            '#type' => 'select',
            '#default_value' => array('day' => 'Día'),
            '#options' => array('day' => t('Día'), 1 => t('1'), 2 => t('2'), 3 => t('3'), 4 => t('4'), 5 => t('5'), 6 => t('6'), 7 => t('7'), 8 => t('8'), 9 => t('9'), 10 => t('10'), 11 => t('11'), 12 => t('12'),
                13 => t('13'), 14 => t('14'), 15 => t('15'), 16 => t('16'), 17 => t('17'), 18 => t('18'), 19 => t('19'), 20 => t('20'), 21 => t('21'), 22 => t('22'), 23 => t('23'), 24 => t('24'),
                25 => t('25'), 26 => t('26'), 27 => t('27'), 28 => t('28'), 29 => t('29'), 30 => t('30'), 31 => t('31')),
            '#description' => t("Thirty-One Days."),
            '#required' => true,
        );

        $form['submitted']['dobs']['dob_years'] = array(
            '#type' => 'select',
            '#default_value' => array('year' => 'Año'),
            '#options' => array('year' => t('Año'), 1 => t('2013'), 2 => t('2012'), 3 => t('2011'), 4 => t('2010'), 5 => t('2009'), 6 => t('2008'), 7 => t('2007'), 8 => t('2006'),
                9 => t('2005'), 10 => t('2004'), 11 => t('2003'), 12 => t('2002'), 13 => t('2001'), 14 => t('2000'), 15 => t('1999'), 16 => t('1998'), 17 => t('1997'),
                18 => t('1996'), 19 => t('1995'), 20 => t('1994'), 21 => t('1993'), 22 => t('1992'), 23 => t('1991'), 24 => t('1990'), 25 => t('1989'), 26 => t('1988'),
                27 => t('1987'), 28 => t('1986'), 29 => t('1985'), 30 => t('1984'), 31 => t('1983'), 32 => t('1982'), 33 => t('1981'), 34 => t('1980'), 35 => t('1979'), 36 => t('1978'), 37 => t('1977'), 38 => t('1975'),
                39 => t('1974'), 40 => t('1973'), 41 => t('1972'), 42 => t('1971'), 43 => t('1970'), 44 => t('1969'), 45 => t('1968'), 46 => t('1967'), 47 => t('1966'),
                48 => t('1965'), 49 => t('1964'), 50 => t('1963'), 51 => t('1962'), 52 => t('1961'), 53 => t('1960'), 54 => t('1959'), 55 => t('1958'), 56 => t('1957'),
                57 => t('1956'), 58 => t('1955'), 59 => t('1954'), 60 => t('1953'), 61 => t('1952'), 60 => t('1951'), 61 => t('1950'),
            ),
            '#description' => t('Select year.'),
            '#required' => true,
        );

        /* Add dropdown for Date Of Problem Field */

        $form['submitted']['dops'] = array(
            '#type' => 'fieldset',
            '#title' => t('Fecha del problema'),
            '#weight' => 11,
            '#prefix' => '<div class="spanish_dop">',
            '#suffix' => '</div>',
        );

        $form['submitted']['dops']['dop_months'] = array(
            '#type' => 'select',
            '#default_value' => array('month' => 'Mes'),
            '#options' => array('month' => t('Mes'),
                1 => t('enero'), 2 => t('febrero'), 3 => t('marzo'), 4 => t('abril'), 5 => t('mayo'), 6 => t('junio'), 7 => t('julio'), 8 => t('agosto'), 9 => t('septiembre'), 10 => t('octubre'), 11 => t('noviembre'), 12 => t('diciembre'),
            ),
            '#description' => t('Select month.'),
            '#required' => true,
        );

        /* for 31 days */
        $form['submitted']['dops']['sdop_day_31'] = array(
            '#type' => 'select',
            '#default_value' => array('day' => 'Día'),
            '#options' => array('day' => t('Día'), 1 => t('1'), 2 => t('2'), 3 => t('3'), 4 => t('4'), 5 => t('5'), 6 => t('6'), 7 => t('7'), 8 => t('8'), 9 => t('9'), 10 => t('10'), 11 => t('11'), 12 => t('12'),
                13 => t('13'), 14 => t('14'), 15 => t('15'), 16 => t('16'), 17 => t('17'), 18 => t('18'), 19 => t('19'), 20 => t('20'), 21 => t('21'), 22 => t('22'), 23 => t('23'), 24 => t('24'),
                25 => t('25'), 26 => t('26'), 27 => t('27'), 28 => t('28'), 29 => t('29'), 30 => t('30'), 31 => t('31')),
            '#description' => t("Thirty-One Days."),
            '#required' => true,
        );

        $form['submitted']['dops']['dop_years'] = array(
            '#type' => 'select',
            '#default_value' => array('year' => 'Año'),
            '#options' => array('year' => t('Año'), 1 => t('2013'), 2 => t('2012'), 3 => t('2011'), 4 => t('2010'), 5 => t('2009'), 6 => t('2008'), 7 => t('2007'), 8 => t('2006'),
                9 => t('2005'), 10 => t('2004'), 11 => t('2003'), 12 => t('2002'), 13 => t('2001'), 14 => t('2000'), 15 => t('1999'), 16 => t('1998'), 17 => t('1997'),
                18 => t('1996'), 19 => t('1995'), 20 => t('1994'), 21 => t('1993'), 22 => t('1992'), 23 => t('1991'), 24 => t('1990'), 25 => t('1989'), 26 => t('1988'),
                27 => t('1987'), 28 => t('1986'), 29 => t('1985'), 30 => t('1984'), 31 => t('1983'), 32 => t('1982'), 33 => t('1981'), 34 => t('1980'), 35 => t('1979'), 36 => t('1978'), 37 => t('1977'), 38 => t('1975'),
                39 => t('1974'), 40 => t('1973'), 41 => t('1972'), 42 => t('1971'), 43 => t('1970'), 44 => t('1969'), 45 => t('1968'), 46 => t('1967'), 47 => t('1966'),
                48 => t('1965'), 49 => t('1964'), 50 => t('1963'), 51 => t('1962'), 52 => t('1961'), 53 => t('1960'), 54 => t('1959'), 55 => t('1958'), 56 => t('1957'),
                57 => t('1956'), 58 => t('1955'), 59 => t('1954'), 60 => t('1953'), 61 => t('1952'), 60 => t('1951'), 61 => t('1950'),
            ),
            '#description' => t('Select year.'),
            '#required' => true,
        );

        return $form;
        break;
 }
}

```

# Answer
> 2 votes
This is because the webform module doesn't know anything about your fields so it doesn't have anywhere in the database to save the values to.

For the webform module to save the fields the easiest way is to create the fields via the webform UI, then use form alter to change the widget, or do other things to make the fields like you need them to be.

---
Tags: webforms
---


# Question
Title: How do I set up multiple sites with one database or multisite Apache configuration?
I have a problem in multisite with Drupal 7.26. The name of the site is multisite, and the IP is 192.168.1.99.

I created a folder that hosts a new site (/var/www/multisite/sites/site1), copied the settings.php file into the site1 folder; the `127.0.0.1 site1` line is present in the hosts file.

This is the content of /etc/apache2/sites-available/site1.

```
<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  ServerName site1
  DocumentRoot /var/www/multisite/sites/site1

  <Directory />
    Options FollowSymLinks
    AllowOverride All
  </Directory>
</VirtualHost>

```

I executed the following commands.

```
sudo a2ensite site1
sudo /etc/init.d/apache2 reload

```

If I use 192.168.1.99/multisite/, it works; if I use 192.168.1.99/site1, I get the following error:

> The requested URL /site1 was not found on this server. Apache/2.2.22
> (Ubuntu) Server at 192.168.1.99 Port 80

What did I do wrong?

should i add any **redirect base** code in .htaccess file?

```
    Solution: Give Symbolic link form mulitsite to site2
    Executed that command line
    ln -s /var/www/multisite /var/www/site2

    Rename example.sites.php to sites.php

    $sites['192.168.1.99.site1'] = 'site1';

    put this line in sites.php

```

I got a result . Thanks for post the answers this questions

Reference URL:

```
  https://drupal.org/node/2622
  https://drupal.org/node/43816/

```

# Answer
> 0 votes
https://drupal.stackexchange.com/questions/104319/give-write-permission-to-symbloic-link-folder-in-centos

Any way I find out the solution . I gave write permission to Symbolic link folder and root folder

```
  lrwxrwxrwx  1 root       root        44 Feb 19 04:39 mmultisite01 -> /var/www/vhosts/vyhub.com/httpdocs/mmultisite

 mmultisite01 is in root .  So that got errror was

 Forbidden
 You do not have permission to access this document.

 That root is changed to

 chown -h vydevplesk:psacln /var/www/vhosts/vyhub.com/httpdocs/mmultisite01

 ls -l

  lrwxrwxrwx  1 vydevplesk psacln      45 Feb 26 05:20 mmultisite01 -> /var/www/vhosts/vyhub.com/httpdocs/mmultisite

  This link is help to me

```

https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link

# Answer
> 3 votes
The new site vhost should be pointing to the drupal root installation where the index file lives and the entry point for all your sites, not to the site1 folder. "DocumentRoot /var/www/multisite" this should be the same for all your sites.

With multi-site a approach you can shared modules between sites (those in all folder), have different modules per site, you can have different databases per site and share tables between them.

Your drupal sites are going to share the same code base, One drupal core for everyone.

This can be useful https://drupal.org/documentation/install/multi-site

# Answer
> 3 votes
I think you have a whole bunch of things going wrong here.

You need to turn on name based virtual hosts in your httpd.conf:

```
NameVirtualHost *:80

```

Then you need to configure your virtual host to respond to these *names* and map them to the base of your installation

```
<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  ServerName site1
  ServerAlias site2, site3, site4
  DocumentRoot /var/www/multisite

  <Directory /var/www/multisite>
    Options FollowSymLinks
    AllowOverride All
  </Directory>
</VirtualHost>

```

Don't forget to restart apache.

Now, you need to configure your DNS or /etc hosts to map these hostnames to an IP address

```
192.168.1.99 site1 site2 site3 site4

```

Now you are ready for multisite. Edit the various settings files, and keep in mind that

* `http://site1` will map to site/site1/settings.php
* `http://site2` will map to site/site2/settings.php
* `http://site3` will map to site/site3/settings.php
* `http://site4` will map to site/site4/settings.php

Then you need to browse by the server name and not IP. You may also want to real about multisite aliasing.

All of that said, avoid multisite. It causes more headaches that it is worth.

# Answer
> 0 votes
```
<VirtualHost *:80>

 ServerAdmin webmaster@localhost
  ServerName site1
  DocumentRoot /var/www/multisite        //change this to your site root folder

  <Directory />
    Options FollowSymLinks
    AllowOverride All
  </Directory>
</VirtualHost>

```

Try this.

You may also need to configure your host file if you need aliasing.

---
Tags: multi-sites
---


# Question
Title: Automatically group the sub menu items in drupal 7
My website contains project for following categories-

1. C language
2. Java language
3. Shell script

I have a custom content type "project", which has these fields as radio button. I have a menu item in main menu called project, which has above three categories as sub menu item. I want whenever I add any "C language" project, it should automatically attach as a sub menu item of "C language".

How to achieve it?

# Answer
> 1 votes
You could make links list attachment with views for each taxonomy term and then add them in theme\_menu\_link function if the link in variables matches. Note that requires customization in template.php

---
Tags: routes
---


# Question
Title: How to make correct View for tasks for each user?
I have taxonomy vocabulary with departments. Different users have task's nodes.

I need View like this:

Department1 Task5\_ForUser10
Department2
Department3
Department4 Task7\_ForUser10
Department5

I've created View with taxonomy terms, Relationship with task's node and with Contextual filter "User ID from logged in user", but I see now only short variant:

Department1 Task5\_ForUser10
Department4 Task7\_ForUser10

How can I get View with full department list and tasks for each user?

# Answer
You can solve above problem using Views Field View module..

Project page says

> This module allows you to embed a view as a field in a view. A new field handler is made available, so this can also be used in area (header/footer/empty) handlers as well as rows.

* Create a new view which accepts term id as argument and lists nodes related to that term
* Add Contextual Filter Author ID - Provide default value
* In your view add term id and select Exclude option
* In your view add above view as a field and read term id using token in settings.

See the result below
> 0 votes

---
Tags: 7, views
---


title: Editor for blog

text:
# Question
Title: Editor for blog
I am new to Drupal so please excuse my lack of knowledge on this. I have a blog installed and it looks good. I would like to give the users that are adding to the blog a wysiwyg editor to enter the blog. I installed the CKEditor but that didnt seem to make any difference. Can anyone please help?

# Answer
> 1 votes
As you have mentioned "that didn't seem to make any difference". I'm making an assume that the installation is not 100% correct / in-complete. I would request you watch these below mentioned screencasts and setup CKEditor correctly. I bet you will notice the difference after finishing the configuration.

---
Tags: views
---


title: login programmatically not work

text:
# Question
Title: login programmatically not work
according to this I wrote below code to create temp user and login , , user create but it not logged in. where is problem?

```
   $user_info = array(
  'name' => 'temp-payment-'.rand(1,999),
  'pass' => user_password(),
  'mail' => 'no@no.com',
  'init' => 'temp-user-'.rand(1,999),
  'status' => 1,
  'roles' => array(DRUPAL_AUTHENTICATED_RID => TRUE),
                    'access' => time(),
                    );
  $user = user_save('',$user_info);

  if($user) {
   $GLOBALS['user'] = $user;
    drupal_save_session(TRUE);
    ym($user);
  }
  drupal_goto('/user');

```

# Answer
> 4 votes
Solution is

```
 $form_state['uid'] = $user->uid;
 user_login_submit(array(), $form_state);

```

and final code :

```
$user_info = array(
  'name' => 'temp-payment-'.rand(1,999),
  'pass' => user_password(),
  'mail' => 'no@no.com',
  'init' => 'temp-user-'.rand(1,999),
  'status' => 1,
  'roles' => array(DRUPAL_AUTHENTICATED_RID => TRUE),
                    'access' => time(),
                    );
  $user = user_save('',$user_info);
//drupal_save_session(FALSE);
//$loggedin = user_authenticate($user->name, $user->pass);
//ym($loggedin);
$form_state['uid'] = $user->uid;
 user_login_submit(array(), $form_state);
//drupal_save_session(FALSE);
$GLOBALS['user'] = $user;
drupal_save_session(TRUE);
//drupal_goto('/user');

```

**hope be useful for another users,**.

**This code generate and login to it programmatically**

---
Tags: users
---


# Question
Title: Is custom coding faster than Rules when reacting on user creation?
I'm granting an avatar to the users on my website, based on their gender (cf. this answer). I've been able to achieve this both programatically and with 3 Rules.

This is my custom module:

```
function custom_user_presave (&$edit, $account) {
    $tid = $edit['field_geslacht']['und'][0]['target_id'];
    if ($account->is_new OR !isset ($account->roles[3])) {
        $avatar = taxonomy_term_load($tid);
        }
        else {
            $avatar = taxonomy_term_load(8);
        }
    $edit['field_avatar']['und'][0]['fid'] = $avatar->field_avatar['und'][0]['fid'];
    $edit['field_avatar']['und'][0]['width'] = $avatar->field_avatar['und'][0]['width'];
    $edit['field_avatar']['und'][0]['height'] = $avatar->field_avatar['und'][0]['height'];
    $edit['field_avatar']['und'][0]['alt'] = $avatar->field_avatar['und'][0]['alt'];
    $edit['field_avatar']['und'][0]['title'] = $avatar->field_avatar['und'][0]['title'];
}

```

This is one of my exported rules (the second only differs in the action part and the third one checks whether the user has a certain role):

```
{ "rules_avatar" : {
    "LABEL" : "Avatar",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "avatar" ],
    "REQUIRES" : [ "rules" ],
    "ON" : { "user_insert" : [], "user_update" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "account" ], "field" : "field_geslacht" } },
      { "data_is" : { "data" : [ "account:field-geslacht" ], "value" : "Man" } }
    ],
    "DO" : [
      { "data_set" : { "data" : [ "account:field-avatar:file" ], "value" : "35" } }
    ]
  }
}

```

I'm wondering which method is the fastest/most efficient. Can you help me?

# Answer
I wouldn't focus too much on speed in situations like this because it's extensibility you will care about as the site grows in function. While your custom code is probably "faster" it's not the measure you should be deciding by since it'll be nanoseconds you're talking about and any good caching strategy will nullify most of that concern.

But to answer your question, your code would likely be faster especially if you're not defining as many hooks as the Rules module.

However, I'd advise using rules for the following reasons.

* Rules are exportable
* Rules are integrated with all the "big" modules out there.
* Never program something you can borrow. :)

Hope this helps.
> 0 votes

---
Tags: 7, rules
---


# Question
Title: Auto assign organic group to a content type
I'm trying to assign the group audience to a content type at creation instant. The first thing I have done is to disable the group audience field. So I have implemented the hook\_form\_alter and done this:

```
$form['og_group_ref']['#access']= false;

```

Then, I have implemented the hook\_node\_insert and here is where I have tried to assign the group. In my use case, users can only have one group. That's my code:

```
/**
 * Implements hook_node_insert
 */
function og_autoassign_node_insert($node){
  //Get the type
  $type = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type);

  if ($type == 'content_type1' || $type == 'content_type2'){
    // Get the user
    $user = user_load($node->uid);

    // Load the current user's group
    //$groups = og_get_entity_groups('user', $user);
    $groups = og_get_groups_by_user($user);

    // Load the GID
    $group_id;
    foreach(array_keys($groups['node']) as $id){
        $group_id = $id;
    }

    $values = array(
        'entity_type' => 'node',
        'entity' => $node,
        'field_name' => 'og_group_ref',
        'state' => OG_STATE_ACTIVE
    );
    og_group('node', $group_id, $values);

    dpm($node);
  }
}

```

When I print the node with dpm, I can not see the organic group associated. What I'm doing wrong? Can anyone help me?

Thanks a lot

**UPDATE (I can't answer myself because I have less than 10 in reputation)**

Well, I found one solution. Instead of implementing the hook\_node\_insert, I did that in my hook\_form\_alter:

```
function my_module_form_alter(&$form, &$form_state, $form_id){
...
// Load the current user's group
$groups = og_get_groups_by_user();

$form['og_group_ref']['und'][0]['default']['#default_value'] = $groups['node'];
}

```

And that set the field "Audience Group" with the user's group.

# Answer
I just ran into this problem with hooks. It's being saved but you won't see this in node\_insert due to the caching system of nodes in Drupal. Add this before your dpm code and you'll see the results immediately.

```
entity_get_controller('node')->resetCache(array($node->nid));

```

I'm so happy I can stop someone else from banging their head on the wall like I did. Ha.
> 0 votes

---
Tags: organic-groups
---


# Question
Title: OpenLayers Locator proximity search(content) and map display within tab
I got correct result when i based on search with mile and distance.

Output displayed openlayer content views and map .

I need to displayed result like tab view that List and Map both are tab titles

```
 Click list -> displayed  ** Content **
 Click Map  -> displayed  ** Map **

```

# Answer
Anyway I Find Out Solution. Create a two pages like Page 1 and Page 2.

Setting Menu Tab to both pages

```
1. Menu Tab: List in PAGE SETTINGS
2. Menu Tab: Map in PAGE SETTINGS

```

Change CSS setting in view-filter.
> 0 votes

---
Tags: javascript
---


# Question
Title: Drupal 7 and views: Get results from two content types and their own individual terms
Drupal 7 and views

My issue might be hard to explain but here goes:

**What I want:**

show all nodes from two content types, that is tagged with their own individual terms.

**What I have done so far:**

I created a view that should display nodes from content type"names", and content type "name\_auto" that is tagged with "job" the two content types, has its own term but the name is the same. (so job and job, could be different, like: bike and carpet)

My filter looks like this: is published AND content type is names, name\_auto AND term is job OR term is job

**What the issue is now:**

the view give me zero results, but, if I remove one of the terms in filter, I get results but only from one of the content types.

I need to get results from both tagged with job from names, and job from names\_auto.

**Issue simplyfed (bottomline):**

This scenario could just as well be content type shoe, tagged with bike, and content type house, tagged with carpet. and then I need all nodes of bike and house, tagged with their own terms.

**What i think is wrong:**

I think the view looks for the term in both content types, and then when it only find it in the one, it dont display any of them at all. But why does it do that? I have tried to change the order of the filters and nothing works.

I know it would be easier if you could just see the view, but its on a local site, if the view query, or an export dump would help, please let me know :)

I hope I have explained this well and that you understand my problem.

# Answer
> 0 votes
Your problem is that your query is using INNER JOINs but you need to be using LEFT JOINS.

As you found in the thread I linked to the easiest solution is to edit your filter criteria and check the reduce duplicates checkbox.

---
Tags: views
---


# Question
Title: How to remove a stylesheet provided by a contrib module?
The new version of Field Group has a new stylesheet included by default that makes my theme look hideous. Deleting the stylesheet from the module's folder fixes the problem but then I will have to delete it again when Field Group is updated again.

What's the right way (= not modifying the module's code directly) to do this?

# Answer
> 10 votes
I think using `hook_css_alter()` in a custom module/theme would be the easiest solution:

```
function MYMODULE_css_alter(&$css) {
  // Get the path to the module
  $path = drupal_get_path('module', 'field_group');

  // Remove the unneeded files from the css array
  unset($css[$path . '/field_group.css']);
  unset($css[$path . '/field_group.field_ui.css']);
}

```

There are also other CSS files in the Field Group module:

* horizontal-tabs/horizontal-tabs.css
* multipage/multipage.css

In case you're look to remove absolutely all the CSS that Field Group introduces.

# Answer
> 7 votes
You can also do this in your theme's `.info` file. Check out the documentation from drupal.org.

If you want to remove css, just add a line like this in your .info file:

`stylesheets[all][] = system-menus.css`

If you have a stylesheet by that name in your theme, then that will replace the one provided by the module. If you don't have that stylesheet in your theme, then Drupal will just omit that stylesheet altogether.

Looks like there was a bug with this method for a while, but it has seemingly been fixed.

---
Tags: 7, theming
---


title: if isset, is there a better way?

text:
# Question
Title: if isset, is there a better way?
Currently I'm retrieving values from entityform\_wrapper and checking if the field exists (fields aren't required and fail if don't exist)

Is there a better way than going through each field like this?

```
if (isset()) {
   $edu_completed = $entityform_wrapper->field_education_completed->value();
}
if (isset()) {
   $edu_hs_name = $entityform_wrapper->field_high_school_info->field_edu_hs_name->value();
}
if (isset()) {
   $edu_hs_city = $entityform_wrapper->field_high_school_info->field_edu_hs_city->value();
}

```

# Answer
I use a function I've written called ifset for this purpose:

```
function ifset(&$var, $prefix='', $suffix='', $else = '') {
    return isset($var) && $var ? $prefix.$var.$suffix : $else;
}

```

It can simply be used like:

```
$foo = 'test';
echo ifset($foo); // produces test
echo ifset($bar); // produces an empty string

```

Or you can supply a suffix, prefix or else values:

```
$foo = 'test';
echo ifset($foo, 'before ', ' after', 'foobar'); // produces before test after
echo ifset($bar, 'before ', ' after', 'foobar'); // produces foobar

```

So, in your instance you could write:

```
$edu_completed = ifset($entityform_wrapper->field_education_completed->value());

```

This is slightly different to your code a `$edu_completed` will be an empty string instead of not being set at all.
> 0 votes

---
Tags: forms, entities
---


# Question
Title: Extract hex colors from image field for taxonomy vocabulary
For a project in D7. I need to extract all the colors from an image field. I am looking for a module or solution to save the colors (ie Taxonomy term). So I can search on them.

I have found a solution for D6: https://drupal.org/project/visual\_search

Is there an alternative for D7?

# Answer
If your happy to use a custom module then something a simple as this would do the trick:

```
$colours = db_query("SELECT field_my_colour_field_value FROM field_data_field_my_colour_field")->fetchCol();

```
> 0 votes

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


title: Contextual filter in views

text:
# Question
Title: Contextual filter in views
I have a form on my site. Each time a user submits the form they are directed to a confirmation page like this;

> eform/help-request/confirm?entityform\_id=1

I want to create a view that has a contextual filter that picks the last form submitted by the user and displays the fields from that form only.

I have a view that shows the field content from the form as it was submitted by the user but i cannot get the view to only display the *latest* form submission from the user... As i have it my view is displaying *all* the forms the user has ever submitted ... which i don't want.

Any help appreciated. I know I am close (ish)

# Answer
> 0 votes
Sort the view by created desc.

Then limit the view to only show 1 row.

The remaining item will be the last form submitted.

---
Tags: views
---


# Question
Title: Accessibility : Broken Skip Link Error on "Skeleton" Theme
I installed the "Skeleton" theme and found it has a "Broken Skip Link" by using "wave.webaim.org". How can I find and fix where is this "Broken Skip Link"?

You can find this Skeleton demo at "http://demo.drupalizing.com/skeleton"

and the "Broken Skip Link" error at "http://wave.webaim.org/report#/http://demo.drupalizing.com/skeleton/"

# Answer
> 1 votes
I use the Skeleton theme. it has:

```
  <div id="skip-link">
    <a href="#main-content" class="element-invisible element-focusable">Skip to main content</a>
  </div>

```

But it has no anchor tag for `main-content`. You should file an issue for the Project on Drupal.org.

You can fix this by supplying a patch to the theme project that alters `html.tpl.php` or `page.tpl.php` to include an `<a name="main-content"></a>` at the top of the content area. You may do this in your own subtheme as well of course simply by modifying the necessary TPL file.

**EDIT**: Issue created at Drupal.org https://drupal.org/node/2211661

# Answer
> 0 votes
Have a look at https://drupal.org/comment/8551121#comment-8551121 for an explanation and a patch file.

---
Tags: theming, navigation
---


title: Disable the comment path site-wide

text:
# Question
Title: Disable the comment path site-wide
Is it possible somehow to completely disable the `/comment/` path on a Drupal 6 site?

Our site really doesn't need comments and despite having disabled comments on all content types and removing any comment hooks in our theme (someone else developed the site with comments in mind, but we have found that we don't need them, users don't use them, and they only bring in spam to clean up) we still get pretty regular stream of spam hitting the `/comment/reply/[some_content_id]` paths and while we have a Mollom taking care of the spam for us, I am wondering if its possible to turn those bots away before they have a chance to leave their droppings.

# Answer
> 1 votes
It's been a while now since I've used D6 but can't you just disable the comments module?

Alternatively what about just blocking /comment with htaccess (SO thread on the subject)?

---
Tags: 6, comments, advertising
---


# Question
Title: ob_start() error running Devel on Search API + Search views page
How can I run Devel on search pages? I keep getting an ob\_start() error. How can I run debug on these search pages.

The error is:

Fatal error: Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0

# Answer
> 0 votes
I just ran my Devel debug on blocks and that worked.

---
Tags: 7, search, debugging
---


title: Black bars in media-vimeo plugin

text:
# Question
Title: Black bars in media-vimeo plugin
Hi is it possible to remove black bars in media-vimeo plugin? There is line in player.css style which controls it, but I can't edit it, because this file is loaded inside of iframe.

# Answer
> 0 votes
No this is a video scaling and proportion issue for the player (or your embed code size). If Vimeo allows you to not show these black bars (you'd have to goto the Vimeo site and compare many many videos) ... you would need to figure out the correct aspect ratio to record you're video at so that these bars are not needed in the embed width of the player.

# Answer
> 0 votes
You need to edit the css on the page that is inside the iframe. If you change the dimensions of the box that surrounds the player you should be able to get the black bars to dissapear. Have a play with firebug.

---
Tags: media
---


# Question
Title: adding meta info to contents and filter them
the target is to be add a meta field for drupal custom content type. that meta tag should be selectable by user when adding a new article .

the meta field is meant for language . (e.g. English / Urdu). the content types should show which belong to the specific meta tag. e.g. if user selects English then the articles marked with english meta tag show up only.

any help appreciated

# Answer
Have you looked at the Internationalization module?

> This is a collection of modules to extend Drupal core multilingual capabilities and be able to build real life multilingual sites. Some features:
>
> * Taxonomy translation (both, per language terms and translatable terms)
> * Multilingual variables Multilingual blocks (control visibility per language and translate title and content)
> * Language selection (when you switch the site language you'll see only the content for that language)
> * Requires Variable module 2.x (Drupal 7)
> * Read a complete feature overview in the Internationalization handbook: Building multilingual sites .

If you dont want a full `i18n` site you can always just use a custom field or Taxonomy term and Views to build page lists of content tagged with that language.
> 0 votes

---
Tags: entities, meta-tags
---


# Question
Title: Drupal 6 Can I use subdomain, for the dev instance of a site and use multiple site configs
How do subdomains work in relationship to multiple sites? This seems to be danced around in the documentation that is out there.

more specifically. If I have...

primarydomain.com as my site in the site folder.... and point the domain dev.primarydomain.com at the drupal install without a dev.primarydomain.com folder will dev load the primarydomain.com or the default site?

The key behind this is I am trying to setup a 3 tier environment for drupal (dev, test, prod) and want to have as few transformation processes to move things up the tier. So I am hoping I can simply put dev infront of the domain and everything will work.

Also if it does work can I do the same thing on a sub-subdomain? dev.blog.primarydomain.com?

Thank you for your help I am relatively new to drupal and working on putting an existing site into a dev environment to learn more safely.

# Answer
Short answer is: if example.com exists in the sites folder and a settings.php file is inside it, that file will be selected to serve any request directed to \*.example.com.

Long answer is: let's say an url such as "an.example.com/something" is requested and such request reaches Drupal, here is what happens:

1. Does a settings file exist in a folder named an.example.com.something (inside the sites/ folder)?
2. Does a settings file exist in a folder named example.com.something?
3. Does a settings file exist in a folder named com.something?
4. Does a settings file exist in a folder named an.example.com?
5. Does a settings file exist in a folder named example.com?
6. Does a settings file exist in a folder named com?
7. Serve the default website.

If at any point of the process the answer to the question is yes, then that file is selected as the settings file. Of course it will work with more complex subdomains and also more complex paths, as well as port numbers. Have a look at the official Drupal documentation on multi-site and at the conf\_path() function for more details.
> 1 votes

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


# Question
Title: How to find all views and panels that use a certain field
I want to delete a field but I am not sure if there is still a view or a panel somewhere on the site that is still using it. So I want to know if there is any possibility to find all views and panels that use a certain field?

# Answer
In D7, you can see this for views at least at
/admin/reports/fields/views-fields (Admin -\> Reports -\> Field list -\> Used in views)

(Similarly for content types it is at
/admin/reports/fields/ (Admin -\> Reports -\> Field list)

Don't know about panels though.
> 2 votes

# Answer
This module may help you Field Tools

It will allow you to see an overview of fields with links to edit single instances, and all instances at once.
> -1 votes

---
Tags: views, entities, panels
---


# Question
Title: Share and update the structure (content types, vocabularies/tags, views, rules, …) for several sites
I want to start a Drupal 7 site, and it’s likely that in the future I need to run several other sites that should share the same modules, theme, configuration, content types, vocabularies and tags, views, rules, …. Apart from created nodes and things like the site name, they should be 100% copies, i.e., all changes should be applied to all current as well as all future sites.

It doesn’t matter if the userbase is shared or not. If it matters, all sites share the same second-level domain, i.e., every site has a subdomain.

As I start with only one site, I could make all changes to the structure (e.g., to node types or tags) right at this place. But as soon as there are two sites, I don’t want to have to replicate all changes for all sites.

How could I achieve this?

As far as I understand, the **multi-site** functionality would help with modules, but not with configuration or content types or vocabularies/tags, correct?

Should I create a custom **distribution**? Whenever I want to change something, I can change it in the distribution first and then automagically update it on all sites (without losing the already created content)?

Or should I use **one site** and, somehow (how?), divide the content into areas/sections so that it only appears on specific sub domains?

Or is there another way?

# Answer
We use the domain access module, https://drupal.org/project/domain

Everything is or can be shared on the multiple sites ... we choose to have different themes for each domain and we only have a few nodes that are common to multiple sites, most of our nodes are only on one site, but the content types and taxonomies and blocks and views are shared.

There are some current domain views filters that allow exactly the same view to be used on multiple sites but show different content on each.

It is working really well for us, our only issues are that

* There are some reports that combine all domains when we would like to have them separate (e.g. ubercart)
* Users have to login to each site separately
* All relative path links are rewritten to the correct domain automatically but if someone for some reason requests a path on the wrong domain they are not redirected and they see an access denied message.
> 1 votes

# Answer
> As far as I understand, the multi-site functionality would help with modules, but not with configuration or content types or vocabularies/tags, correct?

Correct.

> Should I create a custom distribution?

You certainly could of course, but I would think a distribution as a later step to deliver your solution to a broader audience. Some more insight into Distributions: https://drupal.org/node/1089736#distributions-vs-installation-profiles

I would first try to see how much the Features module can help. You can use it to pack all relevant entity configurations in a module which ou can then reuse in other sites.
> 0 votes

---
Tags: 7, multi-sites, distributions, subsites
---


# Question
Title: How to conditionally display some things in the message text created by the Message module?
I am using the Message module to record some activity.

I have a Rule generating a Message. The Message Type has a couple of fields, and I am setting them in the rule. That part all works great. I can verify the contents of each of those message fields.

Now what I'm trying to do is to conditionally display some things in the message text. I have a couple of Message Text rows and they all display what I expect them to. But for one of these, I want only want to display something if one of the tokens matches a condition.

I have selected the PHP Code filter type on that particular Message Text box, but I just don't know to actually evaluate the field values of the current message. I've tried t() and token\_replace() and I just am not getting it.

So here is a simple question for this problem I'm having. Say I have a text field on this message type called field\_foo. And I want the message text to display the length of that field. I basically want something to the effect of `<?php strlen(this-message:field_foo) ?>`.

How do I reference my message instance's field?

# Answer
> 0 votes
I couldn't figure out how to do this what I thought was the "right" way - that being inside the message type itself.

Instead, I added a preprocess field from DisplaySuite and put that into my display.

```
function mytheme_preprocess_message(&$variables) {
    $message = $variables['elements']['#entity'];
    if (isset($message) && $message->type == 'my_custom_message' && isset($message->field_foo) && array_key_exists(LANGUAGE_NONE, $message->field_attachment_themed)) {
        $html = $message->field_fooLANGUAGE_NONE][0]['value'];
        $variables['parsed_output'] = $html;
    }
}

```

Then I just named my preprocess field parsed\_output, and it now displays exactly how I want, and I can add whatever custom code I want to my preprocess\_message().

---
Tags: 7, message-subscribe
---


# Question
Title: How to add Login/Register link in the right header in Skeleton theme
I am using Skeleton theme with Drupal 7 in my website. Below is a screenshot of it-

As you can see, the right header is completely empty here. I want to add "Login | Register" links in this block in the following manner-

# Answer
> 2 votes
Drupal has this feature where you can create menu links for user/login and user/logout and only the appropriate one will be displayed automatically. Same goes for user/register.

So create a new menu, add links "Login" (user/login), "Logout" (user/logout) and "Register" (user/register). In admin/structure/block move your new menu to where you need, and apply necessary styling.

# Answer
> 1 votes
Once you create the login menu as described Kari, It will be available as a block. Then you have to place the block in Header top right region.

# Answer
> 0 votes
Looks like you need to increase the width of the Logo and site slogan region (Header left - may be). Make sure to apply the grid classes properly.

---
Tags: theming
---


# Question
Title: Performance Implications when Views JOIN added twice?
I have a view with a flag (relationship, only show flagged nodes). I have modified it a few times and now I see in the query output that views has the join added twice:

```
INNER JOIN {flag_content} flag_content_node ON node.nid = flag_content_node.content_id AND flag_content_node.fid = '9'
LEFT JOIN {flag_content} flag_content ON node.nid = flag_content.content_id AND flag_content.fid = '9'

```

Is there a performance hit for the extra LEFT JOIN?

# Answer
> 0 votes
Astonish Design did a good write up on this topic: Writing Efficient Queries in Drupal.

You should measure your specific queries though, it always depends on the amount of data you are working with, proper indices, mysql configuration and so on. Joining too many tables will almost always increase your query execution time, keep that in mind.

---
Tags: 7, views, performance, database
---


title: Zendesk Webform hook_alter

text:
# Question
Title: Zendesk Webform hook_alter
Im trying to alter the module "zendek\_forms"

It states: There are four fields in the form (name, e-mail, subject, and description), but more fields can be added in hook\_form\_alter and the submit handler will recognize fields prefixed with "zendesk\_" and pack them in the API call to Zendesk.

I am absolutely clueless on how to do this, even where to begin. Any help would be greatly appreciated.

# Answer
> 0 votes
`hook_form_alter` is a drupal API function. You can google "hook\_form\_alter" and the 1st result will be the API documentation for this function; it includes examples.

Using this "hook" function you can inject, or otherwise change, any form in your drupal website. A "form" is an HTML construct that can send data to a webserver via either POST or GET.

So, you can create a custom drupal Module (which consist of in this case an `.info` file and a `.module` file). In your module you can create a function that implements "hook\_form\_alter" and adds in the zendesk field.

A simple simple example of this would be:

```
# in the below examples lets assume you have named your module folder as "zext" (kinda short for zendesk extensions .... i dunno :P

# in zext.info
name = Custom Zendesk Form Extensions
descrption = We want to add custom fields to the zendesk form.
package = Other
core = 7.x

# in zext.module
<?php

/**
 * Implements hook_form_alter().
 *
 * Alter the zendesk form and add a custom color text field.
 */
function zext_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'zendesk_form') {
    $form['zendesk_favorite_color'] = array(
      '#type' => 'textfield',
      '#title' => t('Favorite Color'),
      '#description' => t('Please tell us what your favorite color is!'),
      '#weight' => 99,
    );
  }
}

# that is all the code that would be in the 2 files.

```

With the above 2 small pieces of code we have modified the default zendesk\_form (I assume its `$form_id` is `zendesk_form` ... it may be different examine the module's code to see how it IDs the forms ...) and added 1 single new custom field to allow the visitor to submit their favorite color. Drupal doesn't store these values anywhere -- they are just passed onto Zendesk upon form submission; You simply need to create the folder + 2 files and install the module in the drupal administration. Your module folder should be called `zext`.

There is alot of documentation online for creating modules, and using hook\_form\_alter. Look on drupal.org and Google.

Happy Coding!

---
Tags: forms
---


title: access denied preferred over no view

text:
# Question
Title: access denied preferred over no view
How can I make it so roles that are denied access to a page can still see overview of page i.e. title and description but get an access denied message if not granted access?

I have tried different combinations of per node access along with content access but because in permissions there is only a view published content for all content which if deselected renders every page access denied regardless of content or node access...my only option it seems is the invisible page for no content access which is not at all preferable.

# Answer
> 0 votes
You can try using Premium content Module..

Project Page Says

> This is useful on a news or membership site where teasers are available to the general public but the full body is only available to privileged users. Premium nodes appear in listings with full title and teaser available to anyone. If a user does not have adequate privileges, the default behavior is to show a simple message, but you can use Panels or theme overrides to do more custom things.

Found this article in D.O which will be useful for your issue.

---
Tags: nodes, users
---


# Question
Title: Author name in comment preview not rendering apostrophe properly: a bug or by-design?
This happens on a Drupal 7.26 using the default theme when previewing a comment. The `&#039` part is equivalent to an apostrophe. What I don't know if this is something that is part of Drupal to prevent exploits or if this is a bug that should be fixed. I tried searching the Drupal.org forums if this is a bug, I wasn't able to find anything relevant.

# Answer
Interesting problem to solve ... Here are the findings of above problem.. I do see this issue in latest Drupal.. I believe it's a bug since check\_plain method is not used in any other comment rendering features where as we can see proper name while viewing comment...

Comment preview is rendered from comment\_preview function defined in 2062 Line in comment module..

```
/**
 * Generate a comment preview.
 */
function comment_preview($comment) {
  global $user;

  drupal_set_title(t('Preview comment'), PASS_THROUGH);

  $node = node_load($comment->nid);

  if (!form_get_errors()) {
    $comment_body = field_get_items('comment', $comment, 'comment_body');
    $comment->format = $comment_body[0]['format'];
    // Attach the user and time information.
    if (!empty($comment->name)) {
      $account = user_load_by_name($comment->name);
    }
    elseif ($user->uid && empty($comment->is_anonymous)) {
      $account = $user;
    }

    if (!empty($account->uid)) {
      $comment->uid = $account->uid;
      $comment->name = check_plain($account->name);
      $comment->signature = $account->signature;
      $comment->signature_format = $account->signature_format;
      $comment->picture = $account->picture;
    }
    elseif (empty($comment->name)) {
      $comment->name = variable_get('anonymous', t('Anonymous'));
    }

    $comment->created = !empty($comment->created) ? $comment->created : REQUEST_TIME;
    $comment->changed = REQUEST_TIME;
    $comment->in_preview = TRUE;
    $comment_build = comment_view($comment, $node);
    $comment_build['#weight'] = -100;

    $form['comment_preview'] = $comment_build;
  }

  if ($comment->pid) {
    $build = array();
    if ($comments = comment_load_multiple(array($comment->pid), array('status' => COMMENT_PUBLISHED))) {
      $parent_comment = $comments[$comment->pid];
      $build = comment_view($parent_comment, $node);
    }
  }
  else {
    $build = node_view($node);
  }

  $form['comment_output_below'] = $build;
  $form['comment_output_below']['#weight'] = 100;

  return $form;
}

```

As you can see

```
$comment->name = check_plain($account->name);

```

Comment name is rendered using above statement which takes $account-\>name as input and wraps using check\_plain function which "Encodes special characters in a plain-text string for display as HTML."

Coming to the solution..

* Comment Preview is rendered using Comment\_view Function which gives us hook "hook\_comment\_view"
* By Implementing above hook in your custom module you can check for $account-\>name and use htmlspecialchars\_decode to decode back to original value...
> 1 votes

---
Tags: 7, comments
---


title: Select all team data from a drop down

text:
# Question
Title: Select all team data from a drop down
I have a drupal form with a drop down list of teams like team A, team B, Team C and on submit it goes to page `/team-page/[team-id]` and displays the particular team details.So how do I do if I have to select all team data? because my page only accepts team ids and I want to use `/team-page/all`.

# Answer
> 0 votes
if your teams data are coming from the same table use drupal db select and table api to create a table where u can see all the data try to ajust that to your system

```
  /**
 * Render a filtered list of entries in the database.
 *
 * DBTNG also helps processing queries that return several rows, providing the
 * found objects in the same query execution call.
 *
 * This function queries the database using a JOIN between users table and the
 * example entries, to provide the username that created the entry, and creates
 * a table with the results, processing each row.
 *
 * SELECT
 *  e.pid as pid, e.name as name, e.surname as surname, e.age as age
 *  u.name as username
 * FROM
 *  {dbtng_example} e
 * JOIN
 *  users u ON e.uid = u.uid
 * WHERE
 *  e.name = 'John' AND e.age > 18
 *
 * @see db_select()
 * @see http://drupal.org/node/310075
 */
function dbtng_example_advanced_list() {
  $output = '';

  $select = db_select('dbtng_example', 'e');
  // Join the users table, so we can get the entry creator's username.
  $select->join('users', 'u', 'e.uid = u.uid');
  // Select these specific fields for the output.
  $select->addField('e', 'pid');
  $select->addField('u', 'name', 'username');
  $select->addField('e', 'name');
  $select->addField('e', 'surname');
  $select->addField('e', 'age');
  // Filter only persons named "John".
  $select->condition('e.name', 'John');
  // Filter only persons older than 18 years.
  $select->condition('e.age', 18, '>');
  // Make sure we only get items 0-49, for scalability reasons.
  $select->range(0, 50);

  // Now, loop all these entries and show them in a table. Note that there is no
  // db_fetch_* object or array function being called here. Also note that the
  // following line could have been written as
  // $entries = $select->execute()->fetchAll() which would return each selected
  // record as an object instead of an array.
  $entries = $select->execute()->fetchAll(PDO::FETCH_ASSOC);
  if (!empty($entries)) {
    $rows = array();
    foreach ($entries as $entry) {
      // Sanitize the data before handing it off to the theme layer.
      $rows[] = array_map('check_plain', $entry);
    }
    // Make a table for them.
    $header = array(t('Id'), t('Created by'), t('Name'), t('Surname'), t('Age'));
    $output .= theme('table', array('header' => $header, 'rows' => $rows));
  }
  else {
    drupal_set_message(t('No entries meet the filter criteria (Name = "John" and Age > 18).'));
  }
  return $output;
}

```

---
Tags: nodes
---


# Question
Title: Custom exposed filter to select expired nodes
In my Drupal 7 website I have a content type called "offer" that has a date field called "deadline".

When the current date is greater than deadline, then the offer is expired.

I would like to make a form with Views where I can put a radio button like this: Expired: yes no

Is it possible to do that?

I know that a solution could be to make a new field, to call that "expired", and finally to make a cron to set the value on yes when the node deadline is lesser than the current date. I was looking for something easier...

I made some steps forward. The solution should be using the grouped filters, but it doesn't allow me to chose the relative date:

# Answer
> 0 votes
What about running a cron task that sets the status of offers to unpublished once the expiry date has passed.

Then the view can simply filter on whether or not the node is published.

If you don't want to go down that route then alternatively create a filter based on date and then with a little jQuery hide that and add some radios. Then when the radio is changed set the date filter to the appropriate value and submit the form.

---
Tags: views
---


title: theme_field() not working in a module

text:
# Question
Title: theme_field() not working in a module
Writing in to custom.module:

```
function custom_field($variables) {
  dpm($variables)
}

```

Returns nothing is it working in a module? And i have devel installed and turned on

# Answer
> 0 votes
You can only use that method to override a theme function in a *theme* (template.php).

To override the callback function for a theme using a module, you need to implement `hook_theme_registry_alter()`, e.g.

```
function MYMODULE_theme_reigstry_alter(&$registry) {
  $registry['field']['function'] = 'MYMODULE_theme_field_override';
}

```

You might need to change other things too (file path, preprocess functions, process functions, etc, depends on your use case). The above method will help with all of that too.

---
Tags: 7
---


title: Drupal max-age=0

text:
# Question
Title: Drupal max-age=0
Trying to setup the Varnish cache with our drupal installation. Issue is that with all pages, it's sending max-age=0. I've set this in the setttings.php

```
$conf['cache_lifetime'] = 3600;

```

But whenever I try and view the setting in drupal, I get:

Which even when I set it to any value instead of `<none>`, it just stays as`<none>`.

Not sure what's going on!

# Answer
The settings in settings.php will override any configurations you (try) to choose in the Drupal UI: /admin/config/development/performance .

```
$conf['cache_lifetime'] = 0;
$conf['page_cache_maximum_age'] = 21600;

```

These two settings would override whatever cache timings you set in the Drupal UI.

The maximum\_age setting (for example 6 hours) will display in your headers as:

> Cache-Control:public, max-age=21600

After making changes to the max-age and clearing the cache, if you do not see the changes reflected in the Response Headers it may be worth looking towards nginx for the answer.

As per Q&A: https://stackoverflow.com/questions/19002567/nginx-add-header-and-cache-control . It does provide good information about how cache headers are, or can be set in Nginx.
> 5 votes

---
Tags: caching, proxies
---