# Question
Title: Difference between hide() and ['#access'] = FALSE
I want to remove the delete button from a standard edit form in certain cases and I'm looking for the right way to do that.

So far I found that `hide()` marks an element as already rendered so it basically tricks the rendering process.

`['#access'] = FALSE` does something similar I guess, but still a little different.

In both cases, nothing is rendered concerning the delete button, but does either of them prevent the delete code from being executed on submit (e.g. if a user was manipulating the POST request)?

Or would I need a `form_validate()` method for that anyway?

# Answer
> 8 votes
Hiding the element is done during the rendering process. If you look at the code, it just marks the element as already being rendered.

The `#access` key on the element is used during the form build process (can't find my chart, so I can't tell you exactly which part). It says that this element is part of the form, but a particular user may or may not have access to be able to use it.

Unsetting the element, just throws the element away and says it is not part of the form anymore.

Of the three options, using `#access` is preferred: it's the API so you should use it. When you just hide the element, a user can still submit that element git GET/POST as the Form API thinks it is still valid. For non-submit elements, I believe the `#default_value` will also appear in `$form_state['values']` when you validate/submit (however I don't recall the last time I tested this).

# Answer
> 1 votes
Using hide() will simply prevent that form element from being displayed. The same would be true of unset().

My understanding is that setting #access to false means that even if the POST request is manipulated, the input from that element will not be accepted.

---
Tags: forms
---


# Question
Title: Drupal 6 Form fields not displaying if nested too deep.
I'm using Drupal 6 to create a form that's pretty big. Basically here is how the client wants this form to act:

Users create engagements, and an engagement can have multiple goals and multiple meetings. Each goal can have multiple recommendations, and each recommendation can have multiple action steps. So far I've been able to use AHAH to dynamically add meetings and goals to engagements, but I've hit a snag as I've started to try adding recommendations to goals. I'm doing something like this for recommendations:

```
 $form['goals_fieldset']['goal_'.$gid]['recommendations']['rec_'.$rid]['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Recommendation Title'),
    '#default_value' => $title,
  );

```

This will nest the recommendations array under the goal its attached to, my issue is, the field doesn't show up on the form, is there a limitation to how nested you can go in a form? If I use:

```
  $form['goals_fieldset']['goal_'.$gid]['rec_'.$rid]['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Recommendation Title'),
    '#default_value' => $title,
  );

```

The field will show up. I really need the \['recommendations'\] piece in there cause it is where I've set the wrapper that AHAH replaces when you click the 'add another' button:

```
$form['goals_fieldset']['goal_'.$gid]['recommendations'] = array(
  '#type' => 'fieldset',
  '#title' => t('Recommendations'),

  // Set up the wrapper so that AJAX will be able to replace the fieldset.
  '#prefix' => '<div id="recommendations-fieldset-wrapper">',
  '#suffix' => '</div>',
);

```

Any insight as to why my fields won't show up, or insight into how to fix is greatly appreciated. Thanks!

# Answer
So I found out why its not working, very simple mistake on my part. I was declaring $form\['goals\_fieldset'\]\['goal\_'.$gid\]\['recommendations'\] later in the form, erasing everything else. Sorry for wasting time!
> 0 votes

---
Tags: forms, ajax
---


# Question
Title: How do I disable a module when Drush or the GUI doesnt work?
My site just gives a WSOD and throws this error:

> Error: Unsupported operand types in sites/all/modules/rules/includes/rules.state.inc, line 620

Since I can't even get to my site now without a WSOD, and when I do a `rush cc all` or `drush pm-disable rules` I get that error via the command line, how can I disable the Rules module?

# Answer
> 11 votes
If you have access to your database, you can do it through there.

You can see all the modules enabled with:

```
SELECT name,status FROM system WHERE type='module' AND status='1';

```

You can disable a module by setting it's status to 0.

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

```

For more on uninstalling stuff via drupal's db.

---
Tags: 7, rules, drush, wsod
---


# Question
Title: How do you redirect anonymous users to another page without rules?
Right now i want to restrict all anonymous users to a specific page. I know you can do this with rules by setting the condition if they are anonymous have them redirected to another page. But how can this be done via code? Also I need to add exceptions to the redirect as I dont want users redirected out of user/login page, but everywhere else.

# Answer
I think something like below should work.

```
function modulename_init() {
  global $user;
  $args = arg();
  if(!user->uid && ($args[0] == 'user' && $args[1] == 'login')) {
    drupal_goto('page_you_want_anony_to_redirect_to');
  }
}

```
> 3 votes

---
Tags: 7, rules, redirection
---


title: Getting rid of personal blogs

text:
# Question
Title: Getting rid of personal blogs
I am using the built in blog module with Drupal 7, and I don't like the fact that "Every user gets a personal blog."

For instance, if a user with administrative privileges (Joe Schmoe from our company) makes a blog entry, within the blog entry, you will see a link for "view Joe Schmoe's blog." I would much rather it say "view (company name here)'s blog" or show nothing at all.

Unfortunately, I cannot find any settings for this. Is it possible to disable this feature or get this feature to work the way I would like?

# Answer
You can alter the title of the link using hook\_node\_view\_alter in a custom module.

For example

```
function MY_MODULE_node_view_alter(&$build) {
  // dpm($build['links']['node']['#links']);
  $build['links']['node']['#links']['personal_blog']['title'] = t('view company blog');
}

```

You will have to use some logic to only apply the link to a certain user etc.

I'm not sure about the actual link concerned so if you have devel installed, uncomment the dpm() part and inspect the array to find the correct link.
> 0 votes

---
Tags: 7, nodes
---


# Question
Title: How to delete a variable during uninstall?
I've never run into this problem before, but the variable I set in my module won't delete during uninstall. What am I doing wrong?

I set the variable in my module like this:

```
variable_set('marigold_nutrients', $nutrients);

```

All is good. The variable saves just fine and I'm able to use it as normal with `variable_get`.

Here is how I try to delete it:

In my module's `.install` file, I implement hook\_uninstall...

```
/**
 * Implements hook_uninstall().
 */
function marigold_nutrition_uninstall() {
  variable_del('marigold_nutrients');
}

```

Using the UI, I remove the module then uninstall it. The database table the module creates deletes just fine, and it looks as though it's uninstalled. However, when I look at the variable table in Sequel Pro, the 'marigold\_nutrients' variable is still there. I've run cron, cleared the cache... not sure what to do.

MORE INFO: \- Using the debugger, I see that when I uninstall the module, it steps into the uninstall function just fine, so I'm pretty sure that function is working.

# Answer
The problem is probably here (from the comments):

> The variable gets set during installation when the hook\_schema calls a function to iterate through an array to create database columns.

The uninstall process calls `drupal_uninstall_schema()`, which in turn calls `drupal_get_schema_unprocessed()`, which invokes `hook_schema()`.

So the variable is being added again during uninstall, presumably at a later point in the process than your `hook_uninstall()` is invoked and `variable_del()` has run.
> 0 votes

---
Tags: configuration
---


# Question
Title: Changing which content appears at which parts of site
I would like to make different divs in the template, that show up at different parts of a site: eg. div#1 shows at pages from Menu-01 + it's sub-menus; div#2 shows up at pages from Menu-02 + its' sub-menus, div#3 at Blog pages, and so on.

How can this be achieved? Coming from the Wordpress world it is something like

```
<?php
if ( is_category ('1') ) {
//something for category 1
}
if (is_page ('6') ){
 // something for page 6
}
// other functions for descendant checks possible with custom made checkers in functions.php
?>

```

In Drupal I only found the front page check

```
drupal_is_front_page()

```

But I've found no other types of checkings with this method.

Any help please? Thanks.

# Answer
> 0 votes
I think Geoff is right, drupal is a bit more abstracted from the template than wordpress, rather than putting logic in the theme (divs, templates) you should use blocks to achieve this.

Create a really simple block module (see block module in examples). This would just be just two simple functions, hook\_block\_info (defining block) and hook\_block\_view (returning content of block). If you would prefer you could create a custom block through the admin interface, or present a block using views or any other block module (eg node block).

To determine whether your block shows up on a specific page you could use your own custom logic (probably using menu\_active\_trail) in your block module, specify the block visibility by path in the block configuration, or use Context module .

# Answer
> 0 votes
There is many ways to do this: \- you might use the arg() values and act based on that

```
        if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'YOUR-CONTENT-TYPE') {
               // do something
         }

```

# Answer
> 0 votes
https://www.drupal.org/project/context might be useful for you

"Context allows you to manage contextual conditions and reactions for different portions of your site. You can think of each context as representing a "section" of your site. For each context, you can choose the conditions that trigger this context to be active and choose different aspects of Drupal that should react to this active context.

Think of conditions as a set of rules that are checked during page load to see what context is active. Any reactions that are associated with active contexts are then fired."

---
Tags: theming
---


# Question
Title: Imce file browser not showing select button
The IMCE file browser seems to be missing it's select button. On this File field, I'd like content creators to choose an image that is already located on the server (not uploading a new image).

What setting might I have missed?

**The field on this content type is configured as follows:**

**The profile is configured as followed:**

**File Permissions** The /tmp folder is owned by the apache user and is chmod'ed to 2775. The /sites/default/files/images folder is owned by apache and chmod'ed to 755.

# Answer
> 2 votes
Oh for heavens sake. I turned *off* Aggregate-JavaScript and cleared cache. The select button shows up. As to why this happened I can't say. I'm leaving this answer here in case any one comes up against this.

Temporarily turn off magnification and clear cache.

---
Tags: media, files
---


# Question
Title: custom module to display content (nodes and fields) from another database
we are trying to somehow show fields from nodes existing in a different drupal database than the default. Eg. in the site the module is installed (drupal2) we have the following settings.php

`$databases = array (
 'drupal1db' =>
 array (
 'default' =>
 array (
 'database' => 'drupal1db',
....
 'default' =>
 array (
 'default' =>
 array (
 'database' => 'drupal2db',
...`

is there a way to override views so that it displays content with specific type "eg news" from the drupal1db and/or from both the databases?

Thank you

# Answer
Absolutely you can use a different db for a view. First create a custom module use hook\_views\_data() in a .views.inc file to define the fields of the external db. Once you have defined the fields and cleared the cache you will be able to select a different base table for your view.

With some custom coding and db\_set\_active() or views relationships you should be able to use both.

EDIT: Assuming Drupal 7.
> 0 votes

---
Tags: views, database
---


# Question
Title: MySQL Error: Duplicate Entry on indexing taxonomy structure with Search API
**Problem**

*I have a search index. I use a views page with this to create a search page and results for users.*

I was forced to re-create my search index. I deleted the old one and I'm getting the following error when I attempt to index the new one after re-creating it.

(Technically I get 49 errors, one for each piece of content i'm trying to re-index)

`SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '632' for key 'PRIMARY'`

I only get this error if I attempt to index the hierarchy of a particular taxonomy field.

It sounds like it's trying to re-generate the ID for my set of items, but even uninstalling and re-installing the module and re-creating everything doesn't clear the error.

Any ideas about what might be causing it? Or what I should look for in MySQL as I dig through tables?

# Answer
> 0 votes
I raised an issue in the Search API queue which then got patched. Forgot to post about it here. My bad.

https://www.drupal.org/node/2174163

---
Tags: 7, database, search
---


# Question
Title: What methods are there to load more ROWS into a View display without reloading the page?
I have a basic View showing 2 node teasers at a time. I want to be able to have a button below it that says load more. Once you click it, it will load the next two. I know that there is the module "views\_load\_more", but there seems to be a bug with that module that causes duplicates. There is a patch for this issue, but it doesn't solve the problem from what i have tried.

I was wondering what other modules or methods to achieve this same functionality?

I was thinking of continuing to use the views load more module, and just use jquery to detect if there are duplicates and then remove them. But that way seems to be a bit hacky.

# Answer
> 2 votes
The Views Infinite Scroll module is an alternative solution for ajax pagers in views however I haven't used it so I cannot comment on how well it works.

It also works a little differently to views load more so it may or may not meed your requirements.

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


# Question
Title: 2 servers with 2 local memcached: flush both
I have servers and 1 memcached server linked by the network. When I add 2 memcached on the 2 servers, locally, it's drastically faste !

So I've configured Drupal to use memcached on 127.0.0.1, except for sessions. The sessions are the only data hosted on the network server (MC 3).

```
DRUPAL 1    DRUPAL 2
 MC 1         MC 2
   \            /
    \          /
     \        /
        MC 3
      Sessions

```

It's fine, except for the cache flush because when I do a `drush cc all`, Drupal 1 will only flush MC1, and Drupal2 only MC2, but not both.

The idea is to force Drupal to clear all the memcached, but to use only the localhost + MC3.

What is your advice, add a hook to clear both servers?

# Answer
I suggest you to use Drush aliases.

Here is the quote from the documentation http://drush.org/en/master/usage/#site-aliases

> Drush lets you run commands on a remote server, or even on a **set of remote servers**. Once defined, aliases can be references with the @ nomenclature

Also from here https://raw.githubusercontent.com/drush-ops/drush/master/examples/example.aliases.drushrc.php

> Alias groups (aliases stored together in files called GROUPNAME.aliases.drushrc.php, as mentioned above) also create an implicit namespace that is named after the group name.

Finally, these are few simple steps to achieve what you want:

* Create `production.aliases.drushrc.php` file
* Put in this file aliases for both Drupal 1 and 2
* Then you can clear cache on all site at once with `drush @production cc all`
> 1 votes

---
Tags: caching
---


# Question
Title: How to hide completed event from view result based on it's end date?
I have created an Event Type pages which have date field Start Date-End Date, how do I hide completed event in view result or else is there any other way to unpublished them automatically?

# Answer
You should Enable the "Date Views" module first. Then you will be able to find the Date CCK fields available in the filter criteria as Expected. You will also be able to provide a relative date in the filter criteria. Refer Screenshot.

Hope this Helps!
> 1 votes

# Answer
You should look at the Scheduler module, which will publish/unpublish nodes after specified date(s).
> 0 votes

# Answer
It is not clear if you're using Views or if you haven't understood that tag, but if you actually are, you can set the filter criteria like that:

Good luck!
> 0 votes

---
Tags: datetime, views
---


# Question
Title: Need to change User Pages Title and Breadcrumb in drupal 7?
I want to change Title and breadcrumb for user pages to `username` to `My Account`. I don't want to user `drupal_set_title` or `drupal_set_breadcrumb` bcoz its in lots of pages

I saw below code in `user core module`

```
  $items['user/%user'] = array(
        'title' => 'My account',
        'title callback' => 'user_page_title',
        'title arguments' => array(1),
        'page callback' => 'user_view_page',
        'page arguments' => array(1),
        'access callback' => 'user_view_access',
        'access arguments' => array(1),
        // By assigning a different menu name, this item (and all registered child
        // paths) are no longer considered as children of 'user'. When accessing the
        // user account pages, the preferred menu link that is used to build the
        // active trail (breadcrumb) will be found in this menu (unless there is
        // more specific link), so the link to 'user' will not be in the breadcrumb.
        'menu_name' => 'navigation',
      );

/**
 * Menu item title callback - use the user name.
 */
function user_page_title($account) {
  return is_object($account) ? format_username($account) : '';
}

```

User menu is calling title callback function and set the user name in that callback function. So i have tried `hook_menu_alter` to change title callback of user menu but it is not working

My Code

```
function health_portal_menu_alter(&$items) {
  $items['user/%user']['title callback'] = 'health_portal_user_menu_title';
}

function health_portal_user_menu_title() {
  return 'Test';
}

```

Anybody tell me what is wrong with this code and what i do?

Thanks

# Answer
Before trying to implement through code, give a try to these modules:

https://www.drupal.org/project/page\_title

https://www.drupal.org/project/custom\_breadcrumbs
> 1 votes

---
Tags: users, breadcrumbs, 7, routes
---


# Question
Title: Using rules how to redirect to a url + element id
After saving a node, I am redirecting to another form using rules.

I want to be able to append this value "field\_article\[und\]\[0\]\[nid\]" to the url that I am sending to. This corresponds to a select list id. Basically, I want this id appended to the url when I redirect.

Any ideas?

# Answer
> 1 votes
You can use token from `Replacement Patterns` list. Token will be something like `[node:field_node_ref]`.

# Answer
> 0 votes
The Rules module provide PHP Evaluation for the action "Page Redirect". You can get the field value using PHP code and append it to the URL. Refer attached Screenshot.

Note: Before providing the value for URL, make sure that value Exists.

---
Tags: rules, workflows
---


# Question
Title: Programmatically translate taxonomy terms
I have a vocabulary of taxonomy terms I get through `taxonomy_term_load($tid);` and displays in views page. How do I get and display the terms depending on the user's language?

# Answer
Basing on Using the i18n API from other modules, the code should be the following one.

```
$term = taxonomy_term_load($tid);
$translated = i18n_string_translate("taxonomy:term:$tid:name", $term->name);

```
> 0 votes

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


title: Nested OR clause with EntityFieldQuery

text:
# Question
Title: Nested OR clause with EntityFieldQuery
I have a table products structure like this

```
product_id   product_name   product_created_date   product_expiry_date  availability
----------   ------------   -------------------    -------------------  ------------
    1           x             12-NOV-13                14-JUN-14               No
    2           y             13-DEC-13                   null                Yes
    3           z             14-DEC-14                14-DEC-15              Yes
    1           p             12-NOV-13                14-JUN-14              Yes
    ----        --             -----                     ----               ----

```

I need a query like :

```
select product_id from products where (product_expiry_date>='12-DEC-14' or product_expiry_date is null) and availability='Yes'

```

how to do this using EntityFieldQuery?

# Answer
> 0 votes
I had to do a query like that once, here is how I achieve this with EFQ:

```
$matches = array();
yourmodule_mini_query('12-DEC-14', $matches);
yourmodule_mini_query('null', $matches);

function yourmodule_mini_query($value, &$matches) {
  $entityQuery = new EntityFieldQuery();
  $query = $entityQuery->entityCondition('entity_type', 'product');
  $query->fieldCondition('product_expiry_date', 'value', $value, '=');
  $query->fieldCondition('availability', 'value', 'Yes', '=');
  $results = $query->execute();

  if(count($results)) {
    foreach ($results['product'] as $p) {
      // By using product_id as array key, you deal with the duplicates
      $matches[$p->product_id] = $p->product_id;
    }
  }
}

```

Where `$matches` contains an **array of product\_id's** that are available and for which `product_expiry_date` is `null` **OR** `12-DEC-14`.

Hope it helped.

**EDIT:** As said in the comments below, the evaluation of the NULL value may require a second distinct query instead of calling twice the same function.

---
Tags: 7, database
---


# Question
Title: How to tag to parent of the parent in taxonomy?
I have a parent term *Regional* and in *Regional* I have several languages say *English* etc. I have songs tagged with these languages.

If I select *Regional* I want to select all songs under all languages in the parent term *Regional*. How would I do that?

# Answer
You could look at the Hierarchical Select module.
> 1 votes

---
Tags: taxonomy-terms
---


title: Create multilingual homepage

text:
# Question
Title: Create multilingual homepage
I created the basic page, then added alias `front_page`. Next, I created a translation of this node and have the same alias. In the settings `admin/config/system/site-information` in the field `Default front page` I added `front_page`, but on the home page is displayed when you switch the language is the same article, without translation. How to fix it?

# Answer
> 1 votes
You need to use the *Variable Translation* for that:

> * In Configuration \> Regional and languages: Multilingual settings \> Variables, enable 'Default front page' as a multilingual variable.
> * Go to Configuration \> System \> Site information \> Front page.
> * Change the language via the section "Select language" at the top of the page to select the language for which you're setting the front page option.
> * Set the 'Default front page' option for the current language.
> * Repeat as necessary for each available language.

Relevant link: HowTo: Different home page (default front page) for each language

---
Tags: i18n-l10n, nodes
---


title: Boolean field not in CSV views export

text:
# Question
Title: Boolean field not in CSV views export
I have a boolean field (a checkbox) in my user profiles. I have left it with the default settings (1= ticked, 0=unticked).

I have created an CSV export in Views of the user data. All the fields in the user profile work, apart from the boolean value, which is not exported (it just appears as "", for all users). If I look at user profiles however, the box is ticked (or unticked) so the data is there, just not being exported.

How can I get this field to export?

# Answer
I have managed to solve this - I needed to change the formatter for the field to "Key".
> 2 votes

---
Tags: views, importing-exporting
---


# Question
Title: How to ask anonymous to confirm their flag by email?
I need to add Flags to one of my content types. Two kinds, actually:

1. I'll take care of it
2. Solved

Second flag should be available only to node author, and only if first one was already raised. But that's simple part. First kind of flag is trivial for logged in users, too.

The point is - I need to make first kind of flag available for anonymous users, too. And I need to make sure I have their valid email addresses. Standard confirmation link in mail would be OK - so how do I do that?

I know I can develop custom module from scratch, and I will if needed, but I was sure there is already a out-of-the-box solution, and I simply can't find it now.

Just to make some things clear:

* Flag module works for anonymous users if you install Session API. No problem here.
* I planned to keep emails in Email Field attached to flag itself. For logged in users it defaults to their email, and if they decide to change it, so be it, I have a way to reach them anyway. For anonymous, I want it verified by link in email, and if it is not verified in time, I want to delete flag. Deletion will be easy with CRON and Rules or simple helper module, it's verification that's complicated (and I hope solved already).

# Answer
I must say, **I wish I would have used Jelle's way**. But I didn't. So I don't know if it works.

# Here is the way I did it

1. I created a flag with email field. I made flag button to lead to form, so users would need to fill it. There are some fields required for everyone, anyway.
2. Required by role made email required for anonymous. Logged in users may fill it if they want different email, and in that case they still should get verified, so far so good.
3. I installed Email Field Verification, enabled it, turned it on the email field attached to flag, and set it to delete content if field is not confirmed.

# Why I wish I didn't

These modules are buggy. Especially Email Field Verification \- all it's bugs needed to be worked around. It took me some patches and hacks to make it all work the way it should. I believe it might be easier to write it myself, actually. Well, at least I hope I'll be able to contribute patches.
> 0 votes

# Answer
I would use hook\_flag\_link\_type\_info() to provide a link type like the 'confirm' link type provided by the flag module. Copy their approach, but on the 'confirm' form you ask for the users e-mail address (if the user is anonymous). You save the value to the email field you added to your flag and the Rules module should be able to do the rest for you. It requires a bit of custom code (not too much I would guess), but the major part of the functionality (flagging, unflagging, rules integration, ...) still comes from the Flag module.

\[EDIT\] For the verification part: Add a boolean field to your flag ('Verified') which you change with the verification link you send by mail. The "Solved" flag can be hidden/shown with hook\_flag\_access().
> 2 votes

# Answer
I have done 2 modules which sends emails. One for authenticated user to receive by email their flagged content and one to send to a friend a URL you like.

I think it's a bit long to post all the code here, so I've put a zip online to upload

Maybe you can do a mix of both to achieve your goal.

Hope it helps.
> 1 votes

# Answer
As far as I know, there is only one anonymous user, whose account is shared by all anonymous users. If you want to track the email address of anonymous users, then can't the be given their own accounts?

The only way I can think of storing information for anonymous users, is to set a cookie, which is stored on their computer. But there would be an issue of different anonymous users shared a computer, or the anon user used two different devices.
> -1 votes

# Answer
I may be missing some of your requirements here, but I would have thought that once you have an anonymous user's email address, they are no longer anonymous. If that is accepted, maybe instead of attributing flags to anonymous users, you could work with the drupal system and simply create them a low level account when they flag something. You could then differentiate flag access by role instead.

In order to do this you would need to get the user immediately logged in, using something like the User Registration Password module. You could alter the flag action to send them to registration page first (simplified to email address only), with the flag details maintained as a destination in the query string, thus applying the flag only after the user is logged in, but prompting email confirmation.
> -1 votes

---
Tags: emails, flags, users
---


title: How to set page title of panel page

text:
# Question
Title: How to set page title of panel page
I have a panel page that includes several views. I want to use the title field of one of the views as the page title. So far, I have not been able to figure out how to do this.

I have installed Panel Variant Page Title module. However, I don't seem to have access to the field I want to use. The closes substitution available is `%arg:title`.

If I use this substitution, the page title is set to the whole URL.

Any ideas about how to accomplish this?

# Answer
Go to the Panel Configuration page into the *Content* section. Now choose in the dropdown field *"Title type"* the value *"From pane"*.

Now select a pane with the view and click on the configuration link of this pane and choose *"pane title"*.

Your Panel shows now the title of your selected pane.
> 6 votes

---
Tags: 7, panels
---


# Question
Title: How to add the Shipping Charge on the selected products in commerce kickstart?
I am using Drupal commerce kickstart. Can anyone tell me how to create the field for Shipping charge in the product creation form and I could enter the Shipping charge in that field for selected products.

# Answer
> 1 votes
There are couple of modules for it:

> Commerce Shipping provides a shipping rate calculation system for Drupal Commerce, integrating shipping service selection into both the checkout form and order edit form.

---
Tags: commerce
---


# Question
Title: How to add the VAT on the selected products in Commerce Kickstart?
I am using Drupal commerce kickstart. Can anyone tell me how to create the field for the VAT in the product creation form? I need a field for each product listed in the product form.

# Answer
> 0 votes
There is a module Commerce VAT for this purpose

> Commerce VAT module is an improved module for supporting VAT than the Commerce Tax module included in Commerce. If you are using Commerce VAT is is recommended you disable Commerce Tax.

# Answer
> 0 votes
What you need to do is calculate the VAT based on the price and not add it as a field. There is the Commerce VAT module, which is a specialised module just for VAT calculations.

This module will add the VAT to the order as a line item at checkout.

---
Tags: commerce
---


title: Drupal Commerce Check out

text:
# Question
Title: Drupal Commerce Check out
I am using Drupal 7 commerce; I would like to set up the check out process to skip the payment portion and just send an email to the admin and the customer. How do I do that?

Thank you for you help.

# Answer
> 1 votes
Just disable the Payment module and edit the default checkout completion rule that emails the customer to include an action that emails the administrator.

---
Tags: commerce
---


# Question
Title: How to customize CKEditor format configuration
I'm using Drupal 7 with CKEditor module and I would like to delete some formats in the dropdown box that is currently labeled "Format". So I modified the config file which is `site/all/modules/ckeditor/ckeditor.config.js`. I modified the code like this :

```
CKEDITOR.editorConfig = function(config) {
   // some code here
   config.format_tags = 'p;h1;h2;h3'; // I added this line
}

```

Then I flush all caches of drupal and the cache of browser, but it doesn't work. When I create a new content, I always have all the formats. How to make it work? (**Note :** I don't want to customize it from `admin/config/content/ckeditor/edit` page)

# Answer
> 0 votes
To remove entries from "Format" selection list of ckeditor just follow in the drupal admin menu :

**Configuration \>\> Content authoring \>\> Ckeditor**

Edit the concerned profile(s) and within the **Cleanup and Output** section change the **"Font formats"** list, removing the tags you don't want.

Save and **clear your caches**.

---
Tags: wysiwyg
---


# Question
Title: Stop caching for a specific node type Drupal 7
I'm working with a node type that has several custom fields. The values of these fields need to refresh on each page load, but because of Drupal's caching feature, they don't. What is the best way (simplest way) to stop this content type from caching?

# Answer
> 14 votes
See if http://drupal.org/project/cacheexclude can do it for you. If not you need to create a module that will implement hook\_init. Inside of that hook you need to load the node from arg() from there see if the node is of a certian type; if it is disable the page cache.

```
<?php
  // Get the current active node object if present.
  $node = menu_get_object();
  if (!empty($node) && !empty($node->type) && $node->type == 'page') {
    drupal_page_is_cacheable(FALSE);
  }
?>

```

# Answer
> -2 votes
For Drupal 8:

```
// Mark this page as being uncacheable.
\Drupal::service('page_cache_kill_switch')->trigger();

```

---
Tags: caching
---


# Question
Title: Display a link to create new content when content missing (via Contextual Filters)?
I'd like to give users the option to create new content when a certain contextual filter is missing on a panel.

e.g. I have my reviews on a panel. When a review is missing I'd like it to display a block/link to submit a new review.

However my only options are to hide the view, give a summary etc.

How do I do this?

I've found the option for '*No Results Behaviour*', but I can't hook into the contextual filter (and then use a relationship to grab a term name). I've also found this work around:

https://www.drupal.org/node/1895724

But I'm struggling to re-write the code to pull the term name out of the term id in the contextual filter.

# Answer
Here I suppose you have added an argument in panel path. You can assign any `context` to your argument, eg `Node: Id`. It can be Term as well.

Assign any context to argument like :

Add a visibility rule if `Context exists` to your view and `not exists` to custom pane.
> 1 votes

# Answer
I managed to work it out, I turned on the PHP Filtering module, and inserted this as a Global text area, with `Text format = PHP Code`

```
<?php
    $view = views_get_current_view(); //get the current view
    $term =  taxonomy_term_load( $view->args[0] ); // the term id
    $term_name = taxonomy_term_title($term); //get the term id e.g. turn 123 = term_name
?>
<p>No comments exist for <?php print $term_name; ?>.</p>//print out the name
<p><a class="button" href="localhost/drupal/node/add/technology-comments?edit[field_technology][und][textfield]=<?php print $term_name; ?>">Add new comment</a> </p> //link to the add new page, pre-populating with term_name
<p></p>

```
> 0 votes

---
Tags: 7, views
---


# Question
Title: Adding the year to the date on the blogs
So, I've gone through making a view called `BlogPage` and a content-type of `BlogEntry` probably ten times now. I've created both in the simplest ways I can, and I've tried to narrow down what is causing my page to look the way it does, and I think it must be my theme. I am using the `Visia` theme I have purchased.

Simply, I've created the view, content of type blog-entry, newest first.

I've also added: Sort Criteria: Content: Post Date(desc).

I do love the look of the blog, but the year is not listed in the date of posting. Is there any way to do this? Is this a setting I can't find? Is this being caused by my theme?

**UPDATE:**

I've tried using the "Fields" option, but I can't find the "Date Format" option. This is the screen I have:

# Answer
Change the date format in *Regional and Language Settings* to match your preference:

https://www.drupal.org/node/71106

Then (assuming you are displaying fields rather than full/teaser nodes) select the date format you require from by editing the field settings in views

And specifying which of the predefined (or custom) date formats you would like to use:
> 1 votes

---
Tags: 7, nodes
---


# Question
Title: Using #states to disable a field collection field
I am trying to disable a date field's second value, inside a field collection, but it isn't working.

My hook\_form\_alter has this:

```
  $form['field_certification']['und'][0]['field_validity']['und'][0]['#states'] = array(
        'disabled' => array(
          'input[name="field_certification[und][0][field_auto_calculate_validity][und]"]' => array('checked' => TRUE),
        ),
      );

```

The HTML for the date field is here:

```
<input class="date-clear form-text hasDatepicker date-popup-init" type="text" id="edit-field-certification-und-0-field-validity-und-0-value2-datepicker-popup-0" name="field_certification[und][0][field_validity][und][0][value2][date]" value="07/23/2014" size="20" maxlength="30">

```

The checkbox is here:

```
<input type="checkbox" id="edit-field-certification-und-0-field-auto-calculate-validity-und" name="field_certification[und][0][field_auto_calculate_validity][und]" value="1" class="form-checkbox">

```

Could it be because I'm not specifically selecting the (second) value of the date field?

# Answer
> 0 votes
My original answer totally missed the point (apologies), this is updated version:

I do not think you can use Drupal's form api #state property to accomplish what you would like. States can be used to hide, reveal and disable whole form elements, such as a fieldset, text input or date field, but you aim to disable one part of a single (contrib) element (ie the second value of a date\_combo field provided by the date module).

There are two possible solutions:

* load your own jquery when the form is loaded, and add a change() function to disable the relevant date field component
* separate the start/end dates into separate date fields and use the drupal #states functionality (as above) to disable the (whole) second date field:

```
$form['field_certification']['und'][0]['field_validity']['#states'] = array(
'disabled' => array(
    ':input[name="field_certification[und][0][field_auto_calculate_validity][und]"]' => array(
        'checked' => true
    ),
)

```

);

I hope this helps, I played around with it on a blank d7 install, and this was the only way I could get your intended functionality to work.

---
Tags: javascript
---


# Question
Title: Last hook to be called after entity save?
Of the various hooks called during the entity save process, which is the very last to be called?

Is there a way to trigger an event after the entity has been created, after all fields have been saved, after caches updated, etc? So that, when a user saves the update form, this action is the very last thing to happen before the redirect page is loaded?

If it's not strictly part of the save process, that's fine. What matters is: it's called after everything to do with an entity being saved. If there's a way of hooking some form function and reliably identifying from the data in there that a save process has been completed, or defining some callback, that's fine by me.

(context: I've got a problem where field caches are being created that caused newly created nodes, and other fieldable entity types, to load as if they are blank and as if they have no field data - but all attempts so far using cache\_get and cache\_clear\_all don't find the cache - it's being created late in the process. So I'm looking for the latest possible hook which will definitely get it)

(Relevant info: `hook_entity_postsave` doesn't exist, and is one of those core issues that got stuck months and months ago)

# Answer
The various wrapper functions (`node_save()`, `user_save()`, etc.) are responsible for resetting the entity cache after the save method has been invoked on an entity controller.

If you take the `user_save()` function as an example, this cache reset happens *after* the function invokes the various entity hooks (same goes for `node_load()`)

That in mind, I think the question then becomes "What is the last hook to be called *during* an entity save"?...and the answer is `hook_entity_update()` / `hook_entity_insert()`. But, they are called before the cache is reset (for obvious reasons).

The `entity_save()` method just invokes the save handler for that particular entity type, and doesn't invoke any hooks of its own, so really your only options are:

* Roll your own entity controller for the various entities you need to intercept, changing the `save()` method to invoke a hook after the cache has been cleared.
* Hack/patch the existing entity controllers with the same code.

Neither are particularly attractive options but unless there's a solution available at a higher level that I'm not seeing, I don't think you've got much choice.
> 3 votes

# Answer
I had a similar problem where I wanted to execute a view after a node was saved. The node appeared in the view but had old data on the fields despite just having been saved. Subsequent calls to the view had the latest field values.

I called the following at the start of my hook\_node\_update which appears to solve the problem (for me).

```
/**
 * Implements hook_node_update().
 */
function mymodule_node_update($node) {
  // Clear internal properties.
  unset($node->is_new);
  unset($node->original);
  // Clear the static loading cache.
  entity_get_controller('node')->resetCache(array($node->nid));

  // Rest of my code e.g. execute a view.
}

```

This reset cache command is what is run by the node\_save function after invoking all the hook\_node\_update's.
> 2 votes

# Answer
Yes, there is an addon module which provides hook to invoke after an entity is saved. It's called Hook Post Action. This was already answered on stackoverflow.com.
> 2 votes

---
Tags: 7, hooks, entities
---


# Question
Title: Memory usage PHP peak=40.25 MB -- too much for a single request?
I am developing a multilingual - multidomain site ( using i18n and Domain Access and several extra modules - CTools, Colorbox, etc. ). I have installed Devel because I thought the site was very memory consuming. I have seen peaks of PHP peak=40.25 MB in many of the pages. Is that too much? What happens if there are many concurrent users? Will the 128 PHP memory limit be able to handle many requests, will it use hard-drive memory instead of RAM ?

# Answer
The memory limit setting (often 128MB) is per process, so you're only using around third of it. If a single request needs more than 128MB of memory, it will fail. This doesn't appear likely in your case.

> What happens if there are many concurrent users?

That depends on your total amount of RAM. You can in theory handle up RAM / 128 MB users.

If you have 15 concurrent users, each using 40MB, and you have 512 MB, then you'll go over that limit, because 40 * 15 = 600.

The normal configuration is then to use the hard-drive, often called swapping. This normally means the death of all performance, and should always be avoided, to the level where it's better to out right reject more incoming connections.
> 2 votes

---
Tags: debugging
---


# Question
Title: Attach an #ajax callback to a field when the form is reloading from previous ajax request
Is it possible to attach an #ajax callback to a field when the form is being regenerated from a previous ajax event (like a submit button)?

---

## **What I tried**

Adding the #ajax callback to the field when the form is reloading does not seems to trigger anything:

```
// Adding the ajax event to the field.
$form['my_field']['#ajax'] = array(
  'wrapper' => 'module_form',
  'callback' => 'module_form_ajax_callback',
);

```

The Drupal.settings array is not updated after the end of the ajax process. Seems like I'm trying to do something the Form API isn't able to do out of the box... Here's the result of the first ajax request: You can see there's **still only the submit button** in the form attached to an ajax event.

## **Update**

I spotted the issue, it was somewhere else. My form **is a multi-steps form**, when a step is submitted, I rebuild the form with the previous steps and add the next one.

For the previous steps, I render them based on data available from $form\_state\['complete form'\], the render array here is actually storing a lot more data than the one I had set in the first place, which was causing conflicts.

# Answer
> 0 votes
When rebuilding previous steps, I used data available from `$form_state['complete form']`. To be sure the #ajax is taken into account, I had to strip some values from the `render array` which were causing conflicts on the form generation.

Once I had included previous steps into `$form`, here's what I did to attach ajax to all the fields of those steps (because that's what I initial wanted to do):

```
/**
 * Remove data causing the ajax event to break.
 */

// Remove all "radio" fields stored into the "radios" field (may be useful for "checkboxes" field too).
foreach ($form[$field_name] as $key => $value) {
  if (strpos($key, '#') === false) {
    unset($form[$field_name][$key]);
  }
}

// Values removed based on tests (were causing weird behavior or breaking template).
unset($form[$field_name]['#defaults_loaded']);
unset($form[$field_name]['#theme_wrappers']);
unset($form[$field_name]['#ajax_processed']);
unset($form[$field_name]['#value']);

// Add the ajax callback.
$form[$field_name]['#ajax'] = array(
  'wrapper' => 'module_form',
  'callback' => 'module_form_ajax_callback',
);

```

The best thing to do would be not to use `$form_state['complete form']` at all. But the module was already too big for such refactoring. So here you go :).

# Answer
> 0 votes
`#attached` Will not be processed properly on elements that was loaded with AJAX. Maybe it could, but it never worked for me. on the other hand, using `#ajax` worked for me without a fault. what I would try (obviously a guess because you didn't provide full SSCCE) would be:

```
$field['#ajax'] => array(
  'wrapper' => 'module_form',
  'callback' => 'module_form_ajax_callback',
  'event' => 'change',
);

```

If this element is created with an AJAX call from another element, it's AJAX will work.

---
Tags: 7, ajax, forms
---


title: Modules like Scroll Reveal

text:
# Question
Title: Modules like Scroll Reveal
I'm looking for a module like Scroll Reveal. The functionality is quite simple, when a user enters a viewport, content will be displayed using jquery effects.

The outstanding issues for the aforementioned module imply that it appears to be broken, according to the issue queue.

# Answer
> 1 votes
I also experienced issues with the module. I think that the module has not kept pace with the scrollReveal library development.

So file a bug report, or just add the functionality to your theme yourself.

Add the library in template\_preprocess\_html, and then add `data-sr` to any element you want the functionality on.

---
Tags: 7, javascript
---


# Question
Title: Change file path of aggregated CSS file path
How do I go about changing the file path of the aggregated CSS file paths?

As most of you know, when using the Drupal option (from admin/config/development/performance) to 'Aggregate and compress CSS files' Drupal creates different CSS files that look something like this:

My issue is that my site visitors are always seeing the cached (old) version of my stylesheet when they visit my site. Of course I always want them to see the newest version, but I also want to optimize my website as well as possible.

Back to my original question. Is there any way to change the path that looks like gibberish (first example starts with "791YXB.....") ? I've gone through several of the questions here, but I can't find an exact answer for this.

Just for reference, this is how my performance options are setup:

After making changes to my CSS files I also always click the button to 'Clear all caches'.

# Answer
Not the answer you're looking for but it does solve the problem you're having (old css); try the Advanced CSS/JS Aggregation module.
> 1 votes

---
Tags: theming, caching, css-js-aggregation
---


title: Can not add content to panels

text:
# Question
Title: Can not add content to panels
Environment:

* Drupal 7
* Modules: Page manager, Devel generate, panels in-Place Editor, Panels, CTools, jquery-module

I defined a 3 column design but I can not add any content to any panel (superior, left side, middle column, right side...)

Any idea what it can be?

# Answer
So it turned out to be a jquery version problem.

Here is how I sort it out.

I have installed the jQuery Update module with version 1.10 selected and I had to change it to version jQuery Version 1.7 and all the gotchas faded away.

I hope this help to anyone else!

(Module jquery\_update)
> 0 votes

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


# Question
Title: How can I assign the Commerce Product SKU as the Path Alias?
We would like to automatically assign the Path Alias for each new Product as /products/sku.

How can we do this, either from the URL Alias admin UI or via Rule or programmatically?

# Answer
> 2 votes
Pathauto should give you enough flexibility to do that.

Once your "product" content type has a `commerce_product_reference` field linked to it (let's call it "field\_product"), all fields attached to your "product variation type" should be available as tokens like this:

`[node:field-product:product-id]` or if you created a specific field to store the value `[node:field-product:field-sku]`.

You probably know it but patterns can be configured from here : `admin/config/search/path/patterns`.

---
Tags: commerce, path-aliases
---


title: rules scheduler performance

text:
# Question
Title: rules scheduler performance
I use drupal 6 with rules. I have more than 200 scheduled tasks (updating node's field)waiting to be executed at one time. Do I need to worry about server crash or is there some kind of queue implemented in scheduler? Thank you.

# Answer
> 0 votes
You need the *Ultimate Cron module*. It is an advanced system for managing scheduled tasks. You can set rules and custom schedules for every single task. Can be found here:

https://www.drupal.org/project/ultimate\_cron

---
Tags: 6, rules
---


# Question
Title: Show related Content type content in block filtered by category
I have a Content Type called "All Documents", this uses a Category called "All Categories". Within "All Categories" I have multiple sub-categories eg "Sales", "Parts" and "Service".

I have a block that displays the related content of "All Documents" but this shows everything in that Category. How do I filter so if I am viewing "Parts" it will only show content related to that sub-category?

# Answer
> 1 votes
At first, category and sub-category should be in Drupal-terms. Taxonomy vocabulary, taxonomy terms etc.

Assuming your related content block is created with contextual filters.

You can add these contextual filters to your views:

* **Content: Has taxonomy term ID (with depth)**

*Display content if it has the selected taxonomy terms, or children of the selected terms. Due to additional complexity, this has fewer options than the versions without depth.*

* **Content: Has taxonomy term ID depth modifier**

*Allows the "depth" for Taxonomy: Term ID (with depth) to be modified via an additional contextual filter value.*

---
Tags: views
---


# Question
Title: Is it possible to add translation to smiley alt and title in CKEditor?
I'm using Drupal 7 with CKEditor module which permit to insert smiley from editor. I've found that the source code of CKEditor fix the smiley description in JS :

```
config.smiley_descriptions = [
    'smiley', 'sad', 'wink', 'laugh', 'frown', 'cheeky', 'blush', 'surprise',
    'indecision', 'angry', 'angel', 'cool', 'devil', 'crying', 'enlightened', 'no',
    'yes', 'heart', 'broken heart', 'kiss', 'mail'
];

```

So when I insert a smiley, the code will be

```
<img alt="laugh" height="23" src="//cdn.ckeditor.com/4.4.3/full-all/plugins/smiley/images/teeth_smile.png" title="laugh" width="23">

```

But I want to modify the language of `alt` and `title` attributs according to the language used in my site. Is it possible to do that? Thanks in advance.

# Answer
> 0 votes
Never tried but I'm pretty sure that's possible.

If you use the `ckeditor` module, you can alter JS settings through PHP with `hook_ckeditor_settings_alter`.

Knowing that, it becomes pretty easy to wrap all strings with the `t()` function:

```
function yourmodule_ckeditor_settings_alter(&$settings, $conf) {
  foreach ($settings['smiley_descriptions'] as $key => $smiley) {
    $settings['smiley_descriptions'][$key] = t($settings['smiley_descriptions'][$key]);
  }
}

```

If you use the `wysiwyg_ckeditor` module, you can use `hook_wysiwyg_plugin`. That's pretty much the same thing, you can find a pretty good example on how to use this hook here.

Again, the code hasn't been tested, but it should be a good starting point ;).

---
Tags: wysiwyg
---


title: Is it possible to sum on webform

text:
# Question
Title: Is it possible to sum on webform
I'm newbie and made web form to fill with some values. I want to sum all values on Column to make it has a total of column Value, like in excel to do sum of several values into one grand total.

Anyone experienced this ?

Thanks in advanced.

# Answer
There is a tab titled "Analysis" for this. Alternatively you can use the "Download" option. See the example in the screenshot below.
> 2 votes

# Answer
You can try Webform Calculator

> Provides a formula webform component for computed values, where you can enter a mathematical calculation based on the other fields. E.g., create a formula field with value formkey1 * 0.1 * formkey2.
> 1 votes

# Answer
You can try Webform Calculation Components.

> This module provides AJAX functionality to perform basic arithmetic operations on webform components.
>
> With this module the user can have calculated fields, e.g. the total amount, calculated percentage etc.

It works with Webform 7.x-4.x
> 0 votes

# Answer
If you would like to sum the webform submission data, you can use Views Aggregator Plus https://www.drupal.org/project/views\_aggregator

You can put sum function in the columns you want to sum. You can put the results in end of the row.
> 0 votes

---
Tags: webforms
---


title: Panels - custom or use System?

text:
# Question
Title: Panels - custom or use System?
Maybe I'm not getting this but for Page manager (Panels) there is two options to create a page either Custom Page or use the System (Node Template).

I need to create a Panel for the news page (/news). I could either create a Custom one and set the path to "/news" OR use the System node\_view page and create a Variant where if the ***Selection rule = This panel will be selected if Current path is "news".***

Which way is better? Should I overload the System with many variants where one of them checks if the Current path is "news" or create my own Custom Page for the news page?

# Answer
> 0 votes
A page provides a certain context.

For `node_view`, it happens to be a node.

There's no benefit to creating a custom page just to provide the same context.

You'd want to add a new page however, if you, for example, wanted both a node and a taxonomy term as context.

# Answer
> 0 votes
It's not a matter of which one is better, but what you are trying to achieve.

* If you want to change what the system does when people view a node `/node/%node`, then you need to make a variant on that system page.
* If you want to make a new page that does something different like `/news` then you need a custom page.

Each page listed in Page Manager must have a different URL, each variant within a page will have the same URL (except for arguments `%mandatory` and `!optional`).

So you actually *cannot* have a variant for `news` inside the `node/%node` system page.

---

One of the most common uses for a custom page is to display a view, which is what I assume your `/news` page to be.

---
Tags: panels
---


# Question
Title: Equivelant of node_type_load() for entity bundles
If I know the entity type and bundle, I want to load the bundle object with its settings. Drupal core has this for nodes, but is there any way to do it for entities?

See `node_type_load()` in core: https://api.drupal.org/api/drupal/modules!node!node.module/function/node\_type\_load/7

**EDIT:** So to elaborate, I'm asking about a way to load up the data about the entity bundle, not a specific entity.

E.g.

```
var_dump(node_type_load('page'));

object(stdClass)[628]
  public 'type' => string 'page' (length=4)
  public 'name' => string 'Page' (length=4)
  public 'base' => string 'node_content' (length=12)
  public 'module' => string 'node' (length=4)
  public 'description' => string 'Use <em>pages</em> for your static content.' (length=43)
  public 'help' => string '' (length=0)
  public 'has_title' => string '1' (length=1)
  public 'title_label' => string 'Title' (length=5)
  public 'custom' => string '1' (length=1)
  public 'modified' => string '1' (length=1)
  public 'locked' => string '0' (length=1)
  public 'disabled' => string '0' (length=1)
  public 'orig_type' => string 'page' (length=4)
  public 'disabled_changed' => boolean false

```

# Answer
You can use entity\_get\_property\_info() for example

```
var_dump(entity_get_property_info('node'));

```

Bundles are a keyed array within the result and they contain a keyed array of the fields and their settings.

Other information about the bundles other than field properties, such as menu callback etc, can be obtained using entity\_get\_info() where the bundles as keyed array within the result contains other non-field info.
> 1 votes

# Answer
I guess I am not 100% sure what you need here. However, as nodes are entities there will be a way to load other entities. You have entity\_load for example. If this is not what you need could you elaborate?
> 0 votes

---
Tags: entities
---


# Question
Title: Pager doesn't work in views block if views php field is used
I have a views block that shows nodes in some conditions. The views has pager and normally it works but if I use **Global: PHP** field the pager doesn't work and it only show the first page.

The Global: PHP field is as below:

* **Value Code**: *emtpy*
* **Output Code**:

-\>

```
<?php if ($row->type == 'book') { ?>
        <i class="fa fa-book fa-lg fa-fw"></i>
<?php }
elseif ($row->type == 'article') {
?>
        <i class="fa fa-file-text-o fa-lg fa-fw"></i>
<?php }
elseif ($row->type == 'thesis') {
?>
        <i class="fa fa-graduation-cap fa-lg fa-fw"></i>
<?php } ?>

```

---

### UPDATE:

I'm listing the nodes in this views block. There are 3 different content types and what I want to do with this PHP field is to print an icon according to content type. The code checks the content type with `if ($row->type == ...)`.

*(End of update.)*

---

**The PHP field works correctly and gives what I want but I wonder if I do something wrong in the PHP structure.**

Do you have any idea what can cause this problem?

# Answer
> 2 votes
There is a patch for that: Pager disappears when Global: PHP used in Views 3.8

> After upgrading from Views version 7.x-3.7 to 7.x-3.8, the pager was missing from all views that used Global: PHP fields.

If patch#6 does not work for you, just follow the links in comment#27

# Answer
> -1 votes
For one thing I know Drupal does not like ending php tags '`?>`' at the end of pages and no start or ending tags in most PHP fields I have seen. If that is not the issue can you put up an image of the field from the edit screen it might help to better understand what you mean?

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


# Question
Title: Modify the image preview area after upload in Drupal 7
I am new to Drupal. I wanted to have table less render view of images after upload at editing window. I found lots of help content, but they are hard to understand. Currently i have following view:

But i need following view with drag-n-drop sorting facility:

I am using File Resumable Upload to upload images. Can anyone tell me what i should do.

# Answer
> 0 votes
You can use Draggable Views. For content view displays you have to use a display and a sort block. Pointers can be found here.

**Edited 'here' link**

# Answer
> 0 votes
Firstly, the module 'views' that you tagged in your question won't be interacting at the edit stage unless you have something else in play that you haven't mentioned.

This sounds like a primarily CSS question... since you need the display altered at the edit stage, you should be able to tinker with the css to change the effected classes and id's to suit your display needs.

Also, if you don't intend to use the alternate text, you should be able to remove that directly from the field management screen.

---
Tags: views, 7, media, files
---


# Question
Title: Set from e-mail address for new user registration only?
In Drupal 7, it's quite easy to change the body of the emails here:

```
/admin/config/people/accounts

```

However, it has no place to set the "from" email address. I'm getting lots of spam signups and want the from email address to be "noreply@mysite.com", so as to make any responses get disgarded.

Any idea how to do this? Or even what email address is set for these emails?

# Answer
You can use `hook_mail_alter()` to change the "from" email address of any email sent out from your site. Your code would look something like...

```
function yourmodule_mail_alter(&$message) {
  $message['from'] = $message['headers']['From'] = '"Full Name" <noreply@mysite.com>';
}

```

Also, keep in mind that just setting the "from" address may not have the desired results in all email clients (see the discussion on the Drupal issue queue). You might also need to set "sender", "errors-to" and "reply-to" based on your requirements. Those values are in the "header" of the `$message` variable from the code sample above.
> 0 votes

# Answer
First off... if you haven't already, take a look at:

captcha and reCaptcha

> A CAPTCHA is a challenge-response test most often placed within web forms to determine whether the user is human. The purpose of CAPTCHA is to block form submissions by spambots, which are automated scripts that post spam content everywhere they can. The CAPTCHA module provides this feature to virtually any user facing web form on a Drupal site.
>
> Uses the reCAPTCHA web service to improve the CAPTCHA system and protect email addresses.

plus a dozen or more other spam protection modules. I found these are very effective at elminating the bots.

Also, take a look at User IP Log

> User IP Log is a simple module that logs the IP address of users on login event to table {uiplog}.

with this you can block the ip addresses of known spammers - it takes some time but in the long run has a profound effect.

You could also set the default email address for the site to noreply@site.com which will make all system emails appear from that address, and then use something like Contact Forms which if memory serves will allow you to set the sender address for different contact forms.
> 0 votes

---
Tags: users
---


# Question
Title: one view for each term or one view for all terms
I have a vocabulary that contains terms and child terms, I would like to create a view to show the content of each child term.

```
Parent Term 1 > Child Term A
              > Child Term B
Parent Term 2 > Child Term C
              > Child Term D

```

So do I have to create 4 views for child terms (A, B, C, D)? Or I can create one view that show each child term in its page? and if it one view how to define path for them?

# Answer
> 0 votes
You just need to define the views path like `taxonomy/term/%`. It will override all the terms path automatically.

---
Tags: 7, views
---


# Question
Title: How do I Import users in the database without re-hashing the password
I want to import users from one database to another, without changing password.

Suppose the password is saved as $S$DfAoLR.OJWl04tkzgnZeE3TdJHlz6NxBNpArOKhQAewyyHDFDD in the database; I want to save the same value in the database of the other site.

Can anyone suggest me how to achieve this?

# Answer
Do this :

```
<?php
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
$old_hash = md5('password');
$hash_count_log2 = 11;

$new_hash = user_hash_password($old_hash, $hash_count_log2);

if ($new_hash) {
  // Indicate an updated password.
  $new_hash  = 'U' . $new_hash;
}
?>

```

or you may check LINK1 or LINK2

Or you can directly import the data from one table to another :

```
INSERT INTO NewTable (ID, Name, Password)
  SELECT ID, Name, md5(Password) AS Password
  FROM OldTable
  WHERE ID BETWEEN 100 to 300

```

Check **LINK** once.
> 1 votes

---
Tags: 7, users, importing-exporting
---


# Question
Title: I would like to duplicate the default product layout grid in a Commerce Kickstart2 site
thanks for looking at my post!

I have a Drupal7 Commerce Kickstart2 site. I recently cloned the default products page so I can create a new page with the same layout. It worked great except that the product grid that displays on the original default products page doesn't show up on my new page. Instead I have a page where the products just list vertically. How do I fix that?

Here are the links to the two pages:

https://www.subcitizen.com/products

https://www.subcitizen.com/ames-bros-m-12.html

Thanks so much for any and all info! I really appreciate it!

Jason

# Answer
It's because the CSS for the list elements is not being applied

```
display: inline;
float: left;
min-height: 380px;
height: auto;
margin: 0;
padding-right: 5px;
padding-bottom: 30px;
width: 230px;

```

So you need to change the CSS selector so that it does apply.

I think that isn't the right answer though, instead of duplicating the template I think you should edit the view so that it shows your brand pages with the brand info at the top rather than put it in the template (if that is what you're doing). It'll take a while to work out but the site will be much easier to maintain over time.
> 1 votes

---
Tags: commerce, theming
---


# Question
Title: Inline images of body is not getting migrated
I am migrating a drupal6 site to drupal7. I am using migration and migrationd2d\_ui module for this. Everything is working fine except wysiwyg inline images in body. path is getting migrated for wysiwyg images . But in content \[\[wysiwyg\_imageupload:15:\]\] is appearing. In drupal 6 wysiwyg with tinymce editor is running. I am using same wysiwyg with tinymce editor in drupal 7. In drupal6 wysiwyg\_imageupload module was used for inilne images in body.

How can i migrate these images in drupal 7 ?

# Answer
Looks like the Drupal 6 site which you are wishing to migrate was using the wysiwyg\_imageupload module for uploading the images to the content region.
If you have a look at the Repository viewer of the module, you'll see that the module defines certain input filters : `Drupal Wiki inline images` to be precise which converts the images saved in format `[[wysiwyg_imageupload:15:]]` into the real path when the page is rendered.

To resolve this, you'll have to implement the prepare function and *actually* change the value of the content and replace the filter formats with src and then run the migration.
> 0 votes

---
Tags: migrations, wysiwyg
---


title: How to create new field type

text:
# Question
Title: How to create new field type
I'd like to create a new field type that can be attached to content (ie an article) via the admin interface through 'manage fields' of the content type. I am unsure of the process and required hooks to achieve this.

At this point I'd like the field to be nothing more than a simple text field. So far I have defined the field in:

```
hook_field_info
hook_field_schema (in .install file)

```

What other hooks do I need to get this to: a) appear in manage fields options. b) appear in the content editor for the content it has been applied to.

Many thanks

# Answer
> 11 votes
When I did this a while ago I adapted the excellent `field_example` module from the Examples Module which is always the first place to look, as it has a lot of Drupal best practice in it.

As they say in the module comments:

```
     * Providing a field requires:
     * - Defining a field:
     *   - hook_field_info()
     *   - hook_field_schema()
     *   - hook_field_validate()
     *   - hook_field_is_empty()
     *
     * - Defining a formatter for the field (the portion that outputs the field for
     *   display):
     *   - hook_field_formatter_info()
     *   - hook_field_formatter_view()
     *
     * - Defining a widget for the edit form:
     *   - hook_field_widget_info()
     *   - hook_field_widget_form()

```

So, not for the faint hearted, but as others have said, all the information is there to get you started.

# Answer
> 0 votes
Many blog-tutorials exist that explain step by step how to setup a module that creates a custom field type. Besides the articles that Djouuuh suggests, I think this one exactly describes the (basic) functionallity that you ask (i.e., just a widgit with a text field).

---
Tags: 7, entities, hooks
---


title: Default image only for view

text:
# Question
Title: Default image only for view
I know that I can set default images for content types, but for my page, I would like to only display the default image for one particular view and not the other ones.

It would also be nice if the image is automatically displayed in the proper image style just like a regular image. Therefore it seems that I can't use "no results behavior" since there, I would have to specify the full html myself.

So can I somehow tell drupal 7 to use a default image for a view in case there is no image for an article such that it does not affect any other views?

# Answer
> 2 votes
Assuming you are working with the default `Article` content type of Drupal 7.x

You should add something similar to this in your **NO RESULT BEHAVIOUR** of your **IMAGE** field in your **VIEWS**

# Answer
> 1 votes
Add custom text in that particular view & fetch the image by using html code. Try this, this can 100% solve your query.

---
Tags: views, media
---


# Question
Title: How do you make Varnish cache update when Drupal content changes?
I just started playing with Varnish cache. Looks like an awesome thing to have for speeding up page load times!

How does one force the cached copy of a node/page/content to be updated when the content changes in Drupal? Would it be something in the VCL file? I am using the VCL from Four Kitchens.

# Answer
> 0 votes
There are many ways to achieve this. A very common way is by using the Expire module (https://www.drupal.org/project/expire).

It can easily be configure to clear specific pages, or sets of pages from varnish when they are changed. It has been well documented and is up to date, a great module and does exactly what you require.

---
Tags: proxies
---


# Question
Title: Send email to specific users when Webform submitted
How can I send emails to specific user roles when a specific Webform is submitted?

For example if a Webform named test is submitted then we have to send email to all users having the role say 'editor'.

# Answer
This could be done by combining Rules and Webform Rules Modules

In Rules Module You could use the following Settings:

**Events:** `After a webform has been submitted`

**Conditions:** `User has role(s)` and `Webform has name` (to apply for particular webform)

**Actions:** `Send HTML e-mail`
> 2 votes

---
Tags: 7, rules, webforms
---


# Question
Title: Change drupalsite/user to drupalsite/customadmin
Currently to login as an admin I need to navigate to the URL `http://drupal.mysite.com/user` and then I am logging in with userid **admin**.

I want to change the `user` part of the URL to my own custom URL containing `customadmin`, so that I can navigate to my login page with URL `http://drupal.mysite.com/customadmin` (instead of URL `http://drupal.mysite.com/user`).

I know there are some core file that can be changed to do this, like:

```
'H:\xampp\htdocs\mydrupal\modules\user\user.module'

```

I.e by modifying the hook menu for login like so:

```
/**
   * Custom menu for login
   */
  $items['customadmin'] = array(
    'title' => 'User account',
    'title callback' => 'user_menu_title',
    'page callback' => 'user_page',
    'access callback' => TRUE,
    'file' => 'user.pages.inc',
    'weight' => -10,
    'menu_name' => 'user-menu',
  );

```

But I wonder if there is some other way to do this (instead of making changes in core files, which is not recommended of course).

# Answer
> 8 votes
Do not edit core files (ever).

You can do this without code by setting a path alias for the /**user** path.

Go to **admin/config/search/path/add** and add the alias *customadmin* for existing path *user*:

Now if you go go to /customadmin you will see the login or user page. If you want to ensure that that the /user path also redirects to /customadmin, just enable the Global Redirect module (no configuration needed).

---
Tags: 7, users
---


title: Dates and rules

text:
# Question
Title: Dates and rules
I've got a rule with php condition. I'm trying to compare 2 dates. the problem comes from the node date.

Here is a part of my script:

```
$date= date("Y-m-d");
$node_date= ("[node:field_event_date]");

$myDateTime = DateTime::createFromFormat("Y-m-d H:i:s", $node_date);
echo $myDateTime->format("d-m-Y");

```

I would like to convert my date and time to a different date format (d-m-Y was set on purpose to test the script, but eventually the format would be Y-m-d).

The date i'm pulling out has this format: yyyy-mm-dd H:i:s (i did an echo $node\_date ) but i can't convert it using "createFromFormat". Even though when i enter a date with the same format that "$node\_date", instead of the variable, it works...

So i don't really know any more what to do...i feel i got the solution, but cannot make it.

Thanks for your help

# Answer
I don't know if my solution is actually going to help, but I had a similar issue not with the node date but with a date field in a content type.

For some reason I was not able to properly expose the date field for comparison, and there are some slightly relevant issues about this in Rules issue queue. So what I did was to expose the field using the Views Rules module.

Although this is just a work-around really, with a performance penalty, it turned out to me that with this way the exposed field could then be used directly in comparisons.
> 0 votes

---
Tags: rules
---


# Question
Title: Splitting existing feature into several smaller. Safe?
I have this really big feature where all CT, fields, views etc are exported. As far as I understand it makes sense to make it into smaller features, more context specific, like features\_views, features\_fields, features\_CT etc.

The big feature is already enabled in production, is it safe to disable it and enable the other 3? Which approach should I follow?

# Answer
## Direct Answer

If you take the appropriate precautions, and **test locally first**, it should be safe to break up the feature.

## Background

If you want to split the big feature up, you need to make ensure that disabling the features does not affect the configuration of your site. Then you can disable the feature and use features to carve up the config differently and export as smaller component features.

I understand your point that one big feature is not that useful, as the individual components are not then transferable via features to other sites (or from dev to production), which is one of the uses of features.

I agree with letharion that it makes much more sense to divide your features along the lines of functionality (eg blog, gallery) rather than along modular lines (eg views, fields) otherwise all of your features will be interconnected anyway, in that disabling one will break dependent functionailty on the site. For example if I export a content type in one feature, and a view using that content type in another, then I would have to declare that the views feature is dependent on the content type feature. Functional features are also easier to document sensibly in version control.

## Method

*I have taken solution from my own previous comment on d.o*

You can use the **Features Tools** module to disable a module while leaving functionality in place. You can then re-export your config as smaller features.

* First BACKUP YOUR DATABASE
* backup your feature (files) if you would like to use it again.
* Install **Features Tools**, go to the 'recreate' page for a feature, uncheck all of the features components
* Now click on the 'Safe autocreate' button to recreate and replace the feature with an empty version.

You can now disable the module without affecting your site configuration. These instructions are for D7, if you are using D6 there is an extra step.

See ftools project for more complete documentation.

http://drupal.org/project/ftools

PS - unchecking all the boxes in the features ui is much quicker if you install a browser plugin like check all first.
> 2 votes

---
Tags: features
---


title: Custom search form

text:
# Question
Title: Custom search form
I am currently printing the search from like this:

```
$block = module_invoke('search', 'block_view', 'search');
print render($block);

```

Wich generates:

```
<form action="/sescam/" method="post" id="search-block-form" accept-charset="UTF-8">
    <div>
        <div class="container-inline">
             <h2 class="element-invisible">Search form</h2>

            <div class="form-item form-type-textfield form-item-search-block-form">
                <label class="element-invisible" for="edit-search-block-form--2">Search</label>
                <input title="Enter the terms you wish to search for." type="text" id="edit-search-block-form--2" name="search_block_form" value="" size="15" maxlength="128" class="form-text" />
            </div>
            <div class="form-actions form-wrapper" id="edit-actions">
                <input type="submit" id="edit-submit" name="op" value="Search" class="form-submit" />
            </div>
            <input type="hidden" name="form_build_id" value="form-NhLKDp33kDMoJjHqw6gDFJw_A_Kp7Dhvrt_w0V-jk6U" />
            <input type="hidden" name="form_token" value="e9aNbw3gz2mWvZUSdjl54aXTlesQsNkn7cGSXVMpoWI" />
            <input type="hidden" name="form_id" value="search_block_form" />
        </div>
    </div>
</form>

```

The thing is that I would like to customize a little bit this html output,

How can I Do so?

-EDIT-

I tried to add this to my template.php

```
function my_theme_form_search_form_alter (& $form, & $form_state)
{
  print_r($form);
  print_r($form_state);
}

```

The thing is that those `print_r` won't output anything,

Anhy idea?

thanks!

# Answer
> 2 votes
You're implementing `hook_form_FORM_ID_alter()`, to which you're providing `search_form` as the ID - if you look at the markup for the form you can see the ID should be `search_block_form`, so your function should be:

```
function MYTHEME_form_search_block_form_alter(&$form, &$form_state, $form_id) {
  // Make changes
}

```

To find out the ID of a form, you can temporarily implement the standard `hook_form_alter()`, and put the ID out to the screen:

```
function MYTHEME_form_alter(&$form, &$form_state, $form_id) {
  drupal_set_message($form_id);
}

```

Just as an aside, don't rely on seeing anything from `print_r()` \- because of output buffering you may or may not see it. To debug Drupal, install the Devel module, and use the `dpm()` function to inspect vars.

# Answer
> 2 votes
Just create a file `search-block-form.tpl.php` and put it inside your template folder.

Paste the following code into your file.

```
<?php

/**
 * @file
 * Displays the search form block.
 *
 * Available variables:
 * - $search_form: The complete search form ready for print.
 * - $search: Associative array of search elements. Can be used to print each
 *   form element separately.
 *
 * Default elements within $search:
 * - $search['search_block_form']: Text input area wrapped in a div.
 * - $search['actions']: Rendered form buttons.
 * - $search['hidden']: Hidden form elements. Used to validate forms when
 *   submitted.
 *
 * Modules can add to the search form, so it is recommended to check for their
 * existence before printing. The default keys will always exist. To check for
 * a module-provided field, use code like this:
 * @code
 *   <?php if (isset($search['extra_field'])): ?>
 *     <div class="extra-field">
 *       <?php print $search['extra_field']; ?>
 *     </div>
 *   <?php endif; ?>
 * @endcode
 *
 * @see template_preprocess_search_block_form()
 */
?>
<input type="text" id="edit-search-block-form--2" name="search_block_form" value="" placeholder="Search..." size="15" maxlength="128" />
<input class="button" id="edit-submit" name="op" value="GO!" type="submit" />
<?php echo $search['hidden']; ?>

```

Edit the code as you wish. Just make sure to leave `echo $search['hidden'];`.

You can find the original template in `YOUR-WEBSITE/modules/search/search-clock-form.tpl.php`.

---

On a side note: Instead of using `print_r()`, install Devel module and use `dpm()`. It's a lot better and is not visible to visitors.

# Answer
> 1 votes
You can simply use the `hook_form_alter` as mentioned below.

Here is the code to be used in the theme's `template.php` file that will override Drupal's search form.

```
<?php
function theme_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'search_block_form') {
      print_r($form);
  print_r($form_state); // Code here

 }
}
?>

```

Either way if you are working within your custom module. It will be used as

```
<?php
function MODULENAME_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'search_block_form') {
      print_r($form);
  print_r($form_state); // Code here

 }
}
?>

```

Hope, it will work for you!

---
Tags: 7, search
---


title: Total sum using view php

text:
# Question
Title: Total sum using view php
I have two footers in a view page with the sum results from View Aggregate Plus (VAP). The last row is the sum result.

> footer A:
> var A
> 10
> 20
> 30 (sum result from VAP)
>
> footer B:
> var B
> 25
> 30
> 55 (sum result from VAP)

I would like to sum the results of footer A and footer B *(Total =20 + 30)*, using global php (module view php).

The available variables below:

What is the output code to get the total summation result ?

# Answer
What you are trying to do is to use module in alpha version (bad practice) that keeps PHP code in database (very, very bad practice) for task that can be accomplished by modules without these flaws, like Views Calc, Views Aggregator Plus or even built-in aggregation.

My current favourite is Views Aggregator Plus:

> In addition to what Views and Views Calc do, this module:
>
> * enumerates group members
> * produces tallies, i.e. textual histograms
> * aggregates on Views PHP code-snippet evalutations
> * can filter out result rows on regexp patterns
> * gives you sorting on Views' Math expressions
> * can process Webform submissions
> * lets you add your own custom aggregation functions

And example on it's page is quite similar to what you want to accomplish here.

For a whole table sum, just add *Global: mathematical expression* column to sum values in row, and then Views Aggregator Plus to sum that column. Column may be hidden, for example with CSS.
> 3 votes

---
Tags: views
---


# Question
Title: How to display author name and post date in entity view page?
I am using Entity Construction Kit module.

# Answer
> 0 votes
1. Go to Structure
2. Select Content type
3. Click on the tap Display settings and unchecked Display author and date information

---
Tags: entities
---


# Question
Title: How to create widget element with unlimited values?
I have a widget for a field as shown below:

I would like to make the text field ('script\_paths') an unlimited value so that the user can add as many as they like. Is there a way to do this? Maybe there is a property I add in my code below:

```
function mango_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {

  $field_name = $instance['field_name'];
  $required = $element['#required'];
  $item =& $items[$delta];
  $element += array(
    '#type' => 'fieldset',
  );

  $element['enabled'] = array(
    '#title' => t('Enabled'),
    '#type' => 'checkbox',
    '#default_value' => isset($item['enabled']) ? $item['enbled'] : '',
  );

  $element['script_paths'] = array(
    '#title' => t('Script Paths'),
    '#type' => 'textfield',
    '#default_value' => isset($item['script_paths']) ? $item['script_paths'] : '',
  );

  return $element;
}

```

# Answer
I would think that there would be a property as well but I can't think of one for text fields. I know that you can use field collections though.

**Edit:** I was mistaken Field Collections will not work for custom forms, however This tutorial worked for me.
> 2 votes

---
Tags: 7, entities
---


# Question
Title: What are the implications of removing define('VERSION', '7.34'); from database.inc
I do not want to advertise what version of Drupal I am running. I want to remove the line:

`define('VERSION', '7.34');`

What are the downsides to doing this other than the site not knowing it's own version of Drupal and messing up updates etc...

Note: I am also removing other txt files from the site root that show the version as well. I also know that there is no way to 100% hide this. I just want to know what the implications are for removing the item above.

Edit: I appreciate everyone's input on this issue. I totally agree that security through obscurity doesn't work. However, we all have had that client that thinks they no better than us and requests stuff like this. It's unfortunately the client's site and I have tried educating him. That being said, if he wants to drive his car 100,000 Km without doing an oilchange than that's his choice and he can live with the consequences. So, I just need to know if manually changing this is going to mess me over as the developer or is it something I can do just to make the client happy and move on?

# Answer
Other than to people that have access to the admin interface, Drupal doesn't advertise sub-version numbers.

The only front-facing way to determine the drupal version information is from the "X-Generator" header which is returned by the server with every request. For drupal version 7, the text returned is "Drupal 7 (http://drupal.org)" This header can be easily removed by adding the following to your .htaccess file:

```
Header unset X-Generator

```

If you're looking to keep your sub-version information a secret, be sure all the readme and non essential .txt files in your root **and in your modules folders** are hidden.

Removing the version definition as you stated can cause problems across core and many modules. Not recommended.

This is also a good read. TL;DR- don't even worry about your version information not being hidden.
> 1 votes

# Answer
it will be fine if you remove the txt files, also it's a good security practice; However removing the version constant will cause a lot of problems, it used it many places, removing it might lead to big issues.
> 0 votes

---
Tags: bootstrapping
---


title: Using MS SQL 2008

text:
# Question
Title: Using MS SQL 2008
I have been pounding my head against the wall on this for a while, and I am about ready to give up.

I have been tasked with installing Drupal 7.27 on a Red Hat Enterprise Linux 5 server, and use a MS SQL 2008 R2 database.

I have installed freetds, and was able to successfully create a test php file that connected to the database and returned information. I was also able to connect to the database using:

```
tsql -H hostname -p port -U username

```

I am using the dlib module for Drupal, and when I go through the steps to install I get all the way to selecting the database type and entering in the username and password. MS SQL Database is listed as an option, and I have verified all neccessary information (database, username, password, etc.). When I click save and continue I recieve this error:

```
SQLSTATE[HY000] Unknown host machine name (severity 2)

```

Has anyone been able to successfully install Drupal on a Linux server with MS SQL as the database?

Any advice would be greatly appreciated.

---

UPDATE

---

Drupal is connecting to the database, and creating all of the neccessary tables, but cancels the setup process saying that the tables are already created... Well duh! It created the tables! So We are a little further along, but still not quite there.

Thoughts?

# Answer
The FreeTDS logs always have some answers. Try looking at it. It has helped me to find a reason why I am not able to move ahead with my Drupal installation on Linux and connecting it to SQL Server via FreeTDS.

It starts the process, creates 8 tables and then stops: the page was reset.

I looked in FreeTDS logs and profiler trace that it tried creating an index on table date\_formats and failed because it found ANSI settings off. I don't know how to set it on now, if it is a Drupal issue or ODBC or FreeTDS.
> 1 votes

---
Tags: database
---


# Question
Title: how can I install Drupal 7 with PHP 5.2 on a Windows Server 2003 machine with IIS 6.0 and SQL server 2000 running on it?
What I have:

> 1. Drupal 7.0
> 2. PHP 5.2
> 3. IIS 6.0
> 4. SQL server Enterprise Manager 2003
> 5. SQL server 2000 running on local system(my database is on the same system.)
> 6. Windows Server 2003.(makes any difference?)

I am using VPN to connect to the production system.(relevant?)

> 7. I have added the Microsoft SQL Drivers 2.0 to the php/ext folder.
> 8. I have added the sqlsrv module to the database\includes as well.

Got the option to install Drupal to sql server which was the only option by default in this case (got a message that my server does not support multiple databases hence sql server was selected by default).

I have the following fields available to me in the database setup:

> The values I have entered are in \[\]:
>
> 1. database type:radio button (selected by default--microsoft SQL server)
> 2. database name: \[database\_name\]
> 3. database user name: \[user\_name\]
> 4. database password: \[password\]
>
> Advanced options:
>
> 1. hostname: \[localhost\]
> 2. port: blank
> 3. prefix: blank

I get an `SQLState[20008]:SQL server native client [10.0] error: can't login.`

what are the possible reason for not being able to connect?

# Answer
I am not sure why you are using SQL2000 in 2014 because it is not supported anymore. I have successfully connected to SQL 2008 version using SQLSRV module in Drupal.

I would do the following in this case:

* Make sure TCP\IP protocol is enabled and it is listening on some port which is not getting blocked by firewall.
* I would try connecting to the database server using IP address and port using enterprise manager first.
* I would look in my SQL error logs because it records the authentication failures there.

Please share what you observe.

Thanks C
> 0 votes

---
Tags: users, iis, database
---


title: Date exposed filter default value

text:
# Question
Title: Date exposed filter default value
I've got exposed date filter (with daily granularity) and I want to provide default value for it. I just want to show nodes that have today 'field\_date' date by default. The field has both start and end date. I use start date for exposed filter.

How can I achieve it?

# Answer
This can be done through contextual filters in views.

Navigate to edit the structure of your view, click advanced and add a contextual filter. Here you will select the date field and "Apply"

On the next page, under "WHEN THE FILTER VALUE IS NOT IN THE URL" you want to "Provide default value" of type "PHP Code". The code you want to use is fairly simple, but depends on your date/time setup. you should have something like this in the php code field:

```
return date("Y/m/d");

```

Good Luck!
> 0 votes

---
Tags: datetime, views
---


# Question
Title: Does install.php open a connection with ANSI ON?
Please accept my warm regards . I need some guidance and light to move ahead.

I am from SQL Server background and has been doing some work on Linux machine offlate and making it connect with SQL Server. I have succesfully installed FreeTDS and can connect to Windows SQL Server machine. Now, I installing Drupal in Linux and during its installation it creates multiple tables in the database.

After creating few tables it quits. I traced and found that it stopped because it needed ANSI settings ON to create an index on the table date\_formats but found it off. I cannot set it at my DB because it chooses the client settings at the runtime.

I am not sure if Drupal install.php opens a connection with ANSI off settings because this causes the index creation to fail. Please help to investigate it.

Regards Chandan Jha

# Answer
If you look in database.inc for your database driver you can see what parameters are passed from drupal on the default connection. If you apply this patch to drupal8 you can set additional `PDO` options supported by the driver https://www.drupal.org/node/1926284
> 0 votes

---
Tags: database
---


# Question
Title: From single site to multi site of an existing site broke all pages images
I had a single site that is running in prod. We wanted to use the multi site feature of Drupal 7 because a few site will be using the same core code. So I moved the default/files/ to mysite.com/files like it was suggested. I created a settings.php that point to my existing DB. Everything worked fine until I reach a page that was created from the CMS and pointed to images in the default/files/ folder.

I understand that somewhere I need to change the image source paths from default/files to mysite.com/files but I can't find where. I find a lot of examples like this one stating that I need to run a sql script in the files table. The thing is, there is no files table... I figure it must be for Drupal 6 or older. I am on Drupal 7 and can't find where to change the images path. I found a table called file\_managed which looks like the right place but all uri are ex: public://folderUnderFiles/image.png. There must be a way to change the public:// to point to my new folder!

# Answer
I reckon that the paths which are stored in the database refer to the old url. In such case, you need to run a SQL command inside MySQL that corrects the paths.

To fix entries inside **field\_data\_body** table, you can run this command:

```
UPDATE field_data_body SET body_value = REPLACE(body_value, 'sites/all/files', 'sites/mysite.com/files');

```

You have to do the same for the corresponding revision table.
> 0 votes

# Answer
you can find the public folder information under mysite.com/admin/config/media/file-system

there you can change the folder contained in public, so that the token is directed to the correct folder in the database
> 0 votes

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


# Question
Title: Access denied for admin page, after moving site from sub-folder to root folder
Not able to access administration site after moving files from sub-directory to root folder.

With the help of google search, I have made below changes in settings.php under default folder, but that also didn't helped. $base\_url = 'http://example.com'; //Changed to site name

Actually base\_url is commented in my settings.php file, I have tried enabling it.

Drupal version: 7

# Answer
> 0 votes
Got it! I was using url as ?q=admin instead of ?q=user url.

---
Tags: commerce, 7
---


# Question
Title: Remove labels in printer friendly version of books
Is there any way to remove labels or apply a CSS file to the printer-friendly version of books?

# Answer
Here is how I approached the problem: Copied

```
/modules/book/book-node-export-html.tpl.php
/modules/book/book-export-html.tpl.php

```

to my theme directory and modified the *$contents* variable via str\_replace.

This works fine as a temporary fix, but I guess performance-wise this is not the best solution, would would be still nice to find a way to apply CSS.
> 0 votes

---
Tags: nodes, entities
---


# Question
Title: Display default image if the image isn't set
**Case**

* A custom image field has been added to the `user entity`, this field contains a default image for users, which should display if an user doesn't add an image. This field is used on multiple templates across the site.

**Problem**

* Only at the user's profile page is the default image displaying when the image is not set (if set will show the image).
* Node templates and other entities will not display the default image. I tried to display the field with `theme_image()` with no success.

**Question**

* Why won't it display the default image?

When I dump the information about the fields attached to the current user, the field\_picture is an empty array if the user has no image set. When the user does have an image set it will return this

**Setup**

* Field name: `field_picture`
* Field type: picture
* Field module: default image field module.

# Answer
> 0 votes
try: make sure in the field settings you have set BOTH default images. There is one specific to that instance of the field, and one everywhere else it is used. The second is further down the screen:

IMAGE FIELD SETTINGS

These settings apply to the Image field everywhere it is used.

---
Tags: theming, media
---


# Question
Title: Is there a filter/search option available for navigating the 'Find Content > Files' page?
I have a site with thousands of files uploaded, and Drupal's admin view doesn't seem to offer a comprehensive filter for the Files view like it does with the Content view.

There also apparently isn't the option to search the files either.

**Files view:**

Is any such filter or search option available? This would make updating files 10 x faster!

# Answer
The best thing to do here is create a custom VBO view to suit your needs! It can have all the filters and sortable columns you want, and ... checkboxes so you can perform actions on the selected items.

See a guide here for using Views Bulk Operations.

Don't forget to set the views access permssions as you want to create an admin only vbo view !
> 0 votes

---
Tags: nodes, search, files
---