# Question
Title: "drush make" is unable to determine the MIME type
On every .js library that needs to be downloaded, I keep getting errors like the following one.

> https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js. Unable to determine mime type for jquery-ui.min.js\`

I've read posts like Make fails to identify mime type of json2.js (identified as .tar) that describes a similar issue, but I can't figure out where to install the patch file since I'm getting errors and nothing ends up being installed or moving past the download fase.

I've found that with more simple make files, if I just get rid of the libraries that are requiring the .js file, I can get through everything without errors, and it will actually install. However, I really need to solve this problem because I need these libraries.

I'm currently using Drush 6.0 and I've installed all of the stuff that was reported in how to prepare mediafront\_demo installation, but I had to comment out media\_module and file\_entity stuff.

I'm using Windows 8 and the mysysgit (mingw32) for my prompt.

I created a smaller test.make file to try and debug this. It has only the latest Drupal 7 core and libraries for html5bp, jquery, and jqueryui. html5bp seems to be downloading fine.

These are the libraries handled by the .make file.

```
libraries[html5bp][download][type] = "file"
libraries[html5bp][download][url] = "http://github.com/h5bp/html5-boilerplate/zipball/v3.0.2stripped"
libraries[jquery][download][type] = "file"
libraries[jquery][download][url] = "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
libraries[jqueryui][download][type] = "file"
libraries[jqueryui][download][url] = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"

```

I ran it with `--debug` and this is what I get. (I've omitted the first half to keep it short because everything with the core is working fine already.)

```
Returned from hook drush_pm_download
Command dispatch complete
Peak memory usage was 9.21 MB
drupal-7.x-dev downloaded.
Undefined property: DrushMakeProject_Library::$type make.project.inc:147 Executing: wget --version
Calling is_writable(C:/Users/jsmith85/AppData/Loca/Temp/make_tmp_1400527562_537a5acaaa72d)
Calling rename(C:\Users\jsmith85\AppData\Local\Temp\dowFB52.tmp, C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72dv3.0.2stripped)
html5bp downloaded from http://github.com/h5bp/html5-boilerplate/zipball/v3.0.2stripped.
Examining C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/v3.0.2stripped headers.
Mime type for C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/v3.0.2stripped is application/zip
Examining C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/v3.0.2stripped headers.
Mime type for C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/v3.0.2stripped is application/zip
Calling chdir(C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d)
Executing: unzip C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/v3.0.2stripped -d C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509
Archive:  C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/v3.0.2stripped5f341a34e8a37b8deeb1f416fa2a7b8a0a78638a
  creating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/
  extracting: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/.gitattributes
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/.gitignore
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0
559509/h5bp-html5-boilerplate-359a13f/.htaccess
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/404.html
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/apple-touch-icon-114x114-precomposed.png
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/apple-touch-icon-57x57-precomposed.png
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/apple-touch-icon-72x72-precomposed.png
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/apple-touch-icon-precomposed.png
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/apple-touch-icon.png
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/crossdomain.xml
  creating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/css/
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/css/style.css
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/favicon.ico
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/humans.txt
  creating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/img/
  extracting: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/img/.gitignore
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/index.html
  creating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/js/
  creating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/js/libs/
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/js/libs/jquery-1.7.1.js
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/js/libs/jquery-1.7.1.min.js
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/js/libs/modernizr-2.5.3.min.js
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/js/plugins.js
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/js/script.js
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/readme.md
  inflating: C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f/robots.txt
Calling chdir(C:\wamp\www\fit3)
Calling drush_delete_dir(C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/__build__/sites/all/libraries/html5bp, 1)
Calling is_readable(C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f)
Calling is_writable(C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/__build__/sites/all/libraries)
Calling  rename(C:/Users/jsmith85/AppData/Local/Temp/drush_tmp_1400527621_537a5b0559509/h5bp-html5-boilerplate-359a13f,
C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/__build__/sites/all/libraries/html5bp)
Undefined property: DrushMakeProject_Library::$type                       make.project.inc:147 [59.42 sec, 7.53 MB]
Executing: wget -q --timeout=30 -O "C:\\Users\\jsmith85\\AppData\\Local\\Temp\\dow300.tmp" https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
  SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
  syswgetrc = c:\Program Files (x86)\GnuWin32/etc/wgetrc
Calling is_readable(C:\Users\jsmith85\AppData\Local\Temp\dow300.tmp)
Calling is_writable(C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d)
Calling rename(C:\Users\jsmith85\AppData\Local\Temp\dow300.tmp,
C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/jquery.min.js)
jquery downloaded from https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js.
Examining C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/jquery.min.js headers.
Unable to determine mime type from header bytes 0x2a2f of C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/jquery.min.js.
Examining C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/jquery.min.js extension.
Unable to determine mime type for jquery.min.js.
Calling is_readable(C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/jquery.min.js)
Calling is_writable(C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/__build__/sites/all/libraries/jquery)
Calling rename(C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/jquery.min.js, C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/__build__
/sites/all/libraries/jquery/jquery.min.js)
Undefined property: DrushMakeProject_Library::$type
make.project.inc:147
Executing: wget -q --timeout=30 -O "C:\\Users\\jsmith85\\AppData\\Local\\Temp\\dow4E5.tmp" https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js
  SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
  syswgetrc = c:\Program Files (x86)\GnuWin32/etc/wgetrc
Calling is_readable(C:\Users\jsmith85\AppData\Local\Temp\dow4E5.tmp)     Calling is_writable(C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d)
Calling rename(C:\Users\jsmith85\AppData\Local\Temp\dow4E5.tmp, C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/jquery-ui
.min.js)
jqueryui downloaded from https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js.
Examining C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/jquery-ui.min.js headers.
Unable to determine mime type from header bytes 0x2a2f of C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/jquery-ui.min.js.
Examining C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/jquery-ui.min.js
extension.
Unable to determine mime type for jquery-ui.min.js.
Calling is_readable(C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/jquery-ui.min.js)
Calling is_writable(C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/__build__/sites/all/libraries/jqueryui)
Calling rename(C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/jquery-ui.min.js, C:/Users/jsmith85/AppData/Local/Temp/make_tmp_1400527562_537a5acaaa72d/__build__
/sites/all/libraries/jqueryui/jquery-ui.min.js)
Returned from hook drush_make
Command dispatch complete
Peak memory usage was 9.38 MB

```

# Answer
In a successful run of `drush make`, the message may be:

> Mime type for /tmp/make\_tmp\_1403284094\_53a46a7e2ceaf/jquery.min.js is text/html

In the log you posted, `drush make` tries to examine the file headers to determine the file MIME type.

> Examining C:/Users/jsmith85/AppData/Local/Temp/make\_tmp\_1400527562\_537a5acaaa72d/jquery-ui.min.js headers.
> Unable to determine mime type from header bytes 0x2a2f of C:/Users/jsmith85/AppData/Local/Temp/make\_tmp\_1400527562\_537a5acaaa72d/jquery-ui.min.js.

This happens when PHP has no *fileinfo* extension and Drush tries to guess the MIME type with `drush_mime_content_type()`.

You can verify if the required extension is installed with `php -i | grep fileinfo`. If it's installed the output will be the following one.

> fileinfo fileinfo support =\> enabled

As for installation instructions, from the PHP's fileinfo installation page, Windows users must include the bundled php\_fileinfo.dll file in php.ini to enable the extension.
> 1 votes

---
Tags: drush
---


title: Translate menu with wildcard

text:
# Question
Title: Translate menu with wildcard
I am creating a menu item using `hook_menu()` and what I want is to translate it when I am using a wildcard, because I have a multilingual site.

There is a solution, using `t()`\[, but it's not the best approach.

```
$items['account/edit/%'] = array(
  'title'            => t('Edit account information'),
  'page callback'    => 'drupal_get_form',
  'page arguments'   => array('partners_add', 2),
  'access arguments' => array('edit account in partners'),
  'type'             => MENU_NORMAL_ITEM,
  'file'             => 'inc/partners.form.inc',
);

```

Does anyone know how to translate it using the Drupal interface?

Thanks in advance!

# Answer
> 0 votes
The point is moot, because the the `hook_menu` strings should not be translated at all. Your code should in fact be:

```
$items['account/edit/%'] = array(
  'title'            => 'Edit account information',
  'page callback'    => 'drupal_get_form',
  'page arguments'   => array('partners_add', 2),
  'access arguments' => array('edit account in partners'),
  'type'             => MENU_NORMAL_ITEM,
  'file'             => 'inc/partners.form.inc',
);

```

I quote from: http://drupal.org/node/323101:

> The Drupal 6 and 7 menu system stores menu item titles and descriptions in English. This allows the system to cache the data, but display to users using various languages on demand. For this to work, you should *not* use t() on the title or description of menu items in your hook\_menu() implementation.
>
> Again, we use plain English so that the menu system can store the English text and translate as required, benefiting performance. If, instead, we use t(), the menu system would store the menu item titles and descriptions in the language of the first visitor when the menu cache was rebuilt, which would not work as a base for translations on a multilingual site.

---
Tags: i18n-l10n, routes
---


# Question
Title: Link static HTML, Javascript and CSS3 in a Drupal Site
I am trying to have collaborative development of a HTML5 web app which people could navigate too through my drupal site. I was planning on putting the html, JS and CSS3 files in my sites/default/files folder and just passing a link. I am curious how i perform to things

How can I put an alias over the html file so i can have url mysite/demo also I want to block people from reading my JS and CSS3 files so the source code is just not purely out in the open is there a way to do this.

I know inspect html on most browsers give you a lot but I do not want them to find my .js file and then request that and have my source code.

Any assistance or guidance would be very helpful

# Answer
> 0 votes
I think the best option for what your describing is to take a screen shot of the site and use that; as an image will not display the html/css/js. https://www.drupal.org/project/phantomjs\_capture is the project I would use; this is a very odd request so in order to achieve this you'll have to do some custom coding.

If your looking to obfuscate the JavaScript by minification AdvAgg can help but it's not setup to fully obfuscate the JS as it will point to the source file by default (for GPL compliance). This could be changed; if you do decide to go down this route open up a request in the advagg issue queue and I'll add in a hidden option to allow this to happen.

---
Tags: javascript, theming, path-aliases
---


# Question
Title: Add execute button to Commerce POS modal?
I'm building a custom POS modal similar to the POS\_Button\_Modal\_View -based ones that present a view. I wrote a modal that presents a page from a given callback:

```
class POS_Button_Modal_Page extends POS_Button_Modal {

  public function modalPage(CommercePOS $pos, $js) {
    $form_state = array(
      'title' => drupal_get_title(),
      'build_info' => array('args' => array($pos->getState()->getOrder())),
      'ajax' => $js,
      'pos' => $pos
    );

    if (!$js) {
      return drupal_build_form($this->config['page callback'], $form_state);
    }

    $output = ctools_modal_form_wrapper($this->config['page callback'], $form_state);

    return $output && !$form_state['executed'] ? $output : FALSE;

  }
...

```

The modal displays my page as intended, but I don't know how to build a submit button that works like the buttons in the POS-provided views.

The view in, eg. the SetUser POS modal uses the commerce\_pos handler to render a button that executes the command:

```
class commerce_pos_handler_field_pos_command extends views_handler_field { ...

```

How can I build a submit button in my custom modal that executes my new command?

My command extends POS\_Command with my custom implementation of execute()

```
class POSCommand_MyCommand extends POS_Command {

  function execute(CommercePOS $pos, $input = '') { ...

```

It seems like a POS\_Button\_Command should be created and rendered in the modal. But how does that get connected to my command?

# Answer
> 0 votes
Instead of a regular "page" callback, implement the page as a form with an action (submit) button. When the form is submitted and validates, the modal will be released courtesy of the way `ctools_modal_form_wrapper()` works.

POS\_Command was not the right way to think about the problem in this case. POS\_Button\_Command is better suited to a simple, pre-defined operation as in setting the order user from a list of users. I was trying to do a more complex operation in the modal, gather some data from form inputs, then run some commerce commands on the order.

Short answer: The `POS_Button_Modal_Page` class works for loading a custom modal page. Implement the page as a form, and do the execution code in the form\_submit handler instead of using POS\_Command.

---
Tags: commerce
---


# Question
Title: Edit tabs and configure gears are missing on all content types in my drupal 7 website
How can I get my edit tabs and configure gears to appear? I switched themes and they appeared, but they just seem to not be working in the theme that I am now using.

Any ideas?

Thanks!

# Answer
> 0 votes
page.tpl.php needs $title\_prefix too. Add before the main (and the suffix after if you need to)

---
Tags: blocks
---


# Question
Title: How do I place thumbnails from videos in a views slideshow?
If the user doesn't give a thumbnail for the video in the slide show, I would like to generate a thumbnail from the video. I looked through questions and couldn't quite find what I was looking for. I am using Drupal 7. I am using the views slideshow module.

# Answer
> 0 votes
I found out that a few boxes were unchecked that I didn't know about. This link shows a good tutorial on this: http://webwash.net/tutorials/display-video-thumbnails-media-module

---
Tags: files, views
---


# Question
Title: How To Hook To Commerce Add To Cart Button After Add?
I'm trying to ask the same question in another way... hoping I can get an answer.

I have a function I need to trigger AFTER the product is added to the cart.

When I added a PHP function to a Pricing Rule it seems to execute -before- the product is added.

The Commerce website says that the a Pricing Rule may be triggered before or after the line item is added but I can't figure out how to do this.

# Answer
> 2 votes
You've got a rules event that fires when a product is added to the cart, which is called after the price calculation one, check commerce\_cart\_product\_add function.

It uses rules\_invoke\_all, which means that you can either run actions on this event or invoke the hook directly, `hook_commerce_cart_product_add` normally.

```
// Invoke the product add event with the newly saved or updated line item.
rules_invoke_all('commerce_cart_product_add', $order, $product, $quantity, $line_item);

```

---
Tags: commerce, rules
---


# Question
Title: Is Pathauto designed to modify URL requests?
I have configured Pathauto to redirect /node/23 to /resource/resourcename. Should it render menus as /resource/resourcename, or still /node/23? If a user requests /node/23, is Pathauto supposed to change the request to /resource/resourcename?

Currently, it does allow for /resource/resourcename to be used, but it does not actively change /node/23 if it is entered.

# Answer
> 1 votes
Pathauto only creates path aliases for nodes, users, etc. based on patterns, i.e. `/node/23` will also work with `/resource/resourcename`. However, no redirect is made. If you wish to redirect the node path to the path alias you could use the Global redirect module.

Once an alias is created all menus etc. will use the alias instead of the real path, in fact, all links created with the `l()` (`url()`) function.

---
Tags: path-aliases
---


title: Handling One-to-Many relationship view?

text:
# Question
Title: Handling One-to-Many relationship view?
I am trying to learn Drupal, and getting stuck every hour. I wish someone could walk me through this. I am trying to create a Employee-Company relationship. I have created a Company Content Type with just Name, Address and Telephone Numbers. And a Employee with Name and an Entity Reference to Company and multi-value Term Reference to skill set.

Now in my page skill/\[whatever\_the\_skill\_may\_be\] - I get a list of Employee. This happens automatically. Now I want to show the Company information along with each employee, but surprisingly can't seem to do this easily. I get the Company name which can be linked, but not the address or Telephone number.

Some of the pages I searched for the answer seem to suggest creating a View for this. I am not sure if I really need to, for such a simple requirement. But even if I do so, how do I override the default view of skill/\[whatever\_the\_skill\_may\_be\], and also the employee/\[name-of-employee\] page, where I would like to show the company information?

I hope I am not asking a stupid or very obvious question. Thanking u in advance,

# Answer
> 1 votes
Its simple, follow the steps.

1. Create a view of employees.
2. In the **Format** section show **fields** instead of **content**
3. Add the fields, Employee Name, Skill, Company Name
4. Add a **Contextual Filter**, `Content: Has taxonomy term ID`
    * Provide default value as **Taxonomy term Id from URL**
    * Select **Specify validaion criteria**
        + Select the validator **Taxonomy term** and choose your **vocabulary - Skillset**
        + In **filter value type**, select **Term name converted to Term ID**
5. Add a relationship **Entity Reference: Referenced Entity**
6. Now add the fields, **Phone**, **Address**, but make sure you are selecting the relationship that you added.

# Answer
> 0 votes
You need Views to achieve that. The listing you are getting automatically is provided by Drupal core and it is meant only for simple listing of teasers of content.

Views module provides already an override for the core taxonomy listing. You just need to enable it and adjust for your needs.

To do that:

1. Download and enable Views, if you haven't already done.
2. Go to views administration at `admin/structure/views`
3. Enable the view named **Taxonomy Term** and edit it.
4. You need to add a relationship to the **Company**. To do that:
    * Expand the **Advanced** section
    * Add new relationship under **Relationships** and select **Entity Reference: Referenced Entity** with a description like *A bridge to the Content entity that is referenced via FIELD\_YOUR\_REFERENCE\_FIELD*
    * Now you need to change the **Teaser** to **Fields** under **Format**.
    * You can now add the fields from the **Employee** content type AND **Company** content type which is referenced by the Employee.

---
Tags: views, entities
---


# Question
Title: Anonymous access to paid downloads using unique link
Is anyone aware of a solution using Drupal Commerce (or alternatives) whereby I can have a product which can go through the following sequence:

1. anonymous user places in cart
2. anonymous user goes to checkout
3. payment is completed
4. a unique token/string is assigned to the email address provided in purchase
5. a url from which an anonymous user can download the purchased file is created and emailed to the address provided as well as displayed on checkout completion screen
6. after a defined period of time the link would expire
7. non-expired links could then be retrieved via a form by supplying email address to resend them

I can achieve most of the above with commerce\_file but it seems that it requires logging in to the user account to access paid for downloads.

Seems like this would be a use case that would not be completely unique so hoping someone has an idea of how best to achieve this without having to roll my own solution.

Thanks in advance

Rich

# Answer
Drupal commerce has a permission to complete the checkout process, that might be your issue there, check the permissions page (admin/people/permissions) and grant anonymous users the "access checkout" permission
> 0 votes

---
Tags: commerce, uri, files, users
---


title: Uber cart external payment system

text:
# Question
Title: Uber cart external payment system
Now I working on project who need support some external payment systems (not PayPall or Google Chackout). I try search some tutorial/documentation about creation Ubercart payment system, but nothing found. So which way to look or where to start to solve this problem?

# Answer
Basically, you need to create a custom module and let ubercart know about your gateway using `hook_uc_payment_gateway()`, then use `hook_uc_payment_method()` to define a payment method. Then, you continue with defining a form that is used on checkout and finish it with creating redirect to your external payment system.

You can start with this - http://nmc-codes.blogspot.sk/2012/07/how-to-create-custom-ubercart-payment.html, it should give you a good start.
> 1 votes

---
Tags: ubercart
---


# Question
Title: How to export feed agregator list and setting as feature?
I want to export feed aggregator list and settings as feature. If both aggregator list and settings cannot be exported, then how to export? Thanks a lot.

# Answer
> 4 votes
I have achieved this using `aggregator_save_feed()` function in `hook_install()` or `hook_update_N()` of my custom module. It's not a feature but there is not much difference.

Example:

```
/**
 * Implements hook_install().
 */
function MYMODULE_install() {
  $feed = array(
    'title' => 'Business',
    'url' => 'http://feeds.bbci.co.uk/news/business/rss.xml',
    'refresh' => 3600, // Update interval in seconds
    'block' => 5, // News items in block
  );
  aggregator_save_feed($feed);
}

```

---
Tags: features, feeds
---


# Question
Title: Generating URLs based on taxonomy vocabularies and terms
I have a Drupal 7 website and I have 1 Vocabulary "Interviews" containing terms Celebrity and Director.

I want my website content to be available at URLs like this:

http://example.com/interviews/celebrity/title

http://example.com/interviews/director/title

# Answer
In your Pathauto Patterns (Admin\>Config\>Search and Meta Data\>URL Aliases\>Patterns `/admin/config/search/path/patterns` ) in the Content Paths section, find the appropriate content type and use the Tokens (called Replacement Patterns) to fill in the field.

In the described case, it might be something like the following: \[node:content-type\]/\[node:field-category\]/\[node:title\] or interviews/\[node:field-category\]/\[node:title\]

Be sure to expand and check what tokens you have available.
> 2 votes

---
Tags: 7, taxonomy-terms, path-aliases
---


title: File Upload in Selected Location

text:
# Question
Title: File Upload in Selected Location
I have file field in a content type to upload files. I have also created a drop down which has different values like folder 1, folder 2, folder 3 and so on.

I want file field to upload my files on location based on that drop down value.

for example if I have selected folder 2 in the drop down then the files should upload in folder 2

please provide some help on this issue.

# Answer
Try using File Path Module

> Adds the ability to use node tokens in destination paths and filenames.
> 0 votes

---
Tags: files
---


# Question
Title: I replaced a pdf file but google searches for the node turn up the old pdf file
I replaced a downloadable pdf file that was uploaded to one of the nodes on my website. But a google search of the item still goes straight to the old file. I've tried deleting the node completely and recreating it with the new file, but it still won't work. (The file name is the same, it's just the content that's augmented). The google search will direct properly on my laptop, but not on my ipad. I can't figure out if this is a drupal issue or a google issue or a browser issue (I deleted all cookies and history on my ipad before googling, but it still won't work)--can you help? Thanks!

# Answer
> 0 votes
Inside your Drupal File System - determined at Admin/Config/Media/File System - there are 3 directories that store files uploaded to your Drupal site. I would recommend navigating to each of these directories to find your (old) .PDF file and deleting it ...

If you want to keep the old PDF, consider renaming it ...

---
Tags: files
---


# Question
Title: change node author with rules. using an array of users with specific role
I am creating nodes with rules and the default author for these nodes is the user 1 (admin).

I have a set of users as 'administrator' roles. e.g: John, Jack, Sophie

Is it possbible with rules(or custom php code in rules) to change the author from admin to one of the 'administrators' in randomly fashion.

workflow: create node, author admin --\> rule --\> change author to John, Jack or Sophie --\> save node

# Answer
> 0 votes
Enable Views Bulk Operations

* Create a view (Table format is the easiest to manage.)
* Add a relationship Content: Author (not required)
* Add the author field so you can see who is the current author
* Add the field Bulk operations: Content
* Under Selected Bulk operations choose Change the author of the content. Save the view.

Now on the view page you will see a table of all your nodes.

* Check the select box next to the rows you need to update the author of.
* Under Operations at the top of your view, choose change the author of content.
* Hit Execute
* On the next page, choose the user and hit next
* on the next page hit confirm.
* Repeat / Integrate with rules...

---
Tags: nodes, rules
---


title: drupal module for uploading to s3

text:
# Question
Title: drupal module for uploading to s3
originally posted on stackexchange. Didn't get any replies. Then I recently found out there's a specific drupal stackexchange so here i am reposting. TIA!

I have a drupal site and I plan to serve static site files directly from s3 (rewrite). I need to provide a way for the content manager to upload his images directly to s3 from the drupal admin UI so he doesn't have to send it to me to upload via s3cmd or the aws console. Can anyone recommend a module or method for this?

I've tried s3fs however mounting a fuse s3 filesystem and serving from it was painfully slow. If it worked drupal would think the files are all local and i'd be set.

I found this but not sure if it will get the job done for me: https://drupal.org/project/storage\_api

I need a module that would allow the drupal admin UI user to graphically browse for a file (image for instance) to upload to the s3 bucket i intend to serve from.

# Answer
storage\_api is the right module for seamlessly transferring data such that the user's upload lands first on the servers local filesystem and by rules can have it automatically propagate to any number of containers (S3, Cloud Files etc..) And even more you can control the priority in which the files are served from the site simply by ordering them in prefered manner. the URLs will change automatically. pretty slick.
> 1 votes

# Answer
Here is a good blog post about using S3 as a media storage for Drupal: http://davidcsonka.com/blog/how-use-amazon-s3-store-your-drupal-website-files

Also, you may consider SaaS solutions, such as Filepicker, Cloudinary or Uploadcare. The latter has an open-source module for Drupal integration: https://github.com/uploadcare/uploadcare-drupal
> 1 votes

---
Tags: 7, files
---


title: How to add metatags to a view?

text:
# Question
Title: How to add metatags to a view?
I need to add rel=canonical meta tags to some views. There are a couple of sandbox modules for the metatag module but I'm looking for a more simple solution.

Couldn't I just use views\_php and drupal\_add\_html\_head()?

# Answer
Try the Context Metadata module. It can add metadata to node and non-node pages. The following metadata tags can be set according to a context: Title, Description, Keywords and **Canonical URL**.
> 2 votes

# Answer
If you want to add meta tags to a view without adding or writing a module, you could just do this. Add a block with the following PHP code and set the block visibility that view only.

```
<?php
$element = array(
  '#tag' => 'meta', // The #tag is the html tag - <link />
  '#attributes' => array( // Set up an array of attributes inside the tag
    'name' => 'description',
    'content' => 'Your view description.',
  ),
);
drupal_add_html_head($element, 'yourviewname_meta_desc');
?>

```
> 0 votes

---
Tags: 7, views, meta-tags
---


# Question
Title: Find out module versions through database dump
I've got a dump from my Drupal database that I've created with Backup and Migrate.

I want to find out which versions of the modules *ctools* and *Panels* have been in use.

Where do I have to look? What do I have to search for?

# Answer
* Import the dump file into mysql database. Create a new database in your localhost and import the db using your backup file
* Browse **System** table.
* Run below query

SELECT info FROM `system` WHERE `filename` LIKE '%ctools.module%' ORDER BY `system`.`name` ASC LIMIT 0 , 30
* You will see version information in info column. Search for "Version". Above information is serialized.
* For Example, As you see below "Ctools" module is 6.x-1.11 version. You can do same for panels module by changing query.
> 5 votes

# Answer
Aside from database dump, with the "Views System" module you can get details (although it seems a bit unstable).
> 0 votes

---
Tags: 6, database, backups
---


# Question
Title: What is the ideal way to restore a previous version of a site with Backup & Migrate files?
So I've been backing up my sites with backup and migrate and I always found weird that the backup&migrate .mysql files are smaller than the "drush sql-dump" sql files. Does anyone know why?

Also what is the quickest way to do a restore using backup&migrate? I usually unzip the gz files that gets saved to my server and just do a mysql drop database and then recreate it again and just fill it in with the sql files. I'm not sure if im doing it the long way or not.

# Answer
> 1 votes
You can restore using backup & migrate itself.

If you've backup and downloaded the file, then you can use Restore tab (/admin/config/system/backup\_migrate/restore) to upload the zipped file and restore.

If you've backed up to the Manual Backups Directory, then you can restore from the directory listing (/admin/config/system/backup\_migrate/destination/list/files/manual).

There are Drush commands for the above as well, see drush help after you enabled backup & migrate module.

# Answer
> 0 votes
BaM files likely smaller than drush dump files becuase BaM profile is leaving out data from accesslog, cache tables, search history, session history and watchdog as defined by default BaM profile \> Default Database Backup Options "Exclude the data from the following tables". I believe BaM drush commands have opt out options that can be used similarly.

---
Tags: database, drush, backups
---


# Question
Title: change FILTER CRITERIA for display (in views)
I want to have different filter criteria for one display in my views. I added it and when i hit "Update preview", the data shows up as expected in the bottom area of my views window. But then, when I surf to the url or when I hit the link specified at **Path**, I get data that appears without that filter applied. I have hit the save button on top, too. What else am I missing?

**edit 1** Also, I have realized that my second display also shows the title of my first display but I can reach it on the alternate path url...

**edit 2** *see screenshot in better resolution at: http://www.tiikoni.com/tis/view/?id=5c2a5fe* screenshot: On the left screen, you can see the view settings and on the right screen, in the April 2014 & May 2014 sections, you can clearly see that the filter *Content: Title (contains Brunch)* doesn't get recognized

# Answer
> 0 votes
The Filter criteria didn't get applied properly because both Displays had the same name. It is required that both View displays have different names to be able to apply filters to only one Display.

---
Tags: views
---


# Question
Title: How can I create a display in views with different filter criteria
Can I have a view with different displays? I.e. I would like to have the same display twice but in the second one, I just want to have an additional filter criteria. How can I do this?

**edit 1**

I cloned my initial display and added a new filter to the new one. I selected "This page (override)" and selected "Content: Title (contains `Brunch`)" but, I hit save but it doesn't seem to apply the filter:http://www.quaaoutlodge.com/restaurant-specials (new display) vs. http://www.quaaoutlodge.com/special-events (generic display)
Why is this, what did I do wrong? The query looks correct:

```
SELECT node.nid AS nid, node.title AS node_title, 'node' AS field_data_field_eventdate_node_entity_type, 'node' AS field_data_field_table_description_node_entity_type, 'node' AS field_data_field_link_to_page_node_entity_type
FROM
{node} node
LEFT JOIN {field_data_field_eventdate} field_data_field_eventdate ON node.nid = field_data_field_eventdate.entity_id AND (field_data_field_eventdate.entity_type = 'node' AND field_data_field_eventdate.deleted = '0')
WHERE (( (node.status = '1') AND (node.type IN  ('event')) AND (node.title LIKE '%Brunch%' ESCAPE '\\') ))
ORDER BY field_data_field_eventdate.field_eventdate_value ASC

```

but doesn't seem to get applied...for the new display - and yes, I hot "save"!

**edit 2**

It seems like the "This page (override)" feature doesn't work properly, I changed the title of my restaurant display and it doesn't geta pplied either.. any idea what I might be doing wrong?

# Answer
In order for filter criterias to be applied correctly to only one display, multiple displays are required to have different names!
> 0 votes

# Answer
You can clone your first display. In your second display you can add additional filters. Be sure when you add filters to choose to override from the dropdown menu, located at the top-left of your filter modal. This way, the additional filters are applied only to your second display.
> 1 votes

---
Tags: views
---


title: Overlay module does not work

text:
# Question
Title: Overlay module does not work
I updated my Drupal, but now the overlay module does not worki and everything shows on the center of page.

# Answer
This is a temporary problem.

do these steps:

1-disable overlay module.

2-click on **Save configuration** at the end of page.

3-click on modules again

4-enable overlay module **Save configuration**

> ```
> its like reseting a computer
>
> ```
> 0 votes

---
Tags: 7, updating, modal-dialogs
---


title: page template for view

text:
# Question
Title: page template for view
I have a view which I want to give a different look and feel from the rest of my page. Now the view is displayed as a page at a specific URL. I have tried naming my custom page template like `views-view--mobile-special-events--page.tpl.php`, (`mobile-special-events` being the name of my View) but this didn't work, it seems to apply this template only to the actual view area on my page but I want to re-theme the complete page, what do I need?

**edit 1**

I found this page: https://www.drupal.org/node/701920 where they say that you can preparte a page template from the link but I called my template `page-mobile-special-events.tpl.php` while my page is reachable under `www.mysite.com/mobile-special-events` but it doesn't seem to work, I've cleared the cache... what's going on, I'm wondering... :o

# Answer
> 1 votes
The thread you link to is for Drupal 6, if you are using Drupal 7 I think the template file should be: `page--mobile-special-events.tpl.php` (note the double dash).

---
Tags: views, theming
---


# Question
Title: redirect based on content type using rules
my problem is really silly and i know I must be missing something. All I want to do is redirect a user based on the type of node being viewed.

Here is what I tried with rules: Event: content is viewed

Condition: Content is of type: my desired type

Action: Path redirect: my desired url

Problem: when i search for anything using the search form, I always get redirected to the url I specified in the Action part of the rule.

Please let me know how to get around this

# Answer
> 1 votes
That's happening because you're reacting on the content is viewed event, which means *everytime* a content of the type you're describing in the conditions is displayed. You need to extend more those conditions to add the search context.

You can either compare with the site path with a "Data comparison" condition on `site:current-page:path` to `node/[node:nid]`

A better solution would be to filter out the view mode, I'm guessing you're looking for reacting on the "Full" view mode of the node, so just add a "Data comparison" condition on `view-mode` and set it to `Full content`

Something very similar has been answered before in: How to set Rules event for "Content is viewed" from excluding Teaser view?

In any case, if you want a node type to *not* have a final page, I recommend the Rabbit hole module.

---
Tags: rules, redirection
---


# Question
Title: Using php if else statement in display suite
Ok i purchased a theme from themeforest called wunderkind.

I liked most of the things about it except for the blog page. I liked the more traditional look of the summary image/video on the right and the blog summary on the left. Instead of one on top of the other.

So I am using display suites to layout the blog teaser and everything is working fine except that the blog article content type is dynamic. You can have either a standard post or a video post. If you choose video then a video URL field appears, and if you choose image then an image field appears.

I am trying to figure out how to create a code field in display suites that will either display the image or display an iframe with the video url.

The other route I am considering is simply creating a field in the blog called summary image and have it display on the main blog page.

Any help would be appreciated.

# Answer
> 1 votes
If your need is simple, a "hide when empty" for example, you definitely need to look into Field formatter conditions module, it will allow you do simple conditions on your field formatters for a given view mode.

If that's not enough, Display Suite allows to have arbitrary fields added to the view modes, you need to look into `hook_ds_fields_info` and implement it in a custom module for your needs.

```
/**
 * Implements hook_ds_fields_info()
 */
function my_module_ds_fields_info($entity_type) {
  $fields = array();

  $fields['my_field'] = array(
    'title' => t('My field'),
    'field_type' => DS_FIELD_TYPE_FUNCTION,
    'ui_limit' => array('node_type|*'),
    'function' => 'my_module_callback_function',
  );

  return array('node' => $fields);
}

function my_module_callback_function(&$field) {
  // Here goes your code, the conditions to display or not another field
  // and return an array with the data.
}

```

Further examples in https://stackoverflow.com/questions/16253312/using-hook-ds-fields-info-is-there-a-way-to-use-standard-formatters-so-the-op and http://www.previousnext.com.au/blog/creating-custom-display-suite-fields-or-how-i-learned-stop-worrying-and-use-hookdsfieldsinfo

---
Tags: display-suite, nodes
---


# Question
Title: Download file one time only for auth user (Suggestion needed)
I have a website has a books & categorize each book to unites, each units has a download link..

when user have a role, he can download file just 1 time .. no more for each unit ..

for example:

Book1 --\> unit1 --\> download --\> if(user NOT download) else { Remove Link }

Book1 --\> unit2 --\> download --\> this link was removed since you download a file

Book1 --\> unit3 --\> download --\> if(user NOT download) else { Remove Link }

Book2 --\> unit1 --\> download --\> if(user NOT download) else { Remove Link }

Book2 --\> unit2 --\> download --\> if(user NOT download) else { Remove Link }

Note: books & unit is term, units are child in books.

my idea for solve this issue is create a normal text field and set user id if he click on download link..

Any suggestion for solve a problem, way, or module, field setting ...
thanks every body

# Answer
> 0 votes
I think I understand what you want. Follow these steps.

1. First use `Private File System`
2. Write your custom module and create a schema/table to trace who has downloaded which file.
3. Implement `hook_file_download($uri)` or `hook_file_download_access_alter(&$grants, $file_item, $entity_type, $entity)` and consult your custom table whether the user has already downled the file or not and provide access accordinlgy, if user hasn't downloaded the file then provide him the access and update your table.
4. Make sure your module runs late, using `weight`.
5. While displaying the download link consult your custom table and show/hide links accordingly.

# Answer
> 0 votes
Please use the tag if you're looking for a module hosted at Drupal.org.

There exist a module named Deep Link. With 13 installs and no full release in sight, I wouldn't have high hopes for the usefulness of this, but the project page says:

> Deep link module allows the direct access to a specific item of content under certain circumstances and limitations. Such as one-off or time-limited deeplinks.

There is also Expiring Private File Link.

It says:

> This module was created when the need arose to offer a downloadable file to users of a site, without revealing the actual URL of the file itself. It also allows through the permissions system a method of allowing the file to only be available for download to registered users. If enabled, anonymous users will see the same dynamic link as registered users, but when they click on it they are presented with a login dialog informing them they must register to have access to the file.

This is a sandbox for Drupal 7, so its usefulness is even more questionable, but you may still want to check it out.

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


title: alternatives to media module?

text:
# Question
Title: alternatives to media module?
Are there any alternatives to the drupal media module for drupal 7?

Looking for functionality to preview and upload images and set the image style before displaying the image. Or would the media module be the best bet for this type of task?

# Answer
> 3 votes
The Media Module and the way it handles files as entities seems to be the wave of the future. It also manages image files, names, location, etc, which is important for keeping track of all your media assets. Unfortunately, as of Jan 2013, Media doesn't handle in-line images very well, and a few useful modules don't play well with it (or vice versa). For example field slideshow only works with images, not media files rendered as images.

I don't use WYSIWYG editors, but they may provide a way around the inserting inline file-images problem.

I do use Media Module for uploading images, but then I set the field type as image rather than use the file:render system. I can then use field slideshow (which is a very easy, very cool module), and Insert.

# Answer
> 8 votes
Have you check the Scald module? This is a real alternative in active development.

> Scald is a different take on how to handle media (audio, video, image or otherwise) in Drupal and beyond. It is a platform designed to make it extremely easy to implement the social features which are so essential -- and so unique -- to web communities. Additionally, Scald -- in tandem with the DnD module -- provides a novel and natural way for users to compose complex posts.

Feel free to ask me for details, or to put a issue in the module issue queue.

# Answer
> 1 votes
Yes there are alternative techniques. See the presentation slides on this post http://quicksketch.org/node/5744 for the module combinations.

Basically it is using FileFieldSources + Insert + Image Resize Filter + IMCE + FileEntity + File Entity Inline.

If you are going to go the Media module route, make sure you use the 2.x-dev and File Entity 2.x-dev. Also make sure to use image or file fields, not the deprecated mediafield that comes with media module.

# Answer
> 1 votes
Here's a very useful recent post examining pros and cons of either approach: http://purewebmedia.biz/articles/2013-01-10/how-insert-and-float-inline-images-drupal-7

After much testing I recommend the second one (using Insert field, without Media module), but I do keep the wonderful File Entity module on (maintains files as entities and allows for view modes for files, without any need for Media module).

# Answer
> 1 votes
At this point (mid 2014), we finally have a much better approach to using Media: Picture, CKEditor and IMCE. Both Inline and Attached images can be handled.

This approach looks like it will be the Drupal 8 default, and includes techniques for handling responsive images, and breakpoints for tablets and mobile phones.

\[addeded early 2015\] I've now begun to use Scald for media management, and it is very slick - especially for end users. It integrates nicely with Picture & Breakpoints.

---
Tags: 7, media
---


# Question
Title: Feeds import from RSS changing dates to current timestamp
I'm trying to import some old news items from a legacy site/system.

Using feeds importer to get the content from an RSS feed.

All works fine except the published date value gets rewritten to the timestamp at point of import. I can't find an option to change this behaviour, even using the 'tamper' module doesn't seem to assist.

Any suggestions?

# Answer
Turns out it wasn't Feeds itself but rather the old site's RSS being invalid. If the simplePie parser used by Feeds can't find a properly formatted `<pubDate>` value it defaults to a current timestamp.
> 0 votes

---
Tags: datetime, feeds
---


# Question
Title: How can I show an Ad popup after search form is submitted?
How can I place an Advertisement after clicking the search button and before showing the search results? can anyone help me with this stuff?

# Answer
> 0 votes
you could try a custom search-results.tpl.php to create a JS overlay while the results are being rendered

---
Tags: webforms, search
---


# Question
Title: Where is my views-view-field.tpl.php and the other views templates
I can not find my vviews templates, where are they? In my `/modules/` I don't have a `views` sub dir and in `/sites/all/themes/modules` I have a sub dir called `views_php` which doesn't seem to contain the view templates either.. where do I find these files?

**edit 1**

My directory structure looks something like this:

```
sites/
  all/
    libraries/
    modules/
      alchemy/
      apps/
      ...
      ...
      views_php/
        plugins/
          views/
      ...
      ...
    themes/
      marinelli/

```

In my db there is some content in tables `drupal_viws_display` and `drupal_views_view` and a `drupal_cache_viws` and `drupal_cache_views_data` also exists - with content.

**edit 2**

I downloaded the whole ftp directory and tried to find my `Views` templates:

```
$ find . -name "*view**.tpl*"
./sites/all/modules/commerce_kickstart/modules/commerce_kickstart/commerce_kickstart_taxonomy/theme/views-view--collection-products--page.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views_megarow/theme/views-view-table.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/tests/templates/views-view--frontpage.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-view-grid.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-view-unformatted.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-ui-edit-item.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-view-row-rss.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-view-field.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-view-fields.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-view-table.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-exposed-form.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-view-grouping.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-ui-display-tab-bucket.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-view-list.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-ui-display-tab-setting.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-ui-edit-view.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-view-row-comment.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-view-summary-unformatted.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-view.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-more.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-view-rss.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/views/theme/views-view-summary.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/eva/eva-display-entity-view.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/date/date_views/theme/date-views-pager.tpl.php
./sites/all/modules/commerce_kickstart/modules/contrib/date/date_views/theme/date-views-filter-form.tpl.php
./sites/all/modules/date/date_views/theme/date-views-pager.tpl.php
./sites/all/modules/date/date_views/theme/date-views-filter-form.tpl.php
./conference/sites/all/modules/views/tests/templates/views-view--frontpage.tpl.php
./conference/sites/all/modules/views/theme/views-view-grid.tpl.php
./conference/sites/all/modules/views/theme/views-view-unformatted.tpl.php
./conference/sites/all/modules/views/theme/views-ui-edit-item.tpl.php
./conference/sites/all/modules/views/theme/views-view-row-rss.tpl.php
./conference/sites/all/modules/views/theme/views-view-field.tpl.php
./conference/sites/all/modules/views/theme/views-view-fields.tpl.php
./conference/sites/all/modules/views/theme/views-view-table.tpl.php
./conference/sites/all/modules/views/theme/views-exposed-form.tpl.php
./conference/sites/all/modules/views/theme/views-view-grouping.tpl.php
./conference/sites/all/modules/views/theme/views-ui-display-tab-bucket.tpl.php
./conference/sites/all/modules/views/theme/views-view-list.tpl.php
./conference/sites/all/modules/views/theme/views-ui-display-tab-setting.tpl.php
./conference/sites/all/modules/views/theme/views-ui-edit-view.tpl.php
./conference/sites/all/modules/views/theme/views-view-row-comment.tpl.php
./conference/sites/all/modules/views/theme/views-view-summary-unformatted.tpl.php
./conference/sites/all/modules/views/theme/views-view.tpl.php
./conference/sites/all/modules/views/theme/views-more.tpl.php
./conference/sites/all/modules/views/theme/views-view-rss.tpl.php
./conference/sites/all/modules/views/theme/views-view-summary.tpl.php
./conference/sites/all/modules/date/date_views/theme/date-views-pager.tpl.php
./conference/sites/all/modules/date/date_views/theme/date-views-filter-form.tpl.php

```

$

# Answer
> 0 votes
I realized that `views` I was using wasn't the real `views` but rather part of `ecommerce-kickstart` which I have uninstalled in the meantime and that forced me to re-install `Views` which also gave me access to all the templates

# Answer
> 1 votes
Doesn't sound like you have the views module installed. Views\_php is a different module.

The modules page (example.com/admin/modules) should tell you whether you have Views installed and enabled. If you don't see Views (just "Views") in the list, then you don't have it installed. If that's the case, head over to https://drupal.org/project/views, download and untar/unzip the appropriate version into your sites/all/modules (or sites/default/modules) directory. Go back to the modules page and enable it.

If all else fails, why not do a file system search for 'views.module' ?

# Answer
> 0 votes
First ensure you have `views` enabled from the list of module.

**Then**

You can find all `views` related templates in the `theme` directory inside `views` module. Proper location --

**sites/all/modules/views/theme**

In your case it's location is

**/sites/all/modules/commerce\_kickstart/modules/contrib/views/theme/**

---
Tags: views, theming, location
---


# Question
Title: BOA installation caching does not refresh
I have recently migrated an existing site into a fresh BOA platform. The problem I am facing is that the cache for the anonymous users is never cleaned, when new content is added. The anonymous user can only see new content by adding ?nocache=1 at the URL. But otherwise cache is not regenerated neither by drush cc all.

Given that this happens when boost is disabled, I conclude that this is an issue with speed booster. I tried all suggested solutions to reduce the TTL to 30seconds or so, but there is no improvment. New content is not even displayed for the devel.domain.com, which is supposed to have TTL of 1 second. So I don't know what to think.

Adding ?noredis=1 helps only occasionally, most of the times it delivers older content as well.

If the anonymous user submits a comment, caching gets suspended, as it should be according the documentation.

Edit: I also noticed that drupal reports

> 1 error has been encountered when purging URLs Array

and nginx gets similar errors

> Blockquote \[alert\] 52902#0: \*65633 stalled cache updating, error:0 while closing request, client: 127.0.0.1, server: 127.0.0.1:8888

I am copying here the headers of a normal request and I would appreciate some directions on how to resolve this issue, which is actually preventing totally all my sites from working. This is a news and forum website, where content needs to be displayed immediately, the latest after a minute or so.

Response Headers

```
Cache-Control public, max-age=0
Connection close
Content-Encoding gzip
Content-Language el
Content-Type text/html; charset=utf-8
Date Thu, 30 Jan 2014 01:09:38 GMT
Expires Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified Thu, 30 Jan 2014 00:58:19 +0000
Server nginx
Transfer-Encoding chunked
Vary Accept-Encoding, Cookie
X-Cookie-Domain .mysite.com
X-Device normal
X-GeoIP-Country-Code DE
X-GeoIP-Country-Name Germany
X-NoCache Cache
X-Server-Name www.mysite.com
X-Speed-Cache EXPIRED
X-Speed-Cache-Key /node/4042

```

Request Headers

```
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Cache-Control max-age=0
Connection keep-alive
Cookie has_js=1; __utma=1.2022174721.1391038387.1391038387.1391038387.1; __utmb=1.49.10.1391038387; __utmc=1; __utmz=1.1391038387.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __unam=f0418e2-143e0596284-fd42fad-47
Host www.mysite.com
User-Agent Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:26.0) Gecko/20100101 Firefox/26.0

```

Response Headers From Cache

```
Cache-Control public, max-age=0
Connection close
Content-Encoding gzip
Content-Language el
Content-Type text/html; charset=utf-8
Date Thu, 30 Jan 2014 01:09:38 GMT
Expires Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified Thu, 30 Jan 2014 00:58:19 +0000
Server nginx
Transfer-Encoding chunked
Vary Accept-Encoding, Cookie
X-Cookie-Domain .mysite.com
X-Device normal
X-GeoIP-Country-Code DE
X-GeoIP-Country-Name Germany
X-NoCache Cache
X-Server-Name www.mysite.com
X-Speed-Cache EXPIRED
X-Speed-Cache-Key /node/4042

```

# Answer
> 2 votes
1. Please make sure you are using latest BOA stable
2. Make sure you have configured custom Speed Booster TTL properly (INI or code)
3. Note that default is just 10 seconds, so there is no way it can cause such issues
4. Disable Purge+Expire modules, unless you are forcing long TTL
5. Check the docs at: https://omega8.cc/node/108 for working code examples
6. Make sure it is not some other caching layer (Views?) which adds confusion

I hope this helps.

---
Tags: caching
---


# Question
Title: Using compass in Aegir limited shell (user o1.ftp)
I installed the latest BOA-stable and after it RVM with Compass and SASS. According to the changelogs of BOA-2.0.4, I should be able to use Compass commands:

> # Fixes:
>
> Allow all standard compass/sass commands in limited shell.

As root, I am able to execute 'compass watch', but I am not with the limited shell (as user o1.ftp). It says:

```
sh: 1: compass: not found

```

# Answer
> 1 votes
For me it didn't work in combination with RVM. I needed to install it the normal way:

```
- apt-get install ruby
- apt-get install rubygems
- gem update --system
- gem install compass

```

I think that because of the isolated gem installs that RVM creates, the limited shell user has no access to the commands.

# Answer
> 0 votes
You should modify the .barracuda.conf file to include the installation of compass tools. There is an option \_XTRAS\_LIST where you simply include CSS

# Answer
> 0 votes
Note that now BOA uses RVM for all gems by default. We have also fixed this for limited shell environment, so at least in the last few months it should work just fine.

---
Tags: theming, aegir
---


# Question
Title: How to update field values of a content type's nodes when when viewing a particular content type page
I'd essentially like to alter the values of a specific custom field of a few of nodes before they're displayed in a view on the 'page' of a specific content type.

The content type is that will be displayed is a ***park***. When a park is viewed, one of the blocks shown is a view that fetches and shows several nodes that are also '*parks*'.

This *park* content type has a field called ***proximity***. I'd like to change the value of proximity (based on a mathematical formula) for all parks before the view is processed, so that I can use *proximity* in the view.

From what I understand so far, I should use a `park_preprocess` function, which calls some sort of `hook` to change the *proximity* values. Is this correct, and how would I do it?

# Answer
Thanks to Pushinder and Shirin for responding, and providing the start I needed! However both answers were lacking the detail I needed. I won't paste my entire code here, as it's too long, but I'll describe what I used and why:

* `hook_node_view` was the right hook to call my function at the right time - before page load
* `$refN = $node->field_location_n[LANGUAGE_NONE][0]['value'];` and the same for East were required to get the reference coordinates
* Because I have several hundred nodes with coordinates, I couldn't load each one individually using `load_node` or collectively using `load_node_multiple` since this used far too many resources for every page load
* Instead, I used `db_query` and `field_attach_load` together, as described in this answer: https://drupal.stackexchange.com/a/30906/20264 to effectively load just the values I needed
* I then used `foreach( $nodes as $nodei ) {` to loop through all the results
* `$distance = sqrt( pow( $refN - $nodeiN, 2 ) + pow( $refE - $nodeiE, 2 ) );` was my proximity calculation
* Then, only for results with a specified proximity would I update `$node`
* Since I was using the *Entity Reference* module to record 'Nearby places' in my nodes, I used the following to update the entity references:

$node-\>field\_nearby\[LANGUAGE\_NONE\]\[$i\] = array( "target\_id" =\> $nodei-\>nid );
> 0 votes

# Answer
hook\_node\_view() will be used in this scenario.

```
function hook_node_view($node, $view_mode, $langcode) {
  if($node->type == 'park' && $view_mode == 'full')
   {
    /* change the value of proximity here after applying your formula.
      * Here you have complete node array, so you alter the result easily here.
    */

   }
 }

```
> 0 votes

# Answer
you can use hook\_node\_view as @Pushpinder Rana said.but if you want to modify a field you should save your node.here i simply plus one my proximity field on my hook.

```
/**
 * Impelement hook_node_view
 * @param type $node
 * @param type $view_mode
 * @param type $langcode
 */
function MODULENAME_node_view($node, $view_mode, $langcode) {
    //plus one proximity field and save a node
    $new_value = $node->field_proximity[LANGUAGE_NONE][0]['value'] + 1;
    $node->field_proximity[LANGUAGE_NONE][0]['value'] = $new_value;
    node_submit($node);
    node_save($node);
    // here is to show user updated proximity value;
    $node->content['field_proximity'][0]['#markup'] = $new_value;
    }

```
> 0 votes

---
Tags: entities, hooks, nodes, theming
---


# Question
Title: Acsessing field data for a views template
I have a client who wants to be able to input a content type which allows for the upload of 4 different pdf files. They want to have a view that allows them to click on one link and load each pdf file in a separate tab. I can get this to work in the footer of the view with the global text option and inputting the following code:

```
<a href="[field_client_first_pdf]" target="_blank"  onclick="window.open('[field_client_second_pdf]','');window.open('[field_client_third_pdf]','');">[title]</a>

```

The problem is, I need this to work in the fields using the global text option but full html is not allowed there. I am trying to use a views template file to input the code but I can not figure out how to access the data that is supplied by the replacement patterns in the view. Any tips on how I can assign variables with the right data in the template file?

# Answer
Use the `Theme: Information` in the `Advanced` part of the view configuration (you need to click the `Advanced` link to expand it).

Here you can explore all the possible templates for that specific view and specific display. But additionally you can click the specific template and see the default code (in your case you will use Row template I guess). There you can see the available variables.

To print out the specific values, I would recommend Devel module and then the `kpr()` or `dpm()` functions, like this: `dpm($fields);` in your template.

Alternatively, you can use `debug($fields);` without using the Devel module.

*Important: Do not forget to delete these debug functions before deployment.*
> 0 votes

---
Tags: entities, files
---


# Question
Title: Providing a default value for an Entity Reference Field using Views Bulk Operations
I have a content type called 'Schools' and a CSV spreadsheet that has columns for information such as School Name, Location, Telephone etc...

Using Feeds I can import the information on the 111 Schools to individual pages.

Furthermore I have a field on the 'Schools' Content type that is an entity reference field to an entity (an entity form - that lets the user contact the school - of widget type 'Select list')

However when I import the school data with my feed the 'entity reference' 'select-list' field defaults to 'none' and the 'Contact form' does not display. Furthermore the entity reference field does not let me set a default value for the 'select list'.

I don't want to go through 111 schools to do this manually. While the previous question on this subject calls for some code...that I do not yet understand...

Therefore is there a way to essentially set a default value for my entity reference ... Perhaps 'Views Bulk Operations' is the answer?

# Answer
> 0 votes
I figured this out.

Views \> Create New View \> Content type 'Schools'

Format \> Table

Add Fields \> Title

Add Fields \> Bulk Operations (Content) \> Bulk Operations \> Modify Entity Values \> 'Your Entity Reference Field' \> Skip Confirmation Step \> Show Token Values

done - navigate the views bulk operations URL, select all of your nodes and apply the changes ... You might need to adjust the pager options in the view to see all of your nodes, and also disable the feeds importer while you adjust the nodes associated with it...

---
Tags: feeds, views
---


# Question
Title: Help with the sub-groups for Organic groups module
I want to have this functionality in my website, but I really do not know how to use this module, I tried to follow this tutorial http://mohitaghera.drupalgardens.com/content/creating-subgroup-organic-groups

But there is a step I do not understand, you have to set the sub-group content type a group or a group content in the og settings?

Please have someone used this module? how to use it. How does it work, what is the workflow of this module.

# Answer
> 0 votes
Read this post, it will help you to figure out how to use the sub-og module

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

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


# Question
Title: create a downloadable file after submit webform
Hello Im not sure if this can be done, but Im trying to make a simple app where you create your own lexical analyzer.

So in the webform I ask the necessary information, then I need the following:

1. After send the webform generate a script file (from a template I already have done)
2. I need a way to replace some tokens in the script file with data from the submitted webform
3. Let the user download the generated script file

Any idea how to achieve this? maybe it is not that complex...

Thank you very much

# Answer
I found the trick in this post =)

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

You can create any kind of generated file with any kind of extension. Not only pdf
> 0 votes

# Answer
This module may be used for your idea please use and try this module

**Webform2PDF**

The Webform2PDF Drupal module is an extension of the Webform module. It can be used to generate PDF document from the results of a form. The generated PDF document can be attached to the form summary e-mail sent by Webform module, or it can be downloaded from the /Results/ page. Different PDF templates can be set for each form. The templates can be formatted with HTML tags, and they can be edited with WYSIWYG Drupal module, making the template creation easy and the templates highly customizable. The output documents will be created by using these templates.
> 0 votes

# Answer
You need hook\_webform\_submission\_insert for that purpose.
> 0 votes

---
Tags: 7, webforms, javascript, tokens, forms
---


# Question
Title: I cannot see the dblog of my kickstart commerce
When I navigate to `/admin/reports/dblog`, nothing happens. It only shows me a node, and if I go to the Admin menu then I cannot see the reports link. Check the image below to better illustrate my issue:

**My questions**: Why I cannot see the reports menu? And how can I access the dblog info?

# Answer
I found in the Commerce kickstart documentation that the dblog is disabled by default due to this functionality consumes a lot of resources.

Enable database logging module and then rebuilt the menus as suggested by Clive
> 0 votes

---
Tags: routes, commerce, log-messages
---


# Question
Title: An AJAX HTTP error ocurred. HTTP Result Code: 500 (while trying to rebuild content access perms)
I have installed a module that ask me everytime to rebuild content Access Permissions, but every time I try to do it, it shows me an error I do not have idea why is it happening. Please help

```
An AJAX HTTP error ocurred. HTTP Result Code:  500 Debugging information follows: Path: /batch?id=172&op=do Status Text: Service unavailable (with message)
Response Text:

```

Please check the image for more details

# Answer
> 1 votes
The problem with this was the server, the server was refusing the ajax request, maybe a php memory problem I have migrated my drupal website to a VPW

---
Tags: 7, ajax, debugging, users, http-request
---


# Question
Title: Use multiple URL arguments to prepopulate multiple entity reference fields
I have multiple nodes of type 'schools'

I also have a contact form that i'd like to provide on a per school basis.

I.e. The user views a school page and can use an entityform embedded or linked to that particular schools page to generate a pdf letter to mail to the school. This letter will be pre-populated with the School name, School address, Head Mistress and other fields from the 'schools' content type that it came from.

I have set up 'entity reference' and 'entityreference prepopulate' as per this tutorial and have made some headway.

However I can so far only successfully pass *one* item from the node to my form using url arguments ... how can I pass multiple arguments ~5-6 elegantly to prepopulate my entity form?

I am open to alternative approaches, it would be nice to have the form embedded on the schools page...rather than linked (via the block in the above example)

# Answer
You can follow the same approach given in the example.

You will need to rewrite the link from

```
http://example.com/contactform?field_name=12345

```

to

```
http://example.com/contactform?field_name=12345&field_name_second=4567&field_name_third=890

```

This should do the trick for you.

If you want it to look more elegant, then you can just pass the entity id of the referring object and then write some code to pre-populate the values based on the given entity.
> 2 votes

---
Tags: entities
---


# Question
Title: What is the best way to stop a node from loading in a node hook?
I want to use hook\_node\_view to stop a node from loading if it was not created by the user trying to access it. What should I include in the following code to kill the loading of the node?

```
function hook_node_view($node, $view_mode, $langcode) {

    global $user;
    $currUser = $user->uid;
    $nodeUser = $node->uid;

    if ($currUser != $nodeUser){
        drupal_set_message('kill page');
  }
}

```

# Answer
> 2 votes
You can't prevent a node from loading but you can deny/grant access to it. Write a custom module and implement `hook_node_grants($account, $op)` && `hook_node_access_records($node)`. Here is a good example.

or, you can implement `hook_node_access($node, $op, $account)` but this hook will not be invoked for **node listings** (e.g., RSS feeds, the default home page at path 'node', a recent content block, etc.)

# Answer
> 1 votes
It would be better to take a look at the Content Access Module

As the project page reads,

> This module allows you to manage permissions for content types by role and author. It allows you to specifiy custom view, edit and delete permissions for each content type. Optionally you can enable per content access settings, so you can customize the access for each content node.

---
Tags: 7, hooks, nodes
---


# Question
Title: Show contextual link for each node on node listing page
I want to show contextual links having Edit and delete links for each node on hover on main listing page of my application. I have searched and found the following code

```
function MyModule_node_view_alter(&$build) {
  if(isset($build['#node'])) {
        $node = $build['#node'];
        if(!empty($node->nid)) {
            $build['#contextual_links']['node'] = array('node', array($node->nid));
        }
    }
}

```

But this code displays contextual link on node detail page. For example when individual node is visited like `http://www.example.com/node/21`. But I want to show these contextual link on listing page where all nodes are displayed. When I hover the node, this should be shown.

This is how my view settings looks like

Any help?

# Answer
> 2 votes
If you are building the node listing page using views, you can

1. Enable contextual links module.
2. In the fields for the listing, add a field 'Content : Edit Link'. Then select Exclude from display.
3. Add a Global : Contextual Links field. In the field settings, check the edit link field.
4. You should be good to go.
5. You can also add additional field in the context menu if you want.

---
Tags: 7, views
---


title: Disable node summary page on /node path

text:
# Question
Title: Disable node summary page on /node path
I want to disable the default front page, that is showing a list of nodes. I use another front page but it is still displayed at the url `example.com/node`. Either restricting access or redirecting to the front page would be fine.

My homepage is currently set to `/home` (which gets nicely rewritten to `example.com/`). Now I have already tried a few different things.

* Under `/admin/config/search/path`, I have set an alias from `node` to `home`.
Unfortunately this just resulted in redirecting both `example.com` and `example.com/node` to `example.com/home`, showing the node list - not my front page.
* I tried with an alias from `node` to `<front>` (I don't know if that is even valid there). This almost worked, `/home` and `/node` both redirect to `example.com` showing the right page. But now the node list is available at `/<front>` ...
* I also tried with panels, creating a variant of node template. Returning a status code when the path was equals `node` did not work, I guess because the page is only triggered on `/node/`, with a slash. It won't let me create a panel just for the node path as the path is already in use of course.
* There doesn't seem to be any permission for setting access to this list.

So, how can I disable the page at `example.com/node`?
I guess my problem is I don't even know what kind of page this node list is. I have the feeling it's some unique page type, buried deep down in the core and can't be easily disabled.

# Answer
> 10 votes
If you're ok with writing a small custom module you could do it very easily using `hook_menu_alter()`:

```
function MYMODULE_menu_alter(&$items) {
  $items['node']['access callback'] = FALSE;
}

```

The above will deny access to the page, if you want to remove it completely use this instead:

```
function MYMODULE_menu_alter(&$items) {
  unset($items['node']);
}

```

There's a discussion on the subject here with a few other ideas but I think this would be the simplest.

# Answer
> 2 votes
You can install Node Page Disable contrib module from Drupal.org.
And then just uncheck "*Retain /node as an active url?*" on page **Configuration \> System \> Site** information (`/admin/config/system/site-information`)

# Answer
> 1 votes
I just set up an alias from `home` (*system path*) to `node` (*alias*) and it is working now. This is the opposite of what I've tried before. Both paths end up on `example.com` and show the correct new front page.

Anyway, this is probably just 'hiding' the system node at this url, so removing/denying access might be the better way to handle this.

---
Tags: 7, path-aliases, nodes
---


title: Displaying multiple price for products

text:
# Question
Title: Displaying multiple price for products
I'm trying to create two selling price for each products. One is retail and another is wholesale price. For that I have two price fields in my product variation (`commerce_price` and `wholesale price`). But when I add a product it was displaying only `commerce_price`. I want to display both prices. I have enabled both price fields in its `display settings` also.

Here is the snapshot how it was looking now

Can anyone tell me how can I achieve this?

# Answer
> 4 votes
I'm guessing you're using commerce kickstart and/or you've got Commerce Extra Price Formatters installed, it has an extension that provides the feature you're displaying, RRPP and your price.

Check out your display options, the second price won't appear automatically until you make it so. Go to `admin/structure/types/manage/[your-product-machine-name]/display` and verify that your price is being displayed there:

Then click in the link for the settings of the variation type display if you're in kickstart or go to `admin/commerce/config/product-variation-types` and edit the display for your variation type.

If you're not in kickstart, the url for this same screen would be `admin/commerce/products/types`

Change the price formatter to `Formatted price` or whatever other fits for your needs.

---
Tags: 7, entities, commerce
---


# Question
Title: Display a promo image at last in every slideshow created for a node
I am using Views Slideshow module to display multiple images uploaded in my `article` content type. Every node landing page will have a slideshow displayed with its images (slideshow works fine). All what I need is one common(Promo)Image to display as the last image/slide in every slideshow.

Is this possible with "Views Slideshow" and "Views" ? Do I need to create a separate tpl file for this?

# Answer
> 0 votes
Create a Promo article and add the promo image as the field in this article.

Note the this article will be just a placeholder for us and will not be presented anywhere. So may you could un-publish as well.

Do a dpm to find out the fid or any related that you need to know about this particular image field. Then make changes to the view in post\_execute.

```
   function modulename_views_post_execute(&$view) {
      // wait for the right view
      if($view->name == "name_of_the_view") {
        // create the object you want to insert in the result
        // dpm($view->result); to check how the objects are built.
        $temp = new stdClass;
        $promo_image->fid = 13;

        // replace the old result array
        $view->result[] = $promo_image;
      }
    }

```

Based on the answer : Insert row into a view

---
Tags: 7, views
---


# Question
Title: How to group taxonomy terms by their parent when using term reference field?
Is there a way to group taxonomy terms by their parent name(as fieldsets) for term reference field in content creation?

For example: Cat#1 as parent and subCat#1, subCat#2 as children should be shown as a fieldset with Cat#1 as legend(and thus unselectable) and subCat#1 & subCat#2 should be shown in this fieldset.

# Answer
I think Taxonomy Super Select does what you want for Drupal 6, but there's no Drupal 7 version available.

However, the module page recommends the Taxonomy Term Reference Tree Widget module to do the same thing

> This module provides an expandable tree widget for the Taxonomy Term Reference field in Drupal 7. This widget is intended to serve as a replacement for Drupal's core Taxonomy Term Reference widget, which is a flat list of radio buttons or checkboxes and not necessarily fit for medium to large taxonomy trees.
> 2 votes

# Answer
I would suggest using the Hierarchical Select Module It is highly configurable.

> This module defines the "hierarchical\_select" form element, which is a greatly enhanced way for letting the user select items in a hierarchy.

Check out a demo here http://wimleers.com/demo/hierarchical-select/taxonomy
> 0 votes

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


# Question
Title: Cannot add content using default content types
I have Article and Basic Page, but when I try to add either of these to my Drupal Site I get the following error message.

> You have not created any content types yet. Go to the content type creation page to add a new content type.

# Answer
If you go to Structure \> Menus \> Navigation, goto "list links" of Navigation menu, you'll see that all of your content types are disabled except for the actual "Add content" link. Just check the enabled box and save, then you should be good to go.
> 1 votes

---
Tags: nodes, debugging
---


# Question
Title: How to trigger hook_form_alter() on my custom $form?
I have written a custom module which builds a custom `user_profile_form()`:

```
mymodule_user_profile_form($form, $form_state, $user) {
  module_load_include('inc', 'user', 'user.pages');
  $form = user_profile_form($form, $form_state, $user, 'account');
  // doing stuff with $form ...
  return $form;
}

```

Now, it's working as desired but I noticed a lot of contrib modules are altering the `user_profile_form()` calling a `hook_form_alter()` on the `$form_id == 'user_profile_form'`.

Now, I want all these modifications applied to my custom profile form, too. How to achieve that?

The hacky way would be to go through all modules and change the checks for `$form_id == 'user_profile_form' || $form_id == 'mymodule_user_profile_form'`, but this is a no-go and I would appreaciate a clean way to do this. Any idea?

---

**Update**: `drupal_get_form()` is not the answer as it is not working as desired. This is only returning the $form object without re-building it which causes many issues with theming layer and `$form_state['values']`. I'm adding this information as requested by moderator, but this is *not* part of my question. This is the not working code with `drupal_get_form()` b6d1f1d8 and this is the working code with `user_profile_form()` d5d43dc0.

# Answer
> 6 votes
You should use `drupal_get_form($form_id)` to get the form instead of directly calling `user_profile_form()` and it will ensure that all the form alters are applied before you get the form.

**Update**: Can you explain why you are not using `hook_form_alter()`?

But if you want to proceed this way, then instead of calling `drupal_get_form()` you can replace that with the code from `drupal_build_form()`, except the call to `drupal_process_form()`,

Replace `drupal_get_form()` with the following code, copied from `drupal_build-form()`

```
$form_state += form_state_defaults();
if (!isset($form_state['input'])) {
   $form_state['input'] = $form_state['method'] == 'get' ? $_GET : $_POST;
}
$form = drupal_retrieve_form('user_profile_form', $form_state);
drupal_prepare_form('user_profile_form', $form, $form_state);

```

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


# Question
Title: How to delete Duplicate Nodes based on title?
Is there any easy way to remove duplicate nodes based on Node title?

# Answer
> 4 votes
You can achieve that by Remove Duplicates module

> This module helps the administrator to easily remove duplicate nodes according to one of the node fields.
>
> **Features**
>
> The duplicate nodes found are permanently removed. It can be very useful with Drupal Feeds module (Feeds).

# Answer
> 2 votes
You can also achieve that by creating a custom module

```
<?php
/**
 * @file
 * Remove Duplicate Nodes.
 */
/**
 * Implementation of hook_menu().
 */
function dedupe_menu() {
    $items['admin/content/dedupe'] = array(
        'title' => 'Dedupe',
        'description' => 'Delete Duplicate Nodes',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('dedupe_content_command'),
        'access arguments' => array('administer site configuration'),
        'type' => MENU_NORMAL_ITEM,
    );
    return $items;
}
/**
 * Build Form
 */
function dedupe_content_command() {
    $options = node_get_types('names');
    $form['dedupe_node_types'] = array(
        '#type' => 'select',
        '#title' => t('You can select content type from which duplicates are removed.'),
        '#options' => $options,
        '#default_value' => variable_get('dedupe_node_types', array('page')),
        '#description' => t('Duplicate content from the selected content types will be deleted.'),
    );
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Dedupe'),
    );
    return $form;
}
/**
 * Call delete function and set message.
 */
function dedupe_content_command_submit($form, $form_state) {
    $type= $form_state['values']['dedupe_node_types'];
    $dedupe_m = 'Duplicates deleted from content type '. $type;
    dedupe_delete($type);
    drupal_set_message(check_plain(t($dedupe_m)));
}
/**
 * Delete duplicates from selected content type, based on title. By Robert Douglass.
 * @see http://robshouse.net/blog-post/remove-duplicate-nodes-dedupe-based-title
 */
function dedupe_delete($type) {
    $previous = array();
    $result = db_query("SELECT nid, title FROM {node}
    WHERE title IN
      (SELECT title FROM {node}
        WHERE type = '%s'
        GROUP BY title HAVING count(*) > 1)
    ORDER BY title, created DESC", $type);
    while ($row = db_fetch_array($result)) {
        if ($row['title'] == $previous['title']) {
            node_delete($previous['nid']);
        }
        $previous = $row;
    }
}
?>

```

Note: I didn't test this code.But seems it would work.Read more from Remove Duplicate Nodes based on title

---
Tags: 7, nodes
---


# Question
Title: dependent dropdowns via #ajax for unlimited option
I have a commerce Product content type, which has a field collection field attached to it field\_mycollection, which has 4 different fields field1, field2, field3 and field4 dependent on each other. Like field2 will be filled based on field1 selected, field3 will be filled based on field2 selected and field4 is dependent on field3. #ajax is used for this.

My Content |\_ field\_mycollection |\_ field\_field1 |\_ field\_field2 |\_ field\_field3 |\_ field\_field4

It is working fine for me for one set of field collection. But I have unlimited option enabled for field collection. It is not working for that.

How could I achieve this goal? I did it using hook\_form\_FORM\_ID\_alter().

How to manage edit form ?

My code is :

```
foreach ($form['field_part_details']['und'] as $key => $fc_mycollection) {
  if (is_numeric($key)) {
    $options_first = custom_get_first_dropdown_options();
    $year = isset($form_state['values']['field_part_details']['und'][$key]['field_year']['und'][$key]['tid']) ? $form_state['values']['field_part_details']['und'][$key]['field_year']['und'][$key]['tid'] : key($options_first);
    $make = isset($form_state['values']['field_part_details']['und'][$key]['field_make']['und'][$key]['tid']) ? $form_state['values']['field_part_details']['und'][$key]['field_make']['und'][$key]['tid'] : '';

    $html_id_first = drupal_html_id('dropdown-first-replace');
    $form['field_part_details']['und'][$key]['field_year']['und']['#ajax'] = array(
      'callback' => 'custom_dependent_dropdown_callback_year',
      'wrapper' => $html_id_first,
    );

    $form['field_part_details']['und'][$key]['field_make']['und']['#options'] = get_second_dropdown_options($year, 'year');
    $form['field_part_details']['und'][$key]['field_model']['und']['#options'] = get_second_dropdown_options($make, 'make');
    $form['field_part_details']['und'][$key]['field_make']['und']['#prefix'] = '<div id="'. $html_id_first .'">';
    $form['field_part_details']['und'][$key]['field_make']['und']['#suffix'] = '</div>';

  }
}

```

Callback Code is :

```
function custom_dependent_dropdown_callback_year($form, $form_state) {
  return $form['field_part_details']['und'][0]['field_make'];
}

```

Any help is appreciated.

# Answer
Use drupal\_html\_id() to generate unique ids. That is:

```
$html_id_first = drupal_html_id('dropdown-first-replace');
$form['field_mycollection']['und'][$key]['field_field1']['und']['#ajax'] = array(
  'callback' => 'custom_dependent_dropdown_callback_year',
  'wrapper' => $html_id_first,
);
...
$form['field_mycollection']['und'][$key]['field_make']['und']['#prefix'] = '<div id="' . $html_id_first . '">';
$form['field_mycollection']['und'][$key]['field_make']['und']['#suffix'] = '</div>';

```
> 0 votes

# Answer
Below solution is working fine for me.

```
 foreach ($form['field_part_details']['und'] as $key => $fc_mycollection) {
      if (is_numeric($key)) {
        $options_first = custom_get_first_dropdown_options();
        $year = isset($form_state['values']['field_part_details']['und'][$key]['field_year']['und'][0]['tid']) ? $form_state['values']['field_part_details']['und'][$key]['field_year']['und'][0]['tid'] : key($options_first);
        $make = isset($form_state['values']['field_part_details']['und'][$key]['field_make']['und'][0]['tid']) ? $form_state['values']['field_part_details']['und'][$key]['field_make']['und'][0]['tid'] : '';

       $form['field_part_details']['und'][$key]['field_year']['und']['#ajax'] = array(
          'callback' => 'custom_dependent_dropdown_callback_year',
          'wrapper' =>dropdown-first-replace--' . $key,
        );

        $form['field_part_details']['und'][$key]['field_make']['und']['#options'] = get_second_dropdown_options($year, 'year');
        $form['field_part_details']['und'][$key]['field_model']['und']['#options'] = get_second_dropdown_options($make, 'make');
        $form['field_part_details']['und'][$key]['field_make']['und']['#prefix'] = '<div id="dropdown-first-replace--'. $key .'">';
        $form['field_part_details']['und'][$key]['field_make']['und']['#suffix'] = '</div>';

      }
    }

```

Callback function :

```
function custom_dependent_dropdown_callback_year($form, $form_state) {
  $from_element_name = $form_state['triggering_element']['#name'];
  $exp = explode('[', $from_element_name);
  $str = rtrim($exp[2], "]");
  return $form['field_part_details']['und'][$str]['field_make']['und'];
}

```
> 0 votes

---
Tags: forms
---


# Question
Title: Add javascript to returned form after ajax validation
I've built a form with the form API, and it's submitting via ajax via this type of thing:

```
  $form['submit'] = array(
  '#type' => 'submit',
  '#value' => 'submit',
  '#ajax' => array(
      'callback' => 'handyman_form_callback',
      'method' => 'replace',
      'wrapper' => 'form-wrap',
      'effect' => 'fade'
  )
);

```

The problem is, if the form is returned due to validation errors the javascript applied to the form no longer works. I've read lots about the attachBehaviors function but I'm not sure where I could put this to make it work, and not sure if this is even the correct thing to do.

Any help?

# Answer
you can attach custom jQuery functions in your modules every time you load content just attaching functions to the Drupal.behaviors like this:

```
(function($) {

  Drupal.behaviors.your_module = {

    attach: function(context, settings){
      $('#element').bind('click', function(event){
            alert('hello!');
      });
    }

  }

}

```

In this way, every time Drupal loads content, no matter via ajax or a page refresh, it will automatically attach the desired behaviors. Don't forget to include the js in your pages.
> 0 votes

# Answer
You can put your code in the `hook_validate` function of your form if you are using it. Because every time when form shows validation errors then it is rebuilt by Drupal so any css or JavaScript added to the form is lost.

So you just need to include the js again to add it in the form.

```
function hook_banner_form()
{
drupal_add_js("javascript","inline");
//............................
//............................
//........................
}

function hook_banner_form_validate($form_state)
{
drupal_add_js("javascript","inline");
//............................
//............................
//........................
}

```
> 0 votes

---
Tags: forms, ajax
---


title: Rate Module - Ability to "Rate" people

text:
# Question
Title: Rate Module - Ability to "Rate" people
Using the Rate Module , I'm interested to know if it is possible to "Rate" people.

For example, rate a *tradesman*; rate a *private tutors teaching service*; rate any *service provider*.

I'm already using the Rate module for node rating, but cannot seem to find at this moment the ability for the above, unless it's custom hack or something.

Has anyone used the Rate module for similar, or would anyone like to share a general overview of what's needed to accomplish such a task?

# Answer
> 2 votes
Drupal is very capable in this arena.

A few modules that come to mind are:

With more detail I think you would get a better answer, but at a glance I believe you could accomplish this quite easily with readily available modules.

The tricky part I believe will be figuring out how to structure your site.

Will People/Service providers be stored as nodes or user accounts?

Will users need to register to rate? Can anonymous users rate? Both?

Can service providers register their own business/service or will you be adding a pre-selected list?

---

If you create a custom content type called "Service Provider" for example, you could apply the Rate module to this content type and have something up and running quite quickly.

# Answer
> 0 votes
You can use the flag module and aggregation in views to have the counting of flags using `Flag:flagged (A boolean field to show whether the flag is set or not)` as a view field, you will need to add the flag as a relationship for that. Then in the view field: aggregation `count distinct` =\> nb of flags on a user. You can even have different countings or flags (customer services, delivery time, etc.) by user.

---
Tags: rating
---


# Question
Title: hook_menu implementation producing error page
I am trying to create a new module implementing hook\_menu, to render a page on my company's web site, which I have taken over from the external firm who designed it. There are other modules that use the hook\_menu mechanism successfully on the site.

However, when I create my module and try to access my new page, I get a message indicating "Error. The website encountered an unexpected error. Please try again later.", with no real indication of what the error is.

Here is my code:

```
<?php

function customer_stories_menu(){
    $items['test'] = array(
        'title' => 'Products Display',
        'title callback' => 'customer_stories_title',
        'page callback' => 'customer_stories_page',
        'access arguments' => array('access content'),
        'type' => MENU_CALLBACK,
    );

    return $items;
}

function customer_stories_page() {
    return "Test 123";
}

function customer_stories_title() {
    return "Title";
}

```

I have made sure that I cleared the cache after putting the code in place. Could something in the site be preventing new hook\_menu pages from working?

I should also mention that I first tried creating a new view page to get to the data I wanted to display, but I also got a non-descript error page when I tried to access the defined URL for the page. The two issues may be related. Thanks for any help you can provide.

# Answer
I've got this noted down as my starting point for a module .

```
function helloworld_menu() {

$menu['helloworld/hello'] = array(
    'title' => 'Hello World',
    'page callback' => 'helloworld_hello',
'access callback' => TRUE,
);
   return $menu;
  }

function helloworld_hello() {
   return 'Hello World';
 };

```

do you still get an error if you take it back to this point.
> 0 votes

# Answer
I had code in one of my blocks that was causing an error. It was missing a condition to exit when getting called on a new page.
> 0 votes

---
Tags: routes
---