# Question
Title: How to theme date combo input side-by-side?
I'd like to theme a date combo field on a node edit form to be side by side, rather than stacked vertically, as shown below. Dates are popups, if that makes a difference.

I'm working with the admin theme Seven, which I've sub-themed, in order to override theme functions or CSS as needed. What is the approach should I take for this kind of customization? Moving the "to" label isn't strictly necessary, but would be nice if possible.

Before

After

Also wondering if there is some good reason why the to and from fields are arranged this way?

Edit: instructions for creating a subtheme are here: https://drupal.org/node/225125 This is an easy way to customize an Admin theme if needed.

# Answer
> 2 votes
Looking at the CSS provided by the module, the boxes are foreseen as block elements. Even the used classes on the form fields are `date-no-float`, so for some reason they don't want that the fields are shown in column layout ...

The fact that you used a sub theme for your admin, you can add these CSS styles (based on `Seven` theme) in your css file. These will create the desired result you want.

```
.date-no-float { float: left; width: auto; clear: none; }
.date-no-float > .form-item > label { float: left; margin: 34px 40px 0 30px; }
.start-date-wrapper { clear: left; }

```

# Answer
> 0 votes
You could also theme the output of the widget with this template override

http://drupalcontrib.org/api/drupal/contributions!date!date.theme/function/theme\_date\_combo/7

---
Tags: 7, theming, datetime
---


title: OAuth2 login provider - endpoint page

text:
# Question
Title: OAuth2 login provider - endpoint page
I have installed OAUTH login provider and all dependencies to provide authentication service to other web application throug drupal authentication. The problem is that I still do not manage to test if the drupal auth login provider works correctly. I am not sure what is the URL that I shoud put in the client application to reach the server auth provider.

For example in local development environment if I try

```
https://localhost/oauth2_loginprovider/

```

I get a FORBIDDEN response from Apache while if I try to contact

```
https://localhost/oauth2/ ...

```

I get a 404 page not found on the server

Could you please help me?

# Answer
Have you tried https://localhost/oauth2/authorize ? That is the authorization start point for me.
> 0 votes

---
Tags: authentication-authorization
---


# Question
Title: User with permission can't add an event to calendar by clicking
I have a working calendar (from the module calendar).

As administrator, i can click on a date and a popup allows me to add an event.

But users, who are allowed to add an event, can't do it. They can add an event by navigation and clicking on"add content", but they can't do it, like me, the administrator.

Can someone help me? I guess, it's somewhere in configuration but I don't find anything.

Thanks for any advice!

# Answer
Can you clarify? You said:

> users, who are allowed to add an event, can't do it. They can add an event by navigation and clicking on"add content", but they can't do it

* what do you mean they can't do it? Can they navigate to /node/add/\[event\] (I'm not sure what your event node type is called)? Or when they do go to /node/add/\[event\] does something happen when they try to save the new event?

Are you sure you have the permissions set correctly for their role? Check out the permissions at admin/people/permissions. Double check the permissions under Node.
> 0 votes

---
Tags: datetime
---


title: Creating Tabs using Drupal?

text:
# Question
Title: Creating Tabs using Drupal?
I have been looking for a solution that allows me to add tabs to my website something similar to this page.

So far I have been using HTML inside of ckeditor to write all my content. However, now I need to be able to have a form and tabs.

Can someone provide me a module or a solution to have tabs and form ?

Thank you in advance

H.

# Answer
> 2 votes
Quicktabs \+ Webforms. You can have multiple pages (nodes) or blocks and using the quicktabs module would allows you to have the different insert those pages or blocks into tabs. To created the field form you can used the Webform module and inserted into quick tabs module.

# Answer
> 1 votes
Take a look at https://www.drupal.org/project/quicktabs...allows you to create blocks of tabbed content.

# Answer
> 1 votes
To style fields in that manner, use Field Group

> Fieldgroup will, as the name implies, group fields together. All fieldable entities will have the possibility to add groups to wrap their fields together. Fieldgroup comes with default HTML wrappers like vertical tabs, horizontal tabs, accordions, fieldsets or div wrappers.

To tabbify pieces of text in a single body text, as done in that example, install Bootstrap theme and read up on the Bootstrap documentation (especially tabs and pills). The sited example uses Bootstrap framework.

Please note that Bootstrap theme for Drupal and Bootstrap framework are not synonymous. Bootstrap is a popular HTML, CSS, and JS framework that Bootstrap theme uses. You can use Bootstrap framework without Bootstrap theme, but the question is, would you want to?

If you do not want to use a Bootstrap enabled theme, then I am sure you would find a myriad of Javascript and CSS solution if you google a bit.

# Answer
> 0 votes
Here is another option jQuery Tabs Field.

> jQuery Tabs Field module allows you to create jQuery Tabs field. Using this you can add upto 7 tabs with tab title and tab body in a node. After saving node, the module will display all these 7 tabs as jQuery tabs.
>
> This module is very useful for content types where you want to display information tabs wise for example product pages etc.

---
Tags: 6, nodes
---


title: Any way to do DISTINCT ON?

text:
# Question
Title: Any way to do DISTINCT ON?
I'm trying to create a query like this:

```
SELECT DISTINCT ON (field1, field2) field1, field2, field3 FROM table1

```

But can't figure out how to get DISTINCT ON narrowed down to a few fields in Drupal like that. Calling `$query->distinct()` just seems to structure the query like this:

```
SELECT DISTINCT field1, field2, field3 FROM table1

```

I did figure out a hacky way to add what I want by adding an expression before I add any fields like this:

```
$query->addExpression('DISTINCT ON (field1, field2) field1', 'field1');

```

Which creates:

```
SELECT DISTINCT ON (field1, field2) field1 as field1, field2, field3 FROM table1

```

I'm looking for a better way to this ?

# Answer
You could try with the distinct() method for dynamic queries and see how it goes with your query.

There is an example to follow on the taxonomy module of the Drupal core, on the following line:

```
$node_types = db_select($revision_name)
->distinct()
->fields($revision_name, array('bundle'))
->execute()
->fetchCol();

```
> 3 votes

# Answer
I have use this some time, Hope this will help you.

```
$result = db_query("SELECT node.uid AS node_uid, node.created AS node_created, COUNT(DISTINCT node.title) AS node_title, COUNT(DISTINCT field_data_body.body_value) AS field_data_body_body_value, COUNT(DISTINCT field_data_body.delta) AS field_data_body_delta, COUNT(DISTINCT field_data_body.language) AS field_data_body_language, COUNT(DISTINCT field_data_body.bundle) AS field_data_body_bundle, COUNT(DISTINCT field_data_body.body_summary) AS field_data_body_body_summary, COUNT(DISTINCT field_data_body.body_format) AS field_data_body_body_format
FROM
{node} node")->fetchAll(PDO::FETCH_ASSOC);

```
> 0 votes

# Answer
you should set that field on your query something like

if you want distinct on 2 field

```
db_select('table1','t1')->fields('t1',array('field1','field2'))->distinct()->execute();

```

the query will be

```
SELECT DISTINCT t1.field1 AS field1, t1.field2 AS field2 FROM {table1} t1

```

and for one field

```
db_select('table1','t1')->fields('t1',array('field1'))->distinct()->execute();
SELECT DISTINCT t1.field1 AS field1 FROM {table1} t1

```
> 0 votes

---
Tags: 7, database
---


# Question
Title: How can I display a view title with 'No Results Behaviour'?
Using Drupal V 7.34 and Views 7.x.38

On the front page I have a view that lists news articles based on publish date being in the last 2 weeks. This works fine.

What I am now wanting is to insert a new view to pull images from Flickr when there are no news articles to show.

So, I created a new view for the Flickr feed, and adjusted the paging as I wanted. I set up the No Results Behaviour to show my new view in the Global View Area.

This works, but the title of the view is not displayed.

How can I show the title of the NRB view?

Many thanks

# Answer
i believe this is your problem

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

solution is here

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

If you have a view and you want to be able to programmatically change the title of, you can do it by implementing hook\_views\_pre\_render in your custom module: alter it when particular view or field is not having any result

```
<?php
function mymodule_views_pre_render(&$view) {
  if ($view->name == 'my_view_name' && $view->current_display == 'my_display_id') {
    // Here you can do any php you want to get the title you need for your view.
    $view->build_info['title'] = "My custom title!";
  }
}
?>

```

If you are altering the query and you have argument substitutions affecting the title, you can change these in hook\_views\_query\_alter:

```
<?php
function mymodule_views_query_alter(&$view, &$query) {
  if ($view->name == 'my_view_name' && $view->current_display == 'my_display_id') {
      // First substitution - you may want !1 or %2, etc
      $view->build_info['substitutions']['%1'] = $new_substitution;
    }
}
?>

```

Views Displayed as Pages

Use this:

```
drupal_set_title('My custom title!');

```

Instead of:

```
$view->build_info['title'] = "My custom title!";

```

or some thing like this in views 3

```
<?php
/**
 * Implements hook_views_pre_view().
 */
function MODULENAME_views_pre_render($view) {
  if ($view->name == 'my_view_name') {
    if ($view->current_display == 'my_display_name') {
      $view->set_title('my new title');
    }
  }
}
?>

```
> 2 votes

# Answer
There is a patch to Views here that will display the title from the View set in the No Results Behavior. Hopefully it will eventually be accepted into the module, but hasn't been reviewed for two years.
> 0 votes

---
Tags: views
---


title: Drupal 6 Views Slideshow configuration

text:
# Question
Title: Drupal 6 Views Slideshow configuration
I am trying to create a gallery like this.

It's been a while since I worked on a D6 site I am sure I have done this before on a few 2/3 year old websites.

**However, when I try configuring Views to generate my image gallery I don't get a slideshow style option**. I have attached an image to show the View configuration area to see what I mean.

Can anyone help me with this, please?

# Answer
> 2 votes
It's looking like you have Views 2 installed, so, make sure you have the right Views Slideshow module installed as there is one for Views 2 and another for Views 3 per the Views Slideshow Module page on drupal.org:

**Requirements**

* Views Slideshow 2.x requires Views 2.
* Views Slideshow 3.x requires Views 3.

# Answer
> 0 votes
I ran into a related issue when troubleshooting a Drupal 6 site that had been recently upgraded to a newer version of views and views slideshow. In the process, the existing slideshows had stopped working.

The problem was that Views Slideshow 2.x for Drupal 6 was changed from the earlier versions and the new version (6.x-2.4) requires you to *also* enable one of two sub-cmodules: Views Slideshow: SingleFrame or Views Slideshow: ThumbnailHover in order for it to work. Here's the relevant section of the Views Slideshow 6.x-2.4 readme file:

> # Views Slideshow
>
> The Views Slideshow module is a Views Style Plugin that can be used to output Views in a jQuery slideshow.
>
> There are currently 2 modes:
>
> SingleFrame
>
> In SingleFrame mode slideshows are output as single elements and controls can be displayed as numbered links or thumbnails of individual fields.
>
> ThumbnailHover
>
> In ThumbnailHover mode slideshows are output as node teasers or full nodes. The controls for advancing the slideshow are nodes too.
>
> Further details about each can be found within their respective directories.

I enabled SingleFrame and set it up in the view and the slideshow worked again.

---
Tags: 6, views
---


title: Integration with third-parties?

text:
# Question
Title: Integration with third-parties?
I'm trying to integrate Drupal Commerce to a File Maker. Why ? Because my client staffing have been using File Maker for over 15+ years. We are trying to integrate both systems.

So my goal is to be able to send the order information every time a purchase is complete to the File Maker server so they can re-created their order information into File Maker as well.

I started to write my custom module to send the order ID to the File Maker server. Here is how I did it.

```
/**
 * Implements hook_commerce_checkout_complete().
 */
function commerce_external_call_order_commerce_checkout_complete($order){
  $script_variable = variable_get ('external_script');
  // Combine the URL with the OrderID.
  $final_variable = file_get_contents($script_variable . $order->order_id);

}

```

And this actually works.

I'm wondering if there is a module that allows me to export my order information every time an order is complete or updated? Ideally would be an integration with Rules and the Service module.

# Answer
You can use https://www.drupal.org/project/services\_rules . It creates actions (usable in rules) for the services module. It's in beta because it has a limited amount of features. It is stable though.
> 1 votes

---
Tags: commerce, rules, services
---


# Question
Title: Render with custom style all contents of a content-type from custom module
I am trying to create a custom module to manage a slider.

After install my current-development module, I have:

* a slider content-type
* a slider view defined to show Content (Full Content) of the content-type slider with Unformatted list format
* a node--slider template that renders the slider node as a li element

**EDIT: Code updated** You can check the module code here: https://github.com/jmvelasco/drupal

I wonder how could I add a wrapper that contains all nodes of this content-type and call to render each node using the template defined.

The idea I have in mind is define a block like:

```
<div id="wrapper" class="slider">
    <ul>
        render_node_slider($slider_content)
    </ul>
</div>

```

So the end rendering will be somethink like:

```
<div id="wrapper" class="slider">
    <ul>
        <li> slider content 1 </li>
        <li> slider content 2 </li>
         ...
        <li> slider content N </li>
    </ul>
</div>

```

But I don't know how to manage this even if I am pretty sure this is completely possible to achieve.

The accepted answer points to the right direction, from the current state of development, now I'd like to know if I can improve the `slider_block_view`

https://github.com/jmvelasco/drupal/blob/master/slider.module (line 101-124)

using a templete file defined in the module instead code the html inside a function module. I want also to attach a css and js files when rendering this view.

I'll appreciate any kind of help here.

Thanks for the reading.

# Answer
If you want to just use the views module. Set your view to use fields. Filter by content type and set your display to using HTML List style. Pickout the fields you want to display (Image, Title). You can then add your custom javascript through a module or your theme so that it actually runs as a slideshow.

There are other modules that can handle this as well like views\_slideshow and owlcarousel.

If you want to keep the code all in your own module, you may want to take a look at this article:

http://www.sitepoint.com/building-drupal-7-module-show-latest-nodes/

It shows you how to create your block, how to query the database, how to use the theme('item\_list', $theme\_args). It should be straightforward.
> 0 votes

---
Tags: theming, nodes
---


# Question
Title: Commerce Pricing Rules Not Applying During Checkout
I have a pricing rule that's defined essentially along the lines of the one described here, and it appears correctly when I add items to the cart. But as soon as I progress to the check out the prices all revert to their base price not the discounted price.

With the Rules debugging enabled all the rules appear to fire, but the calculation doesn't appear to be saved correctly. Since there aren't a lot of hits in Google for this (or at least for the various search terms I can think of) I presume we're doing something odd that's causing trouble, but I've slowly removed every complexity I can so I'm as close to the user guide example as I can all without success.

# Answer
> 1 votes
The problem was the Rules 2.8 regression resolved by Commerce 1.11.

---
Tags: 7, commerce, rules
---


# Question
Title: Question about views (related to page specific blocks)?
Lets say I have a website called "website123" along with several pages called "pageA", "pageB", "pageC" and "news". Each of these pages has custom blocks that will only display on these pages. (Think bannerA/bannerB/bannerC and sidemenuA/sidemenuB/sidemenuC)

On the news page you have a view that will grab all published content that are articles. On "pageA" it will grab all content tagged with "a", "pageB" and "pageC" will have a view just like "pageA" except it will go for content tagged with "b" and "c".

I'll create an article called and tag it with "a,c" so this will go to "news", "pageA" and "pageC".

If you go to "pageA" the layout will be banner at the top and sidemenu on the left with the view in the middle with a list of articles tagged with "a" in a teaser viewmode

Is it possible to make it so that when you click "read more" it will open the article in the current region / page so that the same custom banner/sidemenu applied on "pageA" will be applied to all articles in "viewA"?

Then since the article was tagged with "c" as well if you went to "pageC" and in "viewC" if you clicked the same article there it would open with the banner and sidemenu that only "pageC" has.

Sorry if this question is really confusing, but any advise would be appreciated.

# Answer
> 0 votes
This is a response to the part: Is it possible to make it so that when you click....

If the page regions don't change and all you are really checking for is the blocks that should show depending on the referer, you could do something in your blocks where they check $\_SERVER\['HTTP\_REFERER'\].

You could breakdown the HTTP\_REFERER so you could get /sectionA/article or /sectionB/article or /sectionC/article.

Then you would have your sectionA/B/C that you could then pass into your blocks.

You might use something like this below in your block and selecting the PHP evaluation method.

If user comes from sectionA/article your block might look like the below and it would show up.

```
if (isset($_SERVER['HTTP_REFERER']) {
  $referer = $_SERVER['HTTP_REFERER'];
  switch ($referer) {
    case 'pageA':
      return TRUE;

    case 'pageB':
      return FALSE;

    case 'pageC':
      return FALSE;

  }
}

```

# Answer
> 0 votes
I think what you are looking Views Related Content

> Views Related Content is an extension to the Views module. It helps show the related contents, related nodes on the content detail page. This module makes it easy for you to work with contents, nodes by adding the filter criteria by Author, Content Type, Taxonomy Terms in the Views configuration.

---
Tags: views, blocks
---


# Question
Title: Add additional fields to select list on Webforms
In Webforms type field of Select options looks something like this:

But what if I need to add extra fields per each select option? Fields that are drop-down and you can select amount (number) of quantity.

So what it does is that user fills the form for a product query. They select products from the select list and select the quantity for each item. But how do you do that with Webforms?

# Answer
Had to create a fieldset per each select option with only one select option available and then just play around with CSS and it looks like one select list with separate quantity fields.
> 1 votes

---
Tags: 7, entities, webforms
---


title: Zend Optimizer+ error

text:
# Question
Title: Zend Optimizer+ error
Can an anyone help me.I am getting the following error while running my drupal 7 application

Fatal error: Cannot redeclare function views\_views\_plugins() (previously declared in /var/www/vhosts/cibi.hq.k.grp/newsite/sites/all/modules/views/includes/plugins.inc:15). If this code worked without the Zend Optimizer+, please set zend\_optimizerplus.dups\_fix=1 in your ini file in /var/www/vhosts/cibi.hq.k.grp/newsite/sites/all/modules/ctools/ctools.module on line 113

# Answer
The very same thing happened to me after transferring my website to another hosting company.

**You must run update.php.**

Since I was logged out, the way I resolved this is as follows: I typed in the url box www.example.com/update.php (www.example.com being your site's name. If it's on your local machine, I guess it is something like localhost/update.php.)

If your settings.php file is properly configured, you should get an access denied message.

In that case, go to the directory (sites/default) and open the settings.php file. Look for the line *$update\_free\_access = FALSE;* and change it to TRUE.

Run update.php again. You will find a link at the bottom of the result page sending you to the front page. Click on it and your site is back in business. :)

CAUTION. Very important: Go to your settings.php file again and change the TRUE back to FALSE.
> 0 votes

---
Tags: 7, chaos-tool-suite
---


title: Apache Solr and Arabic diacrictics

text:
# Question
Title: Apache Solr and Arabic diacrictics
I am using Drupal and I would like to index Arabic text that use Arabic diacritics extensively 'similar to accents in French or Umlauts in German".

The text is indexed but the search doesn't ignore the diacritics when searching. Does anybody know if the Arabic standard tokenizer handle Arabic diacritics?

I read somewhere that some people use AraMorph tokenizer. I am not sure if this can work with Solr 4.4.0.

I use Apache Solr integration module along with Search Api for Solr.

How can I make my search insensitive so that it ignores those diacritics?

Thanks, Mohamed

# Answer
> 0 votes
Adding the ICUTokenizerFactory to the text fieldtype solves the issue and the search ignores the diacritics.

---
Tags: search
---


# Question
Title: How to preprocess output of $user_picture in Drupal 7?
By default user picture output markup looks like this:

```
<div class="user-picture">
    <a href="/user/username" class="active">
        <img class="img-responsive" src="http://www.example.com/sites/example.com/files/styles/profile_page/public/pictures/picture-1-1420552205.jpg?itok=3Kt4fK7H" alt="user avatar username" title="user avatar username" />
    </a>
</div>

```

I need change markup of user picture output to something like this:

```
<div class="user-picture">
    <img src="http://www.example.com/sites/example.com/files/styles/profile_page/public/pictures/picture-1-1420552205.jpg?itok=3Kt4fK7H" alt="" />
</div>

```

Remove unnecessary markup. But question is how?

I have read:

The user-profile.tpl.php file won´t be recognized in my Drupal 7 installation

Changing user picture HTML output on user profile

Will be very appriciate for helping me out.

# Answer
> 1 votes
In the core user module you can find user-picture.tpl.php. Copy this file to your active theme, edit it and be sure to clear cache.

If you need to go deeper, put this in your theme's template.php. Original can be found in user.module.

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

```

---
Tags: users, theming
---


title: Comment reply form not working?

text:
# Question
Title: Comment reply form not working?
When I click 'reply' button on the comment, a new comment form open in new Windows; but subject box does not contain 're:' or like that and my reply saves as a new comment.

How can I repair my comment system?

Regards.

# Answer
> 2 votes
you need to go to admin/structure/types/manage/article \[if your content type is Article\] or admin/structure/types/manage/page \[if it's Basic Page\]

click on comment settings and make sure you have threading checked, so the replies have an indentation.

Asfar as re: in subject box, to my knowledge, drupal does not come with that by default.

---
Tags: comments
---


# Question
Title: How to delete a file attachment from the apachesolr index
My file attachments are indexed using apachesolr attachments 7.x-1.x-dev. I have a custom module that physically deletes a file using file\_delete(), but file still remains in Apachesolr index even after re-indexing. The only way to remove from search results is to delete the index then reindex.

I tried this to no avail:

```
// Remove file from apachesolr index
$env_id = apachesolr_default_environment();
$entity_type = 'file';
$entity_id = apachesolr_document_id($file->fid, 'file');
apachesolr_remove_entity($env_id, $entity_type, $entity_id);
drupal_set_message('Deleting '.$file->uri.' from private attachments.');
file_delete($file);

```

The file is physically removed, but not removed from index.

Any suggestions on how to remove file from apachesolr attachments index/search results after it is deleted?

# Answer
From Dileno blog:

If you simply want to delete documents from your Solr index by using the web interface, here's a code snippet that lets you do so:

```
http://localhost:8983/solr/update?stream.body=
<delete><query>id:298253</query></delete>&commit=true

```

This lets you delete documents where the id field matches 298253.

If you want to delete items that matches more than one field, just add another query:

```
http://localhost:8983/solr/update?stream.body=
<delete><query>id:298253</query>
<query>entitytype:BlogEntry</query></delete>&commit=true

```
> 0 votes

---
Tags: search
---


# Question
Title: Drupal commerce order total ignore changed unit price
I have problem with commerce order total counting.

Every product has two prices (two fields). One price for everybody and second for exact role. I have rule which change prices if user with exact role is logged in.

When i browse product with exact role all prices are ok. If i add some product to cart a go to my cart product prices and total price is still good. But when i go to checkout total price is set to 0.

In checkout are all products with good price but total price is 0.

Rule for changing price is simple:

```
event: calculate product price
condition: user role
action: set a data value (commerce-line-item:commerce-unit-price -> second price field)

```

Do anybody know what could be wrong? Thanks for every advice.

# Answer
> 2 votes
Try to downgrade rules to v 2.7. For more details look at https://www.drupal.org/node/2408705

> Important: Rules 2.8 has a critical regression that causes checkout rules to not work. Follow #2403851: Commerce pricing rule not working for more details, and downgrade to 2.7 for now.

---
Tags: rules, commerce
---


# Question
Title: drupal variables custom module and views
I'm trying to figure out how Drupal works. I created a simple module named "myModule".

In its myModule.module file I have:

```
<?php

function myModule_node_view($node, $view_mode, $langcode){
drupal_add_js(array('myModule' => array('nid' => $node->nid)), 'setting');
           }
?>

```

on myModule.js file I have:

```
    (function ($) {
  Drupal.behaviors.myModule = {
    attach: function (context, settings) {

      jQuery("#test").bind('click', function(e) {
        alert(Drupal.settings.myModule.nid);
      });
    }
  };
}(jQuery));

```

On my view which has nodes (articles), I created a custom field which has

```
<a id="test" href="#"Testing!!!</a>

```

So basically what I want is when I click on the *Testing!!!* link to show an alert which shows the node id (nid) that belongs to the article in the view's row.

Right now it's showing the nid of the current node I am in, not the view's row.

# Answer
> 3 votes
in your drupal\_add\_js, you are setting 1 variable many times. (Drupal.settings.myModule.nid). So the last one will be what this is set to.
You could add these nids to an array in Drupal.settings.myModule but then you would still need a reference from anchor in the views row that maps to the appropriate array index in your Drupal.settings.myModule array.

I think the best / easiest way to get what you want would be to set a data attribute in your views anchor using a token of the current rows nid.
Also, set it up as a class instead of an id, so you don't have the same id multiple times.
eg.

```
<a class="nid-button" data-nid="[node:nid]" href="#"Testing!!!</a>

```

Then in your javascript you would just need to use this data attribute.

```
(function ($) {
  Drupal.behaviors.myModule = {
    attach: function (context, settings) {

      jQuery(".nid-button", context).bind('click', function(e) {
        alert($(this).data('nid'));
      });
    }
  };
}(jQuery));

```

Doing it this way you don't even need to set any settings variables, instead it is saved on the anchor itself.

---
Tags: nodes
---


# Question
Title: The RTL css file is not working for a menu
I wanted to make the CorporateClean theme RTL. Every thing is Ok except Main Menu. It effects alignment for both languages. For Persian is also right and for English as well. As example: I wrote the following code in RTL Css file

```
#header-menu ul.menu li {
float:right;
dir:rtl;
text-align:right;
}

```

It makes the menu RTL for both English and Persian languages.

# Answer
you mistake is here **dir:rtl;** :(, and correct code will be below "dadash"

```
#header-menu ul.menu li {
float:right;
direction:rtl;
text-align:right;
}

```
> 0 votes

---
Tags: routes, theming
---


# Question
Title: What path should I give so that contextual filter works
I am creating on **view page** for which works like `archive` and I am doing it for the **terms** that are used in **Blog**(I am using `blog module`).

I have followed this tutorial.

But problem is when I give **CONTEXTUAL FILTERS** to `year+month`, and after that If I open my URL `example.com/blog/201502` it is showing me 404 page.

Where am I lacking ?

**NOTE:** It is working fine in preview which are under view.

Some snap shot regarding this:

If I put path something like `blog/%` then It is showing me all the blog post and I want to have Terms.

If I click on `January 2015` then It should give me following result :

Please help me.I have tried a lot.Let me know if more information is required.

# Answer
Instead of creating a node view create a taxonomy view

In that provide two relationships

```
Taxonomy term: Content with term
Taxonomy term: Content using {Name of the taxonomy field in the content type}*
Add a contextual filter of the type Content : Title Use the first relationship for the contextual filter, Make necessary changes in the more option such as change to lover case turn space to dashes etc
Add the required fields from the content with the relationship set to 2)

```

You are good to go.

EDIT : As per the discussion There was another need to also show the nodes under a term and its sub terms.

```
Create a view of the type content.

Add the required fields

Add a contextual filter of the type Content: Has taxonomy term ID (with depth) and select the depth a value as deep as the hierarchy you have in the taxonomy.

```

Now when you pass the term id as the input it would show all the nodes under that taxonomy term including the child nodes

If you wish to change the url to have the term name instead of the term ID Do the following.

```
In view give the path as taxonomy/term/% this will override the default taxonomy path.

Install Pathauto Module this depends on Tokens module so have to install that as well.

In Configuration -> URL aliases you have a tab called Patters

Set the pattern of the "TAXONOMY TERM PATHS" to what you would like it to be. Make sure that the last value is [term:name] so if you want the path to be category/carrot you should give it as category/[term:name]

If you have already added the taxonomy terms then you would need to do the "BULK UPDATE" which is again a tab on the URL Alias page.

```

Now when you visit the page category/termname you will see all the nodes under the term including the child terms
> 2 votes

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


# Question
Title: assigning a role to a user programatically
I have been looking around for how to assign a role to a user programatically and there is some discussion. Basing my code a little off of https://drupal.org/node/28379, will this work?

```
    global $user;
    $myuser = user_load($user->uid);
    $myuser->$role[4] = 'Member';
    user_save($myuser);

```

where I already know that the Member role is stored at key 4 (I did a print\_r on user who is assigned that role and I see

```
 [roles] => Array ( [2] => authenticated user [4] => Member )

```

# Answer
> 9 votes
```
$uid = 123;// User ID of user that you want to add role to.
$role_name = 'Role to add'; // The name of the role to add.
if ($role = user_role_load_by_name($role_name)) {
  user_multiple_role_edit(array($uid), 'add_role', $role->rid);
}

```

Is how you should do it in Drupal 7. See https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user\_multiple\_role\_edit/7

# Answer
> 0 votes
load the user by uid and send the user object to this function and the role name this function will add role to the user

```
   // Add new role to existing roles.
    function add_role_to_user($account, $role){
      // Add new role to existing roles.
        $role_name = $role;
        if (isset($account->uid) && $account->uid > 0) {
          $userId = $account->uid;
          $newaccount = $new_role = array();
            // If the user doesn't already have the role, add the role to that user.
            $key = array_search($role_name, $account -> roles);
            if ($key === FALSE) {
              // Get the rid from the roles table.
              $roles = user_roles(TRUE);
              $rid = array_search($role_name, $roles);
              if(is_numeric($rid)) {
                $new_role[$rid] = $role_name;
                $newaccount['roles'] = $account -> roles + $new_role;

              }
            }

            user_save($account, $newaccount);
        }

    }

```

add the above function and add this code to add role to user

```
$user = user_load(1);
add_role_to_user($user,"Role name");

```

Here added sample uid add your own uid and pass will add role to the user if you want to update multiple use loop in the two line code will solve your problem

---
Tags: users
---


title: Memory Time-out

text:
# Question
Title: Memory Time-out
I am saving a lot of entities as part of a script - several thousand.

This is frequently causing out of memory errors.

I've been trying to do something like this:

```
cache_clear_all();
drupal_flush_all_caches();
$entity = NULL;

```

After entity save ($entity is the variable for the entity object), but nothing is working.

How do I clear the memory for the past entities? There is no use for it after the entity is saved.

# Answer
If you have to perform long "bulk" actions, I suggest you three ways:
> 3 votes

# Answer
In /etc/php5/apache/php.ini increase the max\_execution\_time this may solve your problem.
> -2 votes

---
Tags: entities
---


# Question
Title: How do I set up the Crumbs trail For Commerce Kickstart Checkout?
Using Crumbs 7.x-1.10

During Checkout, the standard flow is 3 pages:

Cart ---\> Shipping ---\> Review

But at that last (3rd) step the Crumb trail shows

Home \> Checkout \> Checkout \> Checkout

How do I set the Crumb trail to reflect the page H1s?

1. Is this done via the standard Setup page or 2. Does it require a plug-in? And if a plug-in can someone give me an example for this use case? Frankly, I'm having trouble understanding the nomenclature of both the std. Setup -and- the plug-ins of the docs.

# Answer
You will have more luck with Crumbs 7.x-2.\*.

See also
> 0 votes

---
Tags: breadcrumbs, commerce
---


# Question
Title: Editting/Modifying markup of registration form
I would like to over ride the default registration form of Drupal. I want to edit its mark-up. Add few classes and wrap them with few div tags. I don't know how to get this done ? Is it possible to over ride like what we do for html.tpl.php ? I mean copy pasting a particular file some where from system into the template folder and edit it ? Please help me. I am very much new in Drupal.

# Answer
You can use hook\_form\_alter to alter the registration form. This allows you to add markup, change labels, add divs, ...

Also to add markup, you could have a look at markup field

ANd last but not least, check out this page: https://www.drupal.org/node/350634. It contains a lot of info on how to override the user login/registration page

```
function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id === 'user_register_form') {
    // perform other changes here
  }
}

```
> 1 votes

---
Tags: users
---


# Question
Title: Access denied on image styles files on Drupal 7.34
As you can see in the screenshot below, images that are processed through image styles aren't showing up and when trying to display them through their urls, we get a 403 access denied.

It's a fresh drupal install on a Debian 7 with no additional modules

Any ideas are welcome to overcome this problem

Thanks

# Answer
> 2 votes
It's common to have incorrect permissions on that folder. You'll need to fix the permissions for `/site/default/files` directory. For a complete answer, see the recommended directory permissions or just run the following from the website root (per @David's comment below).

```
find sites/default/files -type d -exec chmod 755 {} +
find sites/default/files -type f -exec chmod 644 {} +
chown -R www-data:www-data sites/default/files

```

For additional issues, check Status Reports on `yourWebsiteName.com/admin/reports/status`.

# Update:

I think I found the issue.

There was a similar question asked on Drupal.

It seems that the issue is that certain hosts, such as BlueHost, HostMonster and Virtualmin forbid `+FollowSymLinks`. You will need to change `+FollowSymLinks` into `+SymLinksIfOwnerMatch` in your `.htaccess` file. See an entire discussion on Drupal.

# Answer
> 0 votes
In my case, the problem was just that sites/default/files had the rights set as 544 but needed to be 744. I am not sure why the prohibition of write results in the unability to read. So as this is a bit unintuitive I thought it might be useful for anybody with the same problem.

# Answer
> -2 votes
Go to Terminal by pressing Ctrl+T Type : `cd /var/www/drupal` ( assuming it to be the drupal root for your site )

sudo chmod 777 -R sites/default/files

Now clear cache and try to update the previously created image style

---
Tags: 7, media
---


# Question
Title: Is there any way to know which theme hook or template is being used to output certain area of a page
Is there any way to know which theme hook or template is being used to output certain area of page? I am showing different menus on a page and i want to know which theme hook is being used to output particular menu and links of menu.

I tried `dpm($variables)` in `function theme_menu_links($variables)` in common.inc just to make sure if this theme hook is being used to output the links of menu but this theme hook is not being called and no output is printed. Then certainly this theme hook is overridden by other module or by theme.

Is it possible to know list of all available hooks and templates files for a particular are of a page like block, menu etc with the active theme hook used to output that area?

# Answer
> 2 votes
Yes, there is a module for that: Theme Developer.

> Firebug for Drupal themeing

Note that this is a heavy module, enable it only when needed and on your local machine.

# Answer
> 1 votes
There is no single (active) hook to define an area (that's the idea of hooks). But there is one initial function defined by a module or theme and other modules and themes can alter the initial output.

If you have devel module installed, you can see the theme registry. This is a list of themable items with all files and (pre)process functions. So once a another hook alters an item it is listed there. Works great for entities, but I have never used it on menus. You can give it a try.

You'll find it at /devel/theme/registry

---
Tags: theming
---


# Question
Title: Printing block on all pages of a contenttype
In my page--front.tpl.php i have a menu block rendered using:

```
<?php
$block = block_load('menu', 'menu-basic-menu');
print render(_block_get_renderable_array(_block_render_blocks(array($block))));
?>

```

Which works as expected.

What should i do to print this block on all pages of a specific content type?

Help appreciated

# Answer
To print my block per content type i used following code in my template file:

```
<?php
function themeName_preprocess_page(&$vars, $hook) {
  if (isset($vars['node'])) {
  // If the node type is "blog" the template suggestion will be "page--blog.tpl.php".
   $vars['theme_hook_suggestions'][] = 'page__'. str_replace('_', '--', $vars['node']->type);
  }
}
?>

```
> 0 votes

# Answer
You can created the `page.tpl.php` and put a condition to check the content type then print this block.

page.tpl.php API Drupal 7

From node object you can find the content type to check condition.

```
<?php print_r($node);?>

```

More specific to your question.

```
<?php global $node;
    if ( isset($node) && !empty($node) && $node->type == 'type_name') {

            $block = block_load('menu', 'menu-basic-menu');
            print render(_block_get_renderable_array(_block_render_blocks(array($block))));

    }
 ?>

```
> 2 votes

---
Tags: theming, blocks
---


# Question
Title: Javascript added via drupal_add_js() does not get aggregated
I have a couple custom modules that I add javascript via drupal\_add\_js(). I have all the Bandwidth Optimizations options checked in the performance page (/admin/config/development/performance).

Since I have Aggregate JavaScript files checked, should all my javascript files be aggregated into one file? Is this normal behavior?

# Answer
The reason it wasn't aggregating is that someone had every\_page set to FALSE and preprocess set to FALSE(as @thedotwrite was saying in comment above) in a lot of drupal\_add\_js() calls. (Some of them were set like this because they really shouldn't have been on every page but there were some that really could be on every page).

Not sure why I didn't notice that before :)
> 0 votes

---
Tags: performance, javascript
---


# Question
Title: Bitnami Installation forcing me to flush caches while theming
I recently set up a Drupal 7 installation on an AWS ec2 instance with Bitnami.

When I'm theming, or editing any kinds of files in the sites directory a regular browser refresh won't show the changes, I need to hit Flush all caches \> Css and Javascript to view the changes.

I've disabled caching in Development \> Performance, and I don't have Advanced Agregation installed or anything.

Is there something to the Bitnami installation, or ec2 that could be caching the theme files?

# Answer
> 1 votes
Update for anyone who comes here in the future:

Bitnami comes with Google PageSpeed installed & enabled by default It's a pretty useful tool, but it's tricky to figure out what's caching your css when there's nothing apparent.

To check for it, take a look at the of your drupal site & look through the `<meta>` & `<style>` tags for compressed css files, they'll look like `lkjsdhf.gkdfsgklkshr.pagespeed.kljhasdfgk.ljsdhflgk` or somesuch.

To disable it, navigate to your installation's apache configuration folder, mine was `/home/bitnami/stack/apache2/conf` & edit `pagespeed.conf`

Look for the line `ModPagespeed on` (mine was line 20) and change `on` to `off`

After that, restart Apache. You can also log into AWS and reboot your instance.

---
Tags: 7, theming, caching
---


# Question
Title: How to avoid invoking the same module every time when I have to call a function of that module in Drupal 7?
When there is a need **to call a function inside a module**, some of you say- **it is good to use `module_invoke()` inside the template pages to call the function(it looks great-since I can pass arguments too).**

Using Drupal 7. So for the first time, it is okay. Even for the second time, it makes a bit extra effort in the code, but somehow I can manage it.

Now it is invoking again and again, the same module. Say if the module is `block`, and the function is `hook_block_view()`\- I doubt, **it could affect the Drupal site performance(the time for loading the page contents)**, what do you think? Is there a solution for this problem?

```
<?php
  $header_block = module_invoke('block', 'block_view', '2');
  print drupal_render($header_block);
  $news_block = module_invoke('block', 'block_view', '3');
  print drupal_render($news_block);
  ...
  ...
  $footer_block = module_invoke('block', 'block_view', '12');
  print drupal_render($footer_block);
?>

```
* **Is it a good idea to use the `module_invoke()` every time when I have to call `hook_block_view()` with different arguments?**
* **Is there any other function that can be used for calling the same function or any other function in the module after one- `module_invoke()`?**
* **Is there any other way of doing thing?**

# Answer
> 2 votes
You're calling the same function over and over, that's true. But the parameters are different, so from a pure programming point of view, the processing could be completely different. I don't see another option to approach this.

* Is it a good idea to use the module\_invoke() every time when I have to call hook\_block\_view() with different arguments? **Yes**
* Is there any other function that can be used for calling the same function or any other function in the module after one- module\_invoke()? **Not that I'm aware of**
* Is there any other way of doing thing? **I don't think so**

More specifc, some functions allow passing an array of arguments instead of one. Eg node\_load\_multiple allows to pass 1 nid or whole list of nids. But hook\_block\_views doesn't allow this.

---
Tags: 7, performance, blocks
---


title: embed flexslider in fields

text:
# Question
Title: embed flexslider in fields
I need to create several nodes of the same type and all have to have an image carousel similar to what flexslider does in Views.
I already deleted the Views example but cannot replicate the behavior in a field in spite that I formatted the field with flexslider full, I just get the images displayed one below the other.

# Answer
> 1 votes
Check the following:

1. What version are you using? There was an issue with Fields and alpha 2.
2. Are the libraries downloaded to the correct location? Check the project page for instructions.
3. If the libraries are there, does the webserver user have permission to read the libraries?

---
Tags: javascript
---


# Question
Title: Watchdog "404 page not found" entries from spambot guessing urls
Browsing through the watchdog list I found a lot of **page not found** entries with urls like:

```
http://example.com/wp/wp-trackback.php
http://example.com/phpMyAdmin-2.5.5-pl1/index.php
http://example.com/flpurrbiao.html
http://example.com/gxksjgjrwk.html

```

What's best practice to stop these hits?

# Answer
> 2 votes
Block them using these modules, study these and related modules for perfect working solution to your need :

http://drupal.org/project/httpbl

http://drupal.org/project/badbehavior

http://drupal.org/project/antispam (Apart from blocking comment spam, disables bot showing 403 error)

http://drupal.org/project/botcha

Install http://configserver.com/cp/csf.html and use Real Time Block Lists (RBLs)

And finally a free-service like http://www.cloudflare.com/features-security will get things working.

# Answer
> 0 votes
I had watchdog spam logging issue for several months when I came to this post, and in my case by installing and activating **httpbl** has solved immediately the problem.

---
Tags: advertising, log-messages
---


# Question
Title: How to create a custom frontpage using page--front.tpl.php and keep theme responsiveness
I want my frontpage to be displayed with a full width image, some H2 header text and a navigation menu.

However using a page--front.tpl.php and applying custom css i am losing the natural responsiveness of my theme (at-subtheme), leaving me to apply mediaqueries.

What would be the apporiate way to set up a custom front page using my theme responsiveness?

# Answer
There are different ways to set up a frontpage in drupal. I think the 2 most used ways are panels or context.

Panels allows you to create a page through drag and drop functinality. Almost every piece of content created in drupal (nodes, views, blocks, custom blocks, ...) can be added to a panel. In addition to that, if you use for example "omega" as a base theme, omega has a couple of default (responsive) build in templates you can use with the panels module.

Context allows you to expose content through conditions. So you can expose a block, view, node,... only on your frontpage. You will have to apply css to make your frontpage responsive though...

Both modules have there advantages and disadvantages, you should check them out and decide which is best for you. I'm certain there are other ways to create a frontpage, but this is how I usually get the job done.
> 1 votes

---
Tags: theming
---


title: custom user profile pages

text:
# Question
Title: custom user profile pages
I am working on a directory for a membership organization.

I am trying to create two distinct user pages. One for the user themselves (and admins) and one for the public to view. I would like these formatted differently, not just show different fields (which I could do simply with permissions, right?). And these public pages need to include Profile2 profile data.

I have tried editing the `user-profile.tpl.php` page. For example:

```
<div class="profile"<?php print $attributes; ?>>

  <?php print render($user_profile['field_first_name']); ?>
  <?php print render($user_profile['field_last_name']); ?>

</div>

```

...but this seems to have no effect on the user page at all, even when I clear all caches. (Perhaps because I'm using Display Suite to layout the user profile page? Does that override everything else?)

I also created a View:

* Contextual Filter

+ User:Uid
    + Provide default value: Type = User ID from URL
    + Specify validation criteria: Validator=User
* Relationship

+ User:Profile
    + Profile types (all 3 custom profile types chosen)
* Path: /users/%user

But I'm still just getting the Display Suite layout. Is that doing the override?

# Answer
DS uses it's own templates. Go to admin/config/people/accounts/display, then scroll to the bottom and DS will show you which templates you can use to overwrite the output.

In the example below there are 2 suggestions. Hope this helps you out.
> 1 votes

---
Tags: views, users, display-suite
---


# Question
Title: How to redirect language prefix to language domain (TLD)
I have a single Drupal 7 install running in 2 languages, on 2 domains, but currently using a language prefix as selection. Content can be access as follows:

> **English**
> mysite.com/content/wonderful
> mysite.de/content/wonderful
>
> **German**
> mysite.com/de/content/wunderbar
> mysite.de/de/content/wunderbar

I will change to domain language selection, so that one language is accessible on each domain:

> **English**
> mysite.com/content/wonderful
> **German**
> mysite.de/content/wunderbar

The setup works wonderfully on my dev server, but all the old links with the /de/ language prefix will be broken.

Is there a way to 301 them all with one fell stroke? Or how can I detect and strip the prefix in /de/content and at the same time redirect to .de/content? Is this best accomplished in .htaccess?

For German content, the appropriate redirect pattern would be as follows:

> mysite.com/de/content/wunderbar -\> mysite.de/content/wunderbar mysite.de/de/content/wunderbar -\> mysite.de/content/wunderbar

Since English has no language prefix, how can I subsequently detect English content that is trying to be accessed on the .de domain and redirect accordingly?

# Answer
I had the same issue and solved it by putting a 301 redirect in the htaccess file:

```
# 301 rewrite for all prefixed language nodes to their own domain
RewriteRule ^en/(.*)$ http://example.com/$1 [L,R=301]
RewriteRule ^de/(.*)$ http://example.de/$1 [L,R=301]

```

Then I generated a new sitemap and inserted it in the google webmaster tools. I'll monitor the performance impact of this solution. Update is coming in two weeks!
> 2 votes

---
Tags: redirection, i18n-l10n
---


# Question
Title: Entering inner fields after attaching a field collection entity programmatically
CONTEXT

Adding a node with its field-collection field and inner fields **programmatically**. Saving the node. Then trying to reach the inner fields - bam! - they are not in the array!

MORE INFO

if I am adding the node **manually** (not by code) and then trying to get to the inner fields - they ARE there.

**\[Edit\] - The same problem of undefined inner field happens if saving using VBO (Views Bulk Operations module). So, can it be that the *structure* is bad? However, I have built the collection field using the manual interface only, not by code.**

CREATING A NODE WITH FIELD COLLECTION

```
$node = // Creating a node
$fc_item = entity_create('field_collection_item', array('field_name' => $field_machine_name));
$fc_item->{$field_machine_name}[$node->language][$index][$value_column_name] = $field_value;
$fc_item->setHostEntity('node', $node, $node->language);
$fc_item->save(TRUE);
$node = node_submit($node);
node_save($node);

```

TRYING TO GET INSIDE FIELD COLLECTION JUST MADE

```
$value = $node->field_coll_print_authors['und'][0];
print_r($value);

```

I get:

```
Array
(
    [value] => 278 // This is the field collection item id
    [revision_id] => 1533
)

```

However, what I would have expect, and what I actually DO HAVE when adding a node of the same type by hand is:

```
Array
(
    [field_print_author_last_name] => Array
    (
        [und] => Array
        (
            [0] => Array
            (
                [value] => amir // This is the value I need
            )
        )
    )

```

HELP

Well, is there any function I have not called in order to attach the field collection item properly to the node? Or something else is missing?

Thanks for your help!

# Answer
> 1 votes
Field collections are **not** stored in full with the Loaded node access via node\_load(); only their entity ID.

The data *does* sometimes look like that, for example in a node form (because it actually has to create fields for them) and in a rendered node via node\_view()(depending how you have set it in the view mode settings).

But you can load them easy enough and get the values that way.

Here is an example :

*Dynamically creating a node with multiple field collections :*

```
  global $user;
  $type = 'floor_staff_checklist';
  $event_id        = 12345;

  $chk_node        = new stdClass();
  $chk_node->type  = $type;
  $chk_node->title = '';
  node_object_prepare($chk_node);
  $chk_node->uid                           = $user->uid;
  $chk_node->nid                           = 0;
  $chk_node->status                        = 1;
  $chk_node->promote                       = 0;
  $chk_node->field_event[LANGUAGE_NONE][0] = array(
    'target_id'   => $event_id,
    'target_type' => 'node',
  );

  if ($type == 'floor_staff_checklist') {
    $time = strtotime("01-01-2000 19:30:00");
    for ($i = 0; $i < 22; $i++) {
      $strtime = date("H:i", $time);
      $time += 1800;
      $flrchhk_fc = entity_create('field_collection_item', array('field_name' => 'field_floor_check'));
      $flrchhk_fc->setHostEntity('node', $chk_node);
      $flrchhk_fc->field_check_time[LANGUAGE_NONE][0]['value'] = $strtime;
      $flrchhk_fc->save();
    }
  }

  $chk_node = node_submit($chk_node);
  node_save($chk_node);
  drupal_goto("node/$chk_node->nid");
}

```

In this situation, I am creating a node, and creating 24 field collections within it, one for every hour, then saving the node.

*And if you want to view the data :*

```
$entity = entity_load_single($chk_node->nid);
if (isset($entity->field_floor_check[LANGUAGE_NONE]) && !empty($entity->field_floor_check[LANGUAGE_NONE])) {
  $fcs = array_column($entity->field_floor_check[LANGUAGE_NONE], 'value');
  $items = entity_load('field_collection_item', $fcs);
  foreach ($items as $item) {
    dpm($item);
  }
}

```

This will load the node, access its references to the field collections, load them, and loop through them printing the contents through Krumo (Devel module).

# Answer
> 0 votes
You have to load the field collection entity. You could use:

```
$field_colection = entity_load('field_collection_item', array($node->field_coll_print_authors['und'][0]['value']));

print_r($field_collection);

```

the $field\_collection object will contain all data you need ;)

---
Tags: entities
---


# Question
Title: how do I disable modules in commerce kickstart
I thought I needed dashboard and block languages modules for blocks. I enabled them and now want to disable them again but the update button has been replaced with an install button on the site settings -\> modules admin page. How do I disable them?

# Answer
> 1 votes
Scroll down to bottom of left column for save button.

A module worth mentioning is https://www.drupal.org/project/module\_filter. It makes the module page a lot more user friendly.

---
Tags: 7, commerce
---


# Question
Title: How to change the referenced entity field value?
I have a node that has a node reference to another content type. What I want is to update the referenced node field value on updating the node;

Let me clarify the issue.

For example I have a node of type "Basic Page" which having a relationship to a node of type "Article". I want to sync fields in two node let say I have a name field(Text) in both nodes. On updating basic page node I want to populate the referenced node Name field with that of the value in the basic page node Name field. How can I do that?

This is what I have done so far:

1. Event - After updating existing content.
2. Condition - Content is of type Basic page.
3. Action - Fetch entity by id(id from the entity reference field).
4. Action - Set a data value .

I am stuck at the fourth step I can't select the name field of the entity fetched in the data selector.

How can I populate the referenced node field with the value of the blog page node field?

Note: This is just for example In real case I want to map multiple fields from one node to another.

This is the exported rule:

```
{ "rules_on_updating_basic_page_nodes" : {
    "LABEL" : "On updating Basic Page nodes",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_update" : [] },
    "IF" : [
      { "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "page" : "page" } } } }
    ],
    "DO" : [
      { "entity_fetch" : {
          "USING" : { "type" : "node", "id" : [ "node:field-article:nid" ] },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
        }
      }
    ]
  }
}

```

# Answer
> 1 votes
You have to add a Condition to the rule of the class: "Entity has field", and then a whole bunch of the referenced fields of the entity will appear.

# Answer
> 0 votes
You will need to make it call a Rule Component as you need to specify conditions before the available options in the Rules interface will be available.

As you're fetching an entity these options won't be available.

---
Tags: 7, rules
---


# Question
Title: How to access a field of a referenced entity in a computed field?
I would like to access a field of a referenced entity in a computed field.

For example: The content type A contains an entity reference field referencing the content type B; B has a "price" field. A has a computed field as well. In this field I would like to load the value of the "price" field from the referenced node.

How can I achieve this?

# Answer
> 0 votes
Only, you have to add a Condition (in 'Elements') to the rule of the class "Entity has field", and then a whole bunch of the referenced fields of the entity will appear and will be available.

You'll have to create another Component to call it and add it another Condition of "Entity has field" of the same bundle you want to access.

---
Tags: entities
---


title: handling file upload for drupal 6

text:
# Question
Title: handling file upload for drupal 6
I have a question about handling file uploads. I am trying to implement a form that will allow the user to upload a file. I do not need to store the file, though. I just need to take the uploaded file, where its location happens to be, and pass it to an outside API, which uploads it to its server (its Jira). Is there a way to do this? The file has to be publicly available to be consumed by Jira's API (in other words, Jira won't be able to provide a username/password to validate against drupal). This is what I have, so far:

in my \_add\_form hook:

```
$form['file'] = array(
                '#type' => 'file',
                '#title' => t('Document'),
                '#description' => t('Upload a file, allowed file types: pdf, images, documents'),
            );

```

in my \_add\_form\_validate hook:

```
$validators =  array(
                'file_validate_extensions' => array( 'jpg jpeg gif png bmp txt doc docx xls xlsx pdf ppt pptx ' )
            );

            $file = file_save_upload('file', $validators);

            if (isset($file->filename)) {
                $form_state['storage']['file'] = $file;
            }

```

in my \_add\_form\_submit hook:

i can see the object form\_state-\>storage-\>file but I don't see the full path to where the file is residing. All i see, thats close, is:

```
 file_name = "myfile.jpeg"
 file_path = "/tmp/myfile.jpeg"
 destination = "/tmp/myfile.jpeg"

```

but, as I mentioned, I need to full path to pass to another, external, API so that the file can be consumed. I do not need to store or save the file afterwards.

admin/settings/file-system settings:

```
File System Path:  sites/mySite.net/files
Temporary Dir: /tmp
Download Method: Private

```

# Answer
Ok here is high level overview of the file uploading. I took most of this from the Drupal 6 Developer modules but made some changes that should get you started on how to achieve your final goal here. I left all the original comments and denoted any new comments with `// ** Comment Text` so you should be able to skim through this and get the general idea.

```
<?php

//////////////// Tutorial Example 11 //////////////////////

// ** Will denote any changes or anything that I am pointing out below.

/**
 * Example 11: A form with a file upload field.
 *
 * This example allows the user to upload a file to Drupal which is stored
 * physically and with a reference in the database. In this example, only
 * png, gif, jpg, and jpeg files are allowed.
 *
 * @see form_example_tutorial_11_validate()
 * @see form_example_tutorial_11_submit()
 * @ingroup form_example
 *
 */
function form_example_tutorial_11($form_state) {
  // This is required to upload files.
  // enctype="multipart/form-data" required by browsers to handle files.
  $form = array(
    '#attributes' => array('enctype' => "multipart/form-data"),
  );

  $form['file'] = array(
    '#type' => 'file',
    '#title' => t('Image'),
    '#description' => t('Upload a file, allowed extensions: jpg, jpeg, png, gif'),
  );

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

  return $form;
}

/**
 * Validate handler for form_example_tutorial_11().
 * Verify the valid extensions, and verify content is an image also.
 */
function form_example_tutorial_11_validate($form, &$form_state) {

  // ** I just left this as image but you can change the ext array if needed.
  $file = file_save_upload('file', array(
    'file_validate_extensions' => array('png gif jpg jpeg'),
    'file_validate_is_image' => array(),
  ));

  // If the file passed validation: ** File is in /tmp folder now
  if (isset($file->filename)) {
    // Move the file, into the Drupal file system
    // ** Notice the 'jira-upload/', this would be where your file is placed,
    // ** It will be in your /files folder, but you need to make this directory,
    // ** You can do it in code but for simplicity I just left it as is for now.
    if (file_move($file, 'jira-upload/' . $file->filename)) {
      // Update the new file location in the database.
      // ** Change from /tmp/filename.ext to,
      // ** /sites/default/files/jira-upload/filename.ext in database.
      // ** This will be important for Drupal later.
      drupal_write_record('files', $file, 'fid');
      // Save the file for use in the submit handler.
      $form_state['storage']['file'] = $file;
    }
    else {
      form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
    }
  }
  else {
    form_set_error('file', t('Invalid file, only images with the extension png, gif, jpg, jpeg are allowed'));
  }
}

/**
 * Submit handler for form_example_tutorial_11().
 */
function form_example_tutorial_11_submit($form, &$form_state) {
  $file = $form_state['storage']['file'];
  // We are done with the file, remove it from storage.
  unset($form_state['storage']['file']);
  // Make the storage of the file permanent/temp
  // ** This will actually make it where you don't have to delete,
  // ** You can let Drupal clean it up later on cron runs after a certain,
  // ** Amount of time. This will be done automatically.
  file_set_status($file, FILE_STATUS_TEMPORARY);
  // ** This is what you wanted, was the public file that can be navigated to,
  // ** This should work pretty well, but there are other ways.
  // ** Since validation is already passed I would run the API call here as,
  // ** Well. You could pass the $file object to another function or your pref.
  $fileurl = file_create_url($file->filepath);
  // Set a response to the user.
  // ** I added the $fileurl so you could see it on the frontend,
  // ** Without having to know if devel is there.
  drupal_set_message(t('The form has been submitted and the image has been saved, fileurl: @fileurl. filename: @filename.', array('@filename' => $file->filename, '@fileurl' => $fileurl)));
}

?>

```

Note: For this to work with the way you are wanting to curl the image and send it you will need to set your file system to public. I'm placing a screenshot of that page with configuration.

**Additional Hook:**

If your file system is private you will have to run an additional hook in order to allow access to the file through Drupal without having it attached to a node or anything. I tested this with making my file-system private and clearing out all previous images, then along with the code that I edited from the Drupal 6 Examples module I placed the code below in the main module file (just incase anyone needs to know how to test this out without knowing all the code). This should give you the functionality that you need without having to change the file-system.

```
<?php

/**
 * Implements hook_file_download().
 */
function form_example_file_download($file) {
  //dpm($file);
  // Used jira- as indicator but it needs to match your folder where you are storing your files.
  if (strpos($file, 'jira-') === 0) {
    $info = image_get_info(file_create_path($file));
    return array('Content-type: ' . $info['mime_type']);
  }
}

?>

```
> 0 votes

---
Tags: 7, files
---


# Question
Title: Combine Token title with url in an email
I send emails automatically to users. There is a link in these mails, which points to a node. But I want to use the node title as an alias for this link, so that the link is not directly displayed in the mail.

Currently I use a 'text\_format' form element, where I wrote the content of the mail with the corresponding HTML code for the link:

```
<a href="[node:url]">[node:title]</a>

```

Because this just works with 'full html format', it might be possible to accomplish it in another way?

I would welcome every advise!

Thanks, Daniel

# Answer
> 0 votes
Have you tried the token\_replace function?

---
Tags: 7, forms, tokens
---


title: CSS file is not attached

text:
# Question
Title: CSS file is not attached
I set at the .info module file the parameter to add a css file,

```
stylesheets[all][] = css/style.css

```

but it is not attached even if I clear the cache.

I have look for the web to get the reason but apparently is all I might have to do.

Anybody could tell me what am I missing please? Here the code: https://github.com/jmvelasco/drupal

**The js files are attached.**

Thanks in advance.

# Answer
> 1 votes
I loaded your module into my dev, there were some install errors but I got through that part to the actual problem you are having. You need to rename your CSS file. The common convention is to name it 'slider.css', since that is the name of your module. It never gets loaded with the 'style.css' though due to your theme probably having the same named stylesheet. Once I changed the name it loaded after clearing the cache. Hope that helps, will post a more detailed explanation when I have a little more time.

Also: See comment about using '#attached' method for this. It would be cleaner. Original Comment: 'If you are trying to attach CSS that is supposed to show up on a page hen that block is present you should be using 'attached' to load the CSS. Ref: drupal.org/node/2278795'

In your current module code you can use #attach method like below:

```
   <?php
   // Line 134 of slider.module, make content array and use #markup for content
   // Then use #attach method to finish out render array.
   $block = array(
        'subject' => t('Show Nodes Block'),
        'content' => array(
            '#markup' => $output,
        ),
    );
    // Add CSS File with changed name as well.
    $block['content']['#attached']['css'] = array(
        drupal_get_path('module', 'slider') . '/css/slider.css',
    );

    return $block;

    ?>

```

# Answer
> 2 votes
It could be as simple as just clearing cache or just visiting the 'modules' page in your admin. The content of .info files is cached and isn't reloaded with every page visit.

# Answer
> 0 votes
You should clear the caches.

Another alternative would be to use a module for CSS. This is a great article about modules for css. CSS for Drupal 7 Site Builders

---
Tags: 7, theming
---


# Question
Title: Are configurations written and read directly to/from .yaml files or still to the database?
**Background**

Drupal 7 and previous versions have attracted criticism for Drupal web site admin configuration being stored in the MySQL database, the criticism being that being in a database means that it cannot be directly managed in git together with the PHP code based development for a Drupal site (custom modules, themes etc.).

Secondly with configuration being in the database along with content, transporting configuration between development, test, staging and live servers as part of development activity is complicated, though Features module (and related) can help.

Reading through: https://www.drupal.org/documentation/administer/config

...I'm getting the impression that, in Drupal 8, the database is still used to store the config, when for example a site builder creates a new content type, rather than this being written to a .yaml file which is used directly.

So actually it seems that the role of the yaml file(s) is a much more purer (than Features) vehicle for the configuration. Whereas with Features it was PHP code which was harder to read what the configuration was, including if doing diffs between commits where config had been updated resulting in a new version of the Features-based config export. By that I mean not that PHP itself is hard to read, as I'm familiar enough with it, having written custom modules, hooks, themes. What I mean is that to express a configuration in PHP is perhaps not the most legible way to do it. So I can see the rationale of using yaml. The difference is that yaml will be read by a parser to apply a config. The complexity of applying the config is in the parser, which most folks need not concern themselves with most of the time, so the yaml can more cleanly describe the config. whereas in Features, there is no parser / yaml (or other script) separation. The descripton of the config and the means to apply it are necessarily in the same place as PHP code which is executed directly, so it's bound to be a bit harder to read the config, particularly if doing git commit diffs.

So there's the rationale for yaml, a Declarative Programming approach to storing configuration management in Git, contrasted with Features which is an Imperative Programming approach. And next what I need to know is this the case that Drupal 8 does still store config in the database does still and yaml files are the means for transporting config (replacing what Features did in D7 and before)?

(By the way I am a big fan of Drupal and spend most of my time at work, working with it for the sites that my organisation produces and maintained and am also involved in the community. So this question is not a stealth campaign against Drupal in favour of other platforms. It is a genuine question to try to dispel the apparent mystique around Drupal 8 and the new config management system)

**Update** @Berdir's answer (accepted) is a great definitive summary as to the state of Drupal 8 regarding configuration management.

I recently discovered that using yaml for config in Drupal 8 is a concept that has been developed for Drupal 7 with the Patterns module, also read a FAQ on it which includes comparing features.

**Update**

Change default active config from file storage to DB storage Is a definitive answer about making config active from DB storage, which corroborates with @Berdir's answer.

# Answer
Yes and no. (I am not sure if this will be too technical).

The configuration is stored in configuration objects. Drupal has by default an active and a staging storage for those configuration objects.

The default active storage is in the database, yes, for performance and easier backup/restore, among other reasons. But that is an implementation detail. It used to be read directly from files, but that was pretty slow, even with caching.

The staging storage is yaml files in the staging folder in your file system. Those are the files you manage in git.

You can export to staging and import again from staging through the click of a button in the UI or with drush. Unlike Features in Drupal 7, which uses custom processing to transform configuration between feature files and the actual drupal site, the configuration object structure is always the same. Serialized to yaml for the file storage, as serialized php arrays in the database storage. Drupal does not care (for the most part, but that is too technical). If you want to, you could write a configuration storage that stores it encoded in pictures, as long as Drupal can get the standardized array structure out of it again that it put into the storage.

So, yes, the configuration is by default still stored in the database, but not in the way you were used to in Drupal 7.
> 10 votes

---
Tags: 8, configuration
---


title: marinelli banner images not cycling

text:
# Question
Title: marinelli banner images not cycling
drupal 7 marinelli banner images not cycling (no forward or back icons either) I had disabled banner for a while and on trying to re-enable, images load but don't cycle. my back up site works but main site is too far changed to restore from months ago. I have tried removing and re-installing theme. where does the theme store settings?
What can I do? Thanks Mick

# Answer
Given the error 'TypeError: $.browser is undefined' I would surmise that there is a discrepancy in the version of jquery running. If you have the module jQuery update installed and running on one or both, check to see if both sites are running the same version of jquery.
> 0 votes

---
Tags: 7
---


# Question
Title: Can I set up Paypal recurring payments on Commerce Kickstart?
Like the title suggests, I am using Paypal for provide an apparent 'Trustworthy' service to my customers. I offer a flat-price cleaning service. I would like to offer a weekly, fortnightly and monthly service to my current 'products' at different discount rates on the original product. can someone help me perform this?

# Answer
The only existing module-based solution is Commerce SP plus Commerce SP PayPal.

The latter is in dev at the moment, but I've found it to work pretty well, albeit with a few minor business-specific alterations.
> 1 votes

# Answer
This can be done by adding a product pricing rule, checkout this video http://vimeo.com/22625018, nothing to do with recurring payments here :)
> 1 votes

---
Tags: commerce
---


# Question
Title: How to add more than 7 links in the shortcuts bar?
I just noticed that there is a limit of links to add to the Shortcut bar. Is there any way to change this, I need no limit at all.

# Answer
It's the `shortcut_max_slots()` function that makes that decision; fortunately that function wraps around the return of a variable from the database (also called `shortcut_max_slots`), so you can simply set that variable and be done with it.

There's no way to make it unlimited without hacking the shortcut module directly, so you probably want to go for a high number:

```
variable_set('shortcut_max_slots', 100);

```
> 6 votes

# Answer
You also can change it in `settings.php` like this:

```
$conf['shortcut_max_slots'] = 10;

```

Taken from here https://www.drupal.org/node/682000
> 2 votes

---
Tags: users
---


# Question
Title: Pathauto deactivate when I use node_save($node)
I'm trying to save a node code wise (like I've done a dozen times before), but for some reason, my custom URL given with the Pathauto module, disappears... The `Generate automatic URL alias` checkbox is checked and Drupal ignores my custom URL...

I've tried to give a custom URL with the URL-alias like:

```
$path = 'events/blablabla';
$node->path = array('alias' => $path);
node_save($node);

```

But that didn't work out either. So I'm wondering what do I do wrong. As far as I can see, there seems to be a bug in the module, but I have no clue how to solve this.

# Answer
You'll need to set:

```
$node->path = array('alias' => $path, 'pathauto' => FALSE);

```
> 3 votes

# Answer
As this similar question points out, its as easy as:

```
  $node->path['pathauto'] = 0;

```
> 0 votes

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


# Question
Title: Change commerce kickstart admin toolbar logo
Hello I want to change the logo of the admin toolbar of commerce kickstart how to do it I cannot find any .tpl with that piece of code for chage that logo

# Answer
> 2 votes
Ho it was easy, just add a css class in your subtheme css with the class

```
body.toolbar #toolbar-home a span

```

from there you can change the background image

# Answer
> 0 votes
Your self-answer will only work if you are using the Overlay module. If you aren't, you can go to profiles/commerce\_kickstart/modules/commerce\_kickstart/commerce\_kickstart\_menus/images and overwrite the logo-menu.png image with another 130x40px sized one.

If you want to change anything else in the toolbar (logo size, colors, etc...), that's also the module to look at.

---
Tags: 7, commerce
---


title: Display node in multiple context

text:
# Question
Title: Display node in multiple context
I'm using Drupal 7, and this problem have been tormenting me these past few days :

let's say I'm using the basic content type *Article*, with basic view mode : full and teaser.

Now I'm creating a new content type *Magazine*, which reference multiple *Article* (with the module entity reference). On *Magazine* full view mode, I have set that every *Article* will be diplayed in teaser and linked to its content.

Easy isn't it ? Everything work fine. **Noted that the red block in the sidebar are the same (with contexte module), and as the title**.

Now I'm creating another new content type *Book*, which also reference multiple *Article*. On *Book* full view mode, *Article* are also displayed as teaser linked to its content. And now we have a problem when clicking on a *Article* from book: the sidebar and the title is from *Magazine*, and what I need is to display green block and title from *Book*.

What I get :

What I want :

Is there a way to achieve that ? By contrib or Custom ?

P.S. An article can be referenced in Book, or in Magazine, or both, or neither of them.

# Answer
Sorry all, I had completely forgotten about this un-responded question.

It's been a long time so I don't remember the details. After a deep dive in custom and contrib', I managed to get it done with view\_mode\_page and context

At first view\_mode\_page didn't seems to respond to my need, but after more thorough tests, it do the job pretty smoothly.
> -1 votes

# Answer
You can add query string or another argument to the link of article, for example:

```
node/[nid]/magazine or node/[nid]?ct=magazine
node/[nid]/book or node/[nid]?ct=book

```

After that you need to add visibility to the Book and Magazine block that appears in sidebar.

For Book block:

```
node/*/book

```

For Magazine block:

```
node/*/magazine

```

Hope it will help.

P.S. You can add argument or query string to the link of article through **template\_preprocess\_node** function by changing **$vars\['node\_url'\]**.

P.P.S. Just figured out that you can only use new argument, not query string.
> 2 votes

---
Tags: 7, theming, blocks, entities
---


# Question
Title: Drupal Commerce "let me know when the price goes down"
I've been trying to create a price alert for products of which price dropped (let users flag that product and e-mail them when that product's price drops). For this purpose, I installed Flag and have been trying to make such a thing with it and Rules. Am I on the right track? If not, what can I do?

Regards,

# Answer
In product content type add a new radio field "Would you like to receive an email if the product price change?" with options Yes and No.

Install Token module and Rules module

You can write a rule to send an email whenever the product node price field is updated to only users who has selected Yes option. you can do this by adding a standard available condition or you can execute a custom php code and use Token to access the radio button value.
> 0 votes

# Answer
I ended up using Flag and Rules, and creating a rule still working on it though. Can't add it here (too long) so I can send the export to whoever wishes.
> 0 votes

---
Tags: commerce, rules, flags
---


# Question
Title: Can I manualy add modules in Drupal 7 just by pasting them in the modules folder?
I am unable to install modules in Drupal 7. I'm working on localhost so I don't have FTP, but it seems that they made it impossible to install them otherwise.

In Drupal 6 I would of just paste a module, refresh and there it was. Here I have to specify the FTP.

# Answer
**If you have a single site setup:**

Contrib modules go in /sites/all/modules/contrib/

Custom modules go in /sites/all/modules/custom/

Custom themes go in /sites/all/themes/

**If you have a multi site setup:**

contrib modules go in /sites/site\_name/modules/contrib/

custom modules go in /sites/site\_name/modules/custom/

custom themes go in /sites/site\_name/themes/

I think some of the language in this post is dangerous, remember, do NOT put modules in the root modules directory, that is DRUPAL CORE. Everything you code and download should go in the directories I've mentioned above.
> 1 votes

# Answer
About everything that you'd need to install a contributed module is explained in the following drupal.org article: Installing contributed modules (Drupal 7)

You should be able to just copy/paste the module's folder into your Drupal 7 module folder. Make sure to check the file permissions on your system.
> 0 votes

# Answer
1. Download the required module from Drupal
2. Unzip / Extract it and place it in /sites/all/modules/
3. Access Modules from Administrator end
4. Search for the new module and enable it.
5. You are done :)
> 0 votes

---
Tags: 7, installation
---


# Question
Title: Trouble updating Modules in Drupal 7 with FTP
I'm developing in localhost. When I try to update modules, it requires FTP access. I've tried several ways by installing `vsftpd` and adding my user account to `ftp` group, chowing the files, etc. But, I'm ending up with following message:

*File Transfer failed, reason: Unable to remove to file /media/location-of-drupal/module/blahblah*

Now, I've decided not to use FTP. **Can I just manually download latest copies and unzip \> paste the modules?** Will that work? And is it applicable to updating Drupal core?

Thanks :)

**EDIT:** I've managed to fix FTP, and is now updating modules by FTP. But still, I'd like to know the answer, i.e. does copy-paste works perfectly? I posted my answer here: http://bdhacker.wordpress.com/2011/11/26/update-drupal-modules-using-ftp-in-localhost/

# Answer
Looks like it works. What I figured out is - one needs to:

1. Download any module's updated release, extract and override older version of the module.
2. Run ***update.php*** found in the directory of Drupal's root - very important to update your database.
> 1 votes

# Answer
I had the same effect.

The instructions at http://bdhacker.wordpress.com/2011/11/26/update-drupal-modules-using-ftp-in-localhost/ have all the necessary details. Especially the vsftp config (/etc/vsftpd.conf) is important. Make sure the following options are set:

listen=YES local\_enable=YES write\_enable=YES local\_umask=022

Don't forget to restart vsftpd after config changes.
> 4 votes

# Answer
Well, you could... you could also bring them home on a floppy disk. ;)

Seriously though - get yourself git. Install it on your local machine, create repository (or use a service like GitHub, XP-Dev or whatever else if your machine is not accessible from the internet), and start using proper version control! A bit of hassle at the beginning with setting everything up, but then makes your life tremendously easier...
> 0 votes

# Answer
After all you just have to make sure all your files are transfered in a consistent Way feom your local dev to production.

If you have shell access on production git is an excelent way of doing this. A lot of people are worling rhis way. We have been using rsync succesfully for a long time. FTP is just a remote file transfer tool you have to do at least some manual book keeping that the other tools doing for you once you set them up properly.
> 0 votes

# Answer
You can keep it simple, Just follow the steps below:

1. Download the module from Drupal
2. Extract or Unzip it
3. Place it in /sites/all/modules/ directory
4. Enable the module from admin end
> 0 votes

---
Tags: 7
---


# Question
Title: Avoid caching pages for authenticated users with Varnish
I have the following problem: when a user logs in and navigates through pages that he visited when was an anonymous user, he "sees" the cached page instead seeing the page version for logged users. I'm using Varnish and I have tried the following code without result:

```
  if (req.http.Cookie) {
    set req.http.Cookie = ";" + req.http.Cookie;
    set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
    set req.http.Cookie = regsuball(req.http.Cookie, ";(SESS[a-z0-9]+|NO_CACHE)=", "; \1=");
    set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
    set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");

    if (req.http.Cookie == "") {
      # If there are no remaining cookies, remove the cookie header. If there
      # aren't any cookie headers, Varnish's default behavior will be to cache
      # the page.
      unset req.http.Cookie;
    }
    else {
      # If there are any cookies left (a session or NO_CACHE cookie), do not
      # cache the page. Pass it on to Apache directly.
      return (pass);
    }
  }

```

How can avoid this issue?

Thanks

# Answer
> 2 votes
In your settings.php are you using `$conf['omit_vary_cookie'] = TRUE;` ?

If so, logged in users who have previous viewed a page when logged out will be served the varnish cached version of their page until they manually refresh their browser.

The solution is to simply comment out `$conf['omit_vary_cookie'] = TRUE;` in your settings.php.

This is explained in default.settings.php (drupal 7.34):

```
 /**
 * Page caching:
 *
 * By default, Drupal sends a "Vary: Cookie" HTTP header for anonymous page
 * views. This tells a HTTP proxy that it may return a page from its local
 * cache without contacting the web server, if the user sends the same Cookie
 * header as the user who originally requested the cached page. Without "Vary:
 * Cookie", authenticated users would also be served the anonymous page from
 * the cache. If the site has mostly anonymous users except a few known
 * editors/administrators, the Vary header can be omitted. This allows for
 * better caching in HTTP proxies (including reverse proxies), i.e. even if
 * clients send different cookies, they still get content served from the cache.
 * However, authenticated users should access the site directly (i.e. not use an
 * HTTP proxy, and bypass the reverse proxy if one is used) in order to avoid
 * getting cached pages from the proxy.
 */
# $conf['omit_vary_cookie'] = TRUE;

```

This DA question answers this issue too: What does the "Vary: Cookie" header actually do for serving pages from Varnish?

---
Tags: caching, proxies
---


title: geofield proximity in views

text:
# Question
Title: geofield proximity in views
Ive been trying to setup a view where the distance to users is stated.

There has recently been an update of geofield however I am having trouble with calculating the distances to users (only get a zero)

I have checked whether the users have points, which they do, and tried to create a relationship to the user id without results.

I am a newbee in views so every advice would be beneficial

# Answer
MotoTribe's answer is basically correct, but you might want to use the dev release instead of the alpha release. We've had a few bug fixes in since then. We should probably do a new release soon.

Source: Geofield maintainer.
> 4 votes

# Answer
See new documentation page for geofield that shows how to setup a basic proximity search (it is based on MotoTribe's answer, but with a bit more info)

As requested, some of the link content:

## Instructions

**Required modules**

You must download the latest modules. These instructions have been tested with the 'dev' versions of geocoder, geofield, and addressfield modules. I believe these modules have a dependency on geophp, maybe others, install any dependent modules that you are instructed to when installing. Make sure to download the 'dev' versions!

**Steps**

*Setup your content type:*

1. Create a content type for whatever you want to locate (e.g. Dealers, Stores, etc)
2. In manage fields: Add an addressfield field to the content type (use options as you see fit).
3. In manage fields: Add a geofield field to the content type. When adding, make sure to select 'Geocode from another field' from the 'widget' dropdown! The geofield option are pretty straightforward, just make sure to select the addressfield field you created earlier for the 'Geocode from field' option.
4. Now, create a few records with addresses using your new content type.

That was easy! Now, let's setup the view result...

*Setup your views query:*

1. Create a view, can be any kind. Select the content type you created earlier for the results.
2. Add a field: '\[name of your geofield\] - proximity' (there are a number of geocoding related fields, you want the one with '- proximity' appended)
3. In the field settings: For the 'Source of Origin Point' field, select 'Exposed Geofield Proximity Filter'.
4. Add any other identifying fields, such as title, address, etc.
5. Add a new 'Filter Criteria' for your view for the '\[name of your geofield\] - proximity' field.
6. Choose 'Expose this filter to visitors, to allow them to change it'
7. For 'Operator', choose 'Is less than', because you want results that are closer than a certain distance from the value your users enters, e.g. less than 100 kilometers, etc.
8. For 'Source of Origin Point', choose 'Geocoded Location', which will allow the user enter friendly values such as city, state, zip/postecode, state, etc. (basically, anything you can put into Google location searches).
9. For Geocoding Service, choose 'Google Geocoder'.
10. Add a Sort Criteria: '\[name of your geofield\] - proximity'. Also, remove any other sort filter already existing, since sorting by date first will foil your proximity filter!
11. Set to sort ascending, since you probably want to show the closest results first.
12. Set 'Source of Origin Point' to 'Exposed Geofield Proximity Filter'.
13. Test your new proximity search!
> 14 votes

# Answer
Looks pretty straightforward using geofield 7.x-2.0-alpha2:

I assume you have geofield and geophp enabled and assume you have added a geofield to your users that get the location from an addressfield.

1. create a view of type users
2. add "\[name of your geofield\] - proximity" field
3. select "source of origin", I tried "exposed geofield proximity filter", check the "round" box
4. add "\[name of your geofield\] - proximity" exposed filter and select a "source of origin point" as well. For example, add a "geocoded location" (fancy word for address)
5. add that same field to your sort options to sort by proximity as well.

In your example you would probably change the "source of origin point" to "current user".
> 8 votes

# Answer
Juts in case, i wrote a little plugin, it works on the alpha2 release.

I provide a simple proximity filter that use the Smart IP location information (so Smart IP is requiered). User just have to chek a box to search around him. Nice, isn't it ?

**Disclaimer :** I provide this code as is, i'm not responsible, etc. ;) And i post this **under the control of the Maintainers,** who can tell me that this is a sh\** if it is the case.

See this comment for complete instructions : http://drupal.org/node/1901750#comment-7191652

Best regards,
> 0 votes

# Answer
In addition to RogerRoger's post:

In case you're using this as a **Views attachment**, don't forget to check "*Inherit exposed filters*" in the attachment settings, or it will only display the distance from the default value, or "0" in case there's no given default value.
> 0 votes

---
Tags: views, location
---