# Question
Title: Added field to Basic Page Content Type is not displayed in the page
This question may be a bit silly but I have been struggling with it for a long time and still no solution:

I have added the Star Rating Module to display rating stars in my pages. I have enabled the module and configured the "Basic Page" Content type to have the "rating" field. The point is that I edit a page, assign a rating properly but... when I view the generated page the starts don't show up!

I have tried adding another field, this time a text field, but it doesn't appear on the page either.

Any idea why additional fields added to "Basic Page" aren't displayed in the page?

# Answer
> 1 votes
There is nothing special about putting fields on the Basic Page.

However, to be visible, you have to make sure that the field is not `<Hidden>`.

To check that, go to the *Manage Display* panel for the bundle (content type) you've got problems with.

---
Tags: 7, nodes, rating
---


# Question
Title: Send Email upon Registration to Author of node
I have searched and can not find anything similar.

I have a Rule, Event = send email after someone registers for an event. I have the rule sending to the user just fine. However, I am trying to also email the Author of the page and I can find the correct replacement pattern.

I have an action Fetch Entity by ID Value=registration - DATA-Selector=registration:author:uid

I have tried many patterns: `[node:author:mail] mail - Nothing happens
[registration:author:uid] uid - give me the logged in user id
[registration:author:uid] reg-a-uid (this give mne the id of the logged in user- not the author on the page.)
[node:author:uid] node-a-uid
[site:author:uid] site-a-uid
[registration:author] reg-author - show logged in user
[registration:author:mail] reg-author-mail - show logged in user`

I am at a loss when trying to figure out how to pull the author of the node/page to email them. Any ideas??? Thanks

\[EDIT\]

I was able to get the Author to print out.

```
author: [registration:entity:author]

```

Any ideas to pull the author first name, email and phone number???

Please any little thought would help. Thanks

# Answer
> 0 votes
So after getting the base set I needed to connect to the table for the users profile information.

So for first name it would be:

```
[registration:entity:author:profile-main:field_first_name]

```

So for phone number it would be:(field\_office is what they called the Office Phone field.)

```
[registration:entity:author:profile-main:field_office]

```

Hope it helps someone else.

---
Tags: rules
---


# Question
Title: Post becomes unpublished upon editing it and no additional date values or image uploads are possible
I have a custom content with a large number of multivalue date fields (around 200-300 values). I created a node and added a large number of dates. When subsequently editing the post, the following occurs:

1. The post is saved as unpublished
2. Changes to the body field and other text fields such as tags are saved
3. No additional dates can be saved
4. Clicking on Preview doesn't show a preview, but saves the post as unpublished
5. Upon attempting to upload an image file, the Drupal message "\[content-type\] \[post-title\] has been updated" (with the specific values in place of the \[...\] placeholders) appears, but it appears BEFORE clicking Save; upon saving the post, no file is saved
6. "The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved." appears when clicking Save after the file upload
7. The node can be made Published from the content administration screen (but not from editing it individually)
8. The Revision tab is missing even though the content type has revisions enabled by default
9. The Authored on date is reset to the first time the node become unpublished

I would like to have some instructions as to how to debug this situation.

PS: The site is hosted on Hostgator.com.

# Answer
> 4 votes
I was having a similar problem when editing a node with a field that allowed for unlimited field collection values. Each field collection had 8 input fields, and after adding in over 100 field collection items it stopped adding in more and it would unpublish on Save.

I could publish it from the content administration screen.

I modified max\_input\_vars in the server php.ini file from max\_input\_vars=1000 to max\_input\_vars=2500 and that allowed for the addition of more field collection items and to keep the node published when saved.

---
Tags: nodes, debugging
---


# Question
Title: How to replace the Bartik default menu with Superfish
Since the default Bartik menu doesn't allow me to create a sub menu with styles, I created a Superfish menu.
How can I replace the Bartik default menu with Superfish on the exact place?

# Answer
> 2 votes
I found a report, How to apply Bartik main-menu styles to other menu modules similar to Superfish. Essentially, the trick is not to apply the CSS styles used by Superfish to the CSS styles used by the theme, but to include the CSS styles used by the theme in the CSS styles used by Superfish.

The steps reported in that post are the following (I am editing them to change the format).

* Create a new style sheet (NewStyleSheet.css) and save it to your file directory.
* Edit the block settings for Superfish in /admin/structure/block. This step list assumes you are using a template that includes a "Menu Bar" or similar block area.
    + Move the block "Superfish X" to the "Menu Bar" region, by changing the drop down selector value to "Menu Bar."
    + Click "Configure" under "Operations," on the far right of the setting page.
    + Under "Superfish Settings," change "Menu Type" to "NavBar."
    + Optionally, select "NO" on both "Drop shadows" and "Auto-arrows", as this would take more time to modify the CSS to get them to show up properly.
    + In "Advanced Settings," add your new stylesheet location to "Extra CSS."

This is the content of the new CSS file.

```
/* $Id: whiteTab.css,v 1.0 2011/02/18 05:45:00 erok415 Exp $ */

/*-------------------------------------------------------------*/
/*                                                             */
/*      Important - Be sure to change all references           */
/*      from #superfish-3 below to match the number of the     */
/*      Superfish "X" block region you are using in your       */
/*      Block Settings. I used block region Superfish 3,       */
/*      hence I am using #superfish-3 below.                   */
/*                                                             */
/*-------------------------------------------------------------*/

/*-------------------------------------------------------------*/
/*                                                             */
/*   I have not attempted to use style the 4th level flyout,   */
/*      Auto-arros or the drop shadow features.                   */
/*                                                             */
/*-------------------------------------------------------------*/

#menu-bar{
  margin-bottom:10px;/* Add padding so secondary navigation doesn't run over search sidebar. */
}

sfHover, ul#superfish-3 > li:hover{
  background: none repeat scroll 0% 0% transparent; /* Remove the default background on top level tabs in default state and hover state. */
}

ul#superfish-3 li.sfHover li  a:hover, ul#superfish-3  li.sfHover  li a.active{ /*Secondary Nav: add effect to hover or active state here. */
  color:#09F;
  width:100%;
}

ul#superfish-3 > li > a{ /* Fist level horizontal navigation. */
  margin:4px 2px 0 0; /* Spacing around tabs. */
  color: #333;
  background: #fff;
  background: rgba(255, 255, 255, 1.0);
  float: left; /* LTR */
  padding:0px 6px 6px 6px;
  /* height: 1.8em;
  line-height: 2.4em;
  padding: 0 0.8em; */
  text-decoration: none;
  /* text-shadow: 0 0.5px #999; */
  font-weight:bold;
  -khtml-border-radius-topleft: 8px;
  -khtml-border-radius-topright: 8px;
  -moz-border-radius-topleft: 8px;
  -moz-border-radius-topright: 8px;
  -webkit-border-top-left-radius: 8px;
  -webkit-border-top-right-radius: 8px;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}

ul#superfish-3 > li.sfHover {
  background: none repeat scroll 0% 0% transparent; /* Remove the default background from the sfHover state. */
}

ul#superfish-3 > li.sfHover > a { /* First level hover and active state. */
  margin:4px 2px 0 0; /* Spacing around tabs. */
  color: #333;
  background: #999;
  background: rgba(153, 153, 153, 1.0);
float: left; /* LTR */
  padding:0px 6px 6px 6px;
  /* height: 1.8em;
  line-height: 2.4em;
  padding: 0 0.8em; */
  text-decoration: none;
  /* text-shadow: 0 0.5px #999; */
  font-weight:bold;
  -khtml-border-radius-topleft: 8px;
  -khtml-border-radius-topright: 8px;
  -moz-border-radius-topleft: 8px;
  -moz-border-radius-topright: 8px;
  -webkit-border-top-left-radius: 8px;
  -webkit-border-top-right-radius: 8px;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}

/*------------------- Secondary Nav -------------------*/
.sf-navbar > li > ul{ /* Add background color to secondary nab only. */
  background:none repeat scroll 0% 0% rgb(51, 51, 51);
  background: #333;
}

ul#superfish-3 > li > ul{
  left:-15px; /* Align the menu with the left edge of design. */
  border-right:30px solid #333;/* Add the background color to the right edge because the style attribute above leaves a blank spot due to global conditions. */
}

ul#superfish-3 > li > ul > li {
  left:15px;/*Fix: aligns secondary level nav text with top level nav*/
  border:0;
}

ul#superfish-3 > li.sfHover > ul > li > a{ /* Secondary Nav: Remove tab effect from sfHover state applied to lower level nav. */
  color:#fff;
  background: #333;
  -khtml-border-radius: 0px;
  -moz-border-radius: 0px;
  -webkit-border-top: 0px;
  border-radius: 0px;
  width:100%;
  height:2.0em;
  line-height:1.1em;
  padding:6px 0 0 6px;
  margin:0 16px 0 0;
}

ul#superfish-3 > li > ul > li > a{ /* Secondary horizontal navigation. */
  color:#fff;
  font-weight:bold;
  /* text-shadow: 0 0.5px #CCC; */
  background: none repeat scroll 0% 0% transparent;
  -khtml-border-radius:0;
  -moz-border-radius:0;
  -webkit-border-radius:0;
  padding:0;
}

/*--------------- Third level DropDown navigation ------------*/
ul#superfish-3 > li > ul > li > ul {
  -khtml-border-radius: 0px;
  -moz-border-radius: 0px;
  -webkit-border-top: 0px;
  border-radius: 0px;
  margin:0;
  padding:0 0 0 6px;
  border:0;
  left:-0px;
  background: none repeat scroll 0% 0% transparent;
}

ul#superfish-3 > li > ul > li > ul > li  {
  margin:0px;
  border-right:0;
  left:0;
  border:0;
  padding:6px 6px 0px 6px;
  background:#333;
}

ul#superfish-3 > li > ul > li > ul > li:hover{
}

ul#superfish-3 > li > ul > li > ul > li > a {
  background:#333;
  margin:0;
  padding:0 6px 0px 6px;
  line-height:1.3em;
  background:#333;
}

ul#superfish-3 > li > ul > li > ul > li > a:hover {
  background: none repeat scroll 0% 0% transparent !important;
}

```

# Answer
> 0 votes
Thanks for these instructions but I think I've found a better way to approximate the Bartik look:

Do almost the same as above but for the **Menu Type**, choose 'Horizontal' instead and then use my code below to make the style of the actual the CSS resemble Bartik's menus.

Here is my SASS code which I called 'superfish-bartik.scss'. Just make sure to point Superfish towards that custom file in **Path to CSS file(s)** as directed above.

```
.block-superfish {
  position: absolute; /* position at bottom of header region */
  left: 0;
  bottom:0;
  ul.sf-menu {
    background-color: transparent;
    li {
        /* Fallback for web browsers that doesn't support RGBa */
        background: rgb(255, 255, 255);
        /* RGBa with 0.6 opacity */
        background: rgba(255, 255, 255, 0.6);
        /* For IE 5.5 - 7*/
        filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#7FFFFFFF, endColorstr=#7FFFFFFF);
        /* For IE 8*/
        -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#7FFFFFFF, endColorstr=#7FFFFFFF)";
        margin: 0 2px;
        border-radius: 8px 8px 0 0;
        &:hover {
            background: rgba(255, 255, 255, 0.9);
        }
        a {
            color: #000;
            font: 13px/13px "Helvetica Neue",Helvetica,Arial,sans-serif;
            padding: 10px;
            text-decoration: none;
        }
        ul {
            margin-top: 3px;
            li {
                border-radius: 0;
            }
        }
    }
}

```

And here is the CSS if you don't use SASS:

```
  .block-superfish {
      position: absolute; /* position at bottom of header region */
      left: 0;
      bottom:0;
    }
  .block-superfish ul.sf-menu {
    background-color: transparent; }
    .block-superfish ul.sf-menu li {
      /* Fallback for web browsers that doesn't support RGBa */
      background: white;
      /* RGBa with 0.6 opacity */
      background: rgba(255, 255, 255, 0.6);
      /* For IE 5.5 - 7*/
      filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#7FFFFFFF, endColorstr=#7FFFFFFF);
      /* For IE 8*/
      -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#7FFFFFFF, endColorstr=#7FFFFFFF)";
      margin: 0 2px;
      border-radius: 8px 8px 0 0; }
      .block-superfish ul.sf-menu li:hover {
        background: rgba(255, 255, 255, 0.9); }
      .block-superfish ul.sf-menu li a {
        color: #000;
        font: 13px/13px "Helvetica Neue",Helvetica,Arial,sans-serif;
        padding: 10px;
        text-decoration: none; }
      .block-superfish ul.sf-menu li ul {
        margin-top: 3px; }
        .block-superfish ul.sf-menu li ul li {
          border-radius: 0; }

```

---
Tags: 7, routes
---


# Question
Title: Drupal 7 Bartik plus theme drop down menu
This is actually, must be easy question, ive been fiddling around for some hours trying to figure it out.

The short version is I am making a drop down menu in Bartik,

I am aware of superfish,nicemenues,megamenues, But I am not interested in these. Since Bartik runs with superfish built in.

I came across this Drupal 7 Bartik Plus Theme with a fresh install of Drupal

But this menu isnt working. The default menu is not showing.

as you can see here this is how it supose to work

Drupal 7 Bartik Plus example

Any good ideas to how I get it to work?.

# Answer
The answer I found was here Changing Bartik theme to dropdown

and I used this CSS file with fixed issue

CSS file to put into superfish folder
> 0 votes

# Answer
I've just updated that thread with simpler code, resulting in menus that actually look just like Bartik's. Please vote my answer up if it works for you. Thanks.
> 0 votes

---
Tags: theming, navigation
---


# Question
Title: Adding Google Map via iframe with CKeditor in an article
I want to add to the body of a Drupal node (in my case the default article), the google iframe to embed one map

```
<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m12!1m3! ... </iframe>

```

I use Drupal 7.26, CKEditor as Wisywig editor with the "Standard Package", and everything is working fine.

What I tried after reading many articles:

* I set the node to Full Html (of course)
* I unchecked "Limit allowed HTML tags" in /admin/config/content/formats/full\_html
* I put "Use custom formatting options" to yes in the "Cleanup and Output" section of admin/config/content/ckeditor/edit/Full
* ... few combination of the above.

What it happens: I edit the article, I insert the html source in the body. I untoggle the source button, everything is disappeared (I go back to source and nothing left).

Note: I don't want to use OpenLayers, I don't want to install modules such Iframe, or SimpleMap, because I just need this map once. It should be working, but my html is still filtered for some reason.

# Answer
> 1 votes
As results from the discussion in http://dev.ckeditor.com/ticket/11688 it turned out that **CKeditor Standard Package** don't allow on principle to paste iframes and other html objects, while **Full Package** allows it. This confused me since I don't expect this difference among packages that should differ only in terms of features provided.

This can be tested at the demo page of CKEditor, while in the Full Package tab you can paste iframe (as expected) in the Standard Package Demo you can't. I used a Google Maps Iframe for the test.

Hence, this problem can be solved

* As answered by @user27417, updating the module to the dev version and configuring the ACF
* By installing the **Full Package** client of CKEditor.

The CKeditor team was very supporting. Thank you.

# Answer
> 1 votes
Please see dev.ckeditor.com/ticket/11688 for more details.

> If you are using latest CKEditor for Drupal module then please go to Modules-\>CKEditor-\>Configure and edit your profiles. Each of them has ADVANCED CONTENT FILTER setting which can be disabled/enabled or extended.

**NOTE:** durring checking it has turned out that relase version for drupal OS module hasn't been updated thus you can't see this setting. **For now please use development release which has this feature and is fully stable**.

# Answer
> 0 votes
Create a Text Format OR modify text format with these setting(see image) and using that text format use iframe of google map.

---
Tags: wysiwyg, google-maps
---


# Question
Title: Drupal Media Library - File Upload Library shows “No files available.”
I am actualy running in some sort of strange problem. I installed Media 7.x-2.x-alpha2. I can upload files without any problems. When I go to "admin/content/file" I see the uploaded files.

Now comes the problem, when I want to add a image via the library dialog, while creating a new node, the box shows me "No files available.".

I checked the media browser view and the very strange is, that the files shows up in there

I tried updating to newest dev release and checked the permissions, but anything looks just fine. I am working as user 1.

Any idea about that?

# Answer
> 2 votes
Answer from basti:

> The problem could be solved by removing the Query Tag under "Query settings" inside the view options. I have no idea why, but after removing it, anything works just fine.

---
Tags: views, media
---


# Question
Title: How to show different entity in Views with different displays?
I create a views with 2 displays.

One display show **content type.**

One display show **taxonomy** list that related above content type.

When I try to create a display with content type, then I can not create a display with taxonomy.

Content type and taxonomy are different entity, So How to show different entity in Views with displays?

# Answer
You have to add relationships **Content: Taxonomy terms on node** then you will get options to add **taxonomy** in **filter criteria** and **fields**
> 3 votes

---
Tags: views
---


# Question
Title: Calling menu in a certain way from page.tpl.php
My menu structure looks like the structure in the left part of the image. I want the output to look like the right part of the image when I'm in the 'oranges' page for example. This works great if done from Drupal's admin panel, but is there any way I can code it in my page.tpl.php?

Currently, I'm using the code below to output my menu, but I can't seem to get it to look exactly the way I want.

```
<?php
  $main_menu = menu_navigation_links('main-menu', 2);
  print theme('links', array(
  'links' => $main_menu,
  'attributes' => array(
  'id' => 'main-menu',
  'class' => array('links', 'clearfix'),

),

  'heading' => array(
  'text' => t('Main menu'),
  'level' => 'h2',
  'class' => array('element-invisible'),
),
));
?>

```

Any ideas?

# Answer
You can use **menu\_tree\_all\_data** function to get all nested menus. And then you can add your own html to display menus with your style

```
$menutree_produce = menu_tree_all_data('menu-produce');

```

And if you want to Active current menu on related page you can use menu\_get\_item and menu\_set\_item on that page

```
$menu_item = menu_get_item(drupal_get_normal_path('produce/oranges'));
menu_set_item(NULL, $menu_item);

```
> 0 votes

---
Tags: routes, theming
---


# Question
Title: Module for Importing and exporting Vcards
Is there drupal module to support importing vcard details to the site and publish the details of the content?

Thank you

# Answer
> 1 votes
You can check the vCard module. It can be useful for you.

Here is a quote about it (from the module's project page):

> ... adds a vCard download link to every users profile. This link makes it easy to add users on your Drupal site to your local address book. Since we love microformats, there is also a theme function (theme\_vcard) for displaying user data in the hCard format.

---
Tags: 7, commerce
---


title: Add CSS class to body for admin-end

text:
# Question
Title: Add CSS class to body for admin-end
There are classes in the body like .front and .no-front that are good for styling front page separately and etc.

I am using same theme for front end and back end and would be nice if there was some .admin-end class in the body each time when editing content or just being in admin zone when logged in.

# Answer
Depending on your theme, you should be able to do something like this:

```
function YOURTHEME_preprocess_html(&$variables) {
  global $user;

  if ($user->uid) {

    if (arg(0)=='admin') {
      $variables['classes_array'][] = 'admin-page';
    }
    if (arg(0)=='node' && arg(2)=='edit') {
      $variables['classes_array'][] = 'node-edit-page';
    }

  }

}

```
> 2 votes

# Answer
Jimajamma answer is correct and works. I configured it a bit.

```
function YOURTHEME_preprocess_html(&$vars) {
  global $user;
  if ($user->roles) {
    foreach ($user->roles as $key => $value) {
      if ($value =='administrator') {
        //print "<h1>Logged in as admin</h1>";
        $vars['classes_array'][] = 'admin-page';
      }
    }
  }
}

```

This way all users with administrator authentication get same class added to body.
> 1 votes

# Answer
Drupal core actually already provides classes that should be enough.

In template\_preprocess\_html() it calls theme\_get\_suggestions() and adds a bunch of css classes based on the path.

So for any path you are on that starts with admin there will be a class page-admin.

For example the path admin/content would have the classes: page-admin page-admin-content

and admin/structure/views would have page-admin page-admin-structure page-admin-structure-views

and so on.

It is best not to add more classes if you can get away with using ones that are already there.

And for the node add pages you can use the page-node-add class and for the node edit pages you can use the class page-node--edit.

That last one is a little confusing but it is because the path is node/%/edit and so the class is page-node-%-edit but then % is stripped out because it is invalid for a class.
> 0 votes

---
Tags: 7, theming
---


# Question
Title: Is it okay to edit the webform content type?
I want all the *static* pages on my website to have an image at the top of them. So instead of using Drupal's Basic Page type, I created my own type (Simple Page) that has:

* Title
* Body
* Image

I have enabled Webform module on my site and created a simple Contact Us form.

The problem I have is that the Contact Us page (a Webform) does not have an image at the top, like all my other pages. To fix this, I edited the webform content type and added an Image field, and now my Contact Us page follows the styling of the other pages.

But it feels wrong, editing the Webform type directly. (Its as if I have hacked core!) And now I am worried that I'll have problems when I upgrade the Webform module.

Is there a better way that I could have done this?

# Answer
> 2 votes
I don't think you've necessarily done anything wrong by adding fields to the Webform content type, but if you're interested in strictly keeping your code separate from core code, you can create a new content type, and enable Webforms to be used on this content type under "Webform-enabled content types" on /admin/config/content/webform.

Then you'll be able to add your own image field to your own content type without problems. This will then leave you free to export the content type configuration to code with the features module, without really interfering with the Webform content type provided by the Webform module.

# Answer
> 1 votes
It is perfectly ok to do that.

The content type is provided by the webform module but changing it's configuration is not like hacking the code of a module.

When you do module updates for the webform module you won't lose any changes you have made to that content type.

---
Tags: nodes, webforms
---


# Question
Title: Is it possible to use Views for listing data created in a custom module?
The title says it all.

I'd like to create a view and provide rows for that view from a custom module where I've prepared the data for it.

The data is prepared when a page is visited and a callback function has run, the data is not stored in the database.

Is that possible somehow?

Thank you!

# Answer
I know link-only answers are generally frowned upon, but this series of blog posts are unlikely to ever go anywhere and are WELL worth a read:

Building Views Query Plugins: Part 1 \- *Mapping web service data to the Views model*

Building Views Query Plugins: Part 2 \- *Writing and testing the plugin itself*

Building Views Query Plugins: Part 3 \- *Exposing options and configuration*

Building Views Query Plugins: Part 4 \- *Building custom pager plugins*

*Note: In the unlikely event that someone gets here and the links are dead, please comment and let me know so I can address it :-)*
> 2 votes

---
Tags: 7, views
---


# Question
Title: How to use hook_views_query_alter to add field with no table in Drupal 7 Views 3
I am new to Drupal 7/Views 3 hooks. I am trying to approximate this query:

```
SELECT *, 3956 * 2 * ASIN(SQRT(POWER(SIN(($postcode_lat - abs(lat))*pi()/180/2),2) + COS($postcode_lat * pi()/180) * COS(abs(lat) * pi()/180) * POWER(SIN(($postcode_lng - lng) * pi()/180/2),2))) AS distance
WHERE distance < 500
ORDER BY distance ASC

```

This gives a list of locations sorted by distance. However, in trying to implement with hooks, I am struggling. Here is the code that I tried:

```
$query->addField('', '3956 * 2 * ASIN(SQRT(POWER(SIN((32.7828 - abs(29.7631))*pi()/180/2),2) + COS(32.7828 * pi()/180) * COS(abs(29.7631) * pi()/180) * POWER(SIN((96.8039 - 95.2665) * pi()/180/2),2)))', 'distance');

```

Drupal doesn't like the empty parameter for table. But how can I add a field with no table?

I appreciate any suggestions offered.

# Answer
> 3 votes
I had the same problem. And I've solved it.

```
    function ModuleName_views_query_alter(&$view, &$query) {
  if ($view->name == 'my_view' && 'my_block_name' == $view->current_display)) {

    $formula = "3956 * 2 * ASIN(SQRT(POWER(SIN(($postcode_lat - abs(lat))*pi()/180/2),2) + COS($postcode_lat * pi()/180) * COS(abs(lat) * pi()/180) * POWER(SIN(($postcode_lng - lng) * pi()/180/2),2)))";

    // Sets the formula's alias.
    $query->add_field(NULL, $formula, 'distance');
    $query->add_where(0, "$formula < 500", array(), 'formula');

    // Sets the order by reference
    $query->orderby = array(
      array(
        'field' => 'distance',
        'direction' => 'ASC',
      )
    );
  }
}

```

See http://roldanarts.com/2013/11/22/diego-f-roldan/blog/using-formulas-views-hook-views-query-alter for more details.

# Answer
> 1 votes
You can use the `SelectQuery::addExpression()` method (instead of `addField()`) to add complex expressions to the query. e.g.

```
$formula = '3956 * 2 * ASIN(SQRT(POWER(SIN((32.7828 - abs(29.7631))*pi()/180/2),2) + COS(32.7828 * pi()/180) * COS(abs(29.7631) * pi()/180) * POWER(SIN((96.8039 - 95.2665) * pi()/180/2),2)))';
$query->addExpression($formula, 'distance');
$query->condition('distance', 500, '<')->orderBy('distance');

```

# Answer
> 0 votes
You can't add fields using `hook_views_query_alter()`.

You need to use `hook_views_data()` or `hook_views_pre_render()`.

See this answer for show fields after adding joins in hook\_views\_query\_alter for more info.

---
Tags: views
---


title: Enabling JavaScript from CKEditor

text:
# Question
Title: Enabling JavaScript from CKEditor
I would like to enable javascript to be added inside CKEditor. The editor filters all my javascript and I would like to make a transtision from an image to a youtube iframe, here is the code that I am using:

```
<div id=“hideThisVideo” style=“display:none;”><iframe frameborder=“0” height=“360px” src=“//www.youtube.com/embed/W10F0ezCTIQ?autoplay=1” width=“640”></iframe></div><img style=“width:640px;height390px;cursor:pointer;”src=“/sites/all/themes/gloriajesus/video.png” onclick=“this.style.display=‘none’;document.getElementById(‘hideThisVideo’).style.display=‘block’;”/>

```

But when I click nothing happens, it filters the "onclick" event and adds a paragraph tag:

```
<div id=“hideThisVideo” style=“display:none;”><iframe frameborder=“0” height=“360px” src=“//www.youtube.com/embed/W10F0ezCTIQ?autoplay=1” width=“640”></iframe></div> <p><img src=“/sites/all/themes/gloriajesus video.png” style=“cursor:pointer; height:390px; width:640px”></p>

```

I am using CKEditor with the module Wysiwyg.

Thanks in advance.

# Answer
> 0 votes
Hope this will help you, For achieving your goal you need to create a plugin of ckeditor, First of all read more about ckeditor plugin, and create a view to get all the video with the display in a page, you can use the views page url for the ckeditor plugin to insert the media on ckeditor, a good tutorial is here.Click Here

this is one of the module which will help you click here & click here

# Answer
> 0 votes
A partial fix it can be done editing the plugins.js file that is inside /sites/all/libraries/ckeditor that was created when we added CKEeditor with Wysiwyg. Then adding inside the {} of the script that we see there:

config.allowedContent = true;

With this we allow all type of content and we desactivate the Advanced Content Filter (ACF) of CKEditor, but besides that we must use the Full HTML of Drupal, not the filtered.

Adding the code to the CKEditor field we can not edit it again without losing all the javascript loaded in the first time that we saved the content, we will lose it, but we can add it again.

Thats all, thanks to madhurjya for helping!

---
Tags: theming, javascript, wysiwyg
---


# Question
Title: Is there a Drupal module to add a Creative Commons license to entities?
I am looking for a module (beyond the Media Gallery module) that allows content creators to licence the content they create by means of the Drupal WCMS under one of the Creative Commons licenses. Is there a module for this?

# Answer
> 3 votes
Yes, in addition the the Creative Commons licensing support that is integrated in the Media Gallery module, there exists a module for that does exactly that: the Creative Commons licenses module. From the project page:

> The Creative Commons module allows users to select and assign a Creative Commons license to a node and any attached content, or to the entire site. It also provides integration between CC and Drupal technology.

It was originally written for D6 and is still under development for D7 (up to alpha2 at the time of writing), but the core functionality is in place.

Somebody may ask:

> "Why would you need a module for that? Why can't you just add an Entity Reference field to link to whatever license the user chooses? What tasks should this module accomplish that a simple dropdown (or dropdown with link) cannot?"

The answer is that there is a lot more to Creative Commons licensing than just linking content to the CC license.

I think that reading the road map for the D7 port will shed some light on what is desirable, and why you need a module to accomplish it. To summarize: When licensing content under Creative Commons it is highly desireable that RDFa and ccREL metadata is properly presented, and you need more than a link for that. A CC search option should also be is available.

Looking at the issue queue for the Creative Commons module, it looks like development may have stalled when it comes to porting the more advanced features of the D6 version to D7, but I think it still is worth checking out.

There is also an experimental module named **Attributions**. It is not only for Creative Commons. It lets module and themes authors who use third party materials (e.g. fonts, photos and icons) that requires attribution register an attribution string in the project's `.info`-file. All the registered attribution strings from various projects can then be shown together on an attribution page or block. Disclosure: I am one of the co-maintaners of **Attributions**.

---
Tags: 7, nodes, entities
---


# Question
Title: Show exposed pager as links instead of select box
How to show exposed pager as links instead of select box in drupal 7 views ?

# Answer
Hope this will help, Use Better Exposed Filters go to settings of better exposed filter
> 1 votes

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


title: how to stop repeated content in view

text:
# Question
Title: how to stop repeated content in view
I am showing content from product content type of commerce module using view but view is showing some repeated content.how to solve this problem.

# Answer
> 2 votes
Did you check How do I remove duplicates when using the random sort? before?

If it does not help you check views\_distinct module

> Relationships or other joins in Views often create "duplicate" results. For example, a node with a field that has multiple values may show up in the View once per value in the multi-value field. It's frustrating, and the "DISTINCT" SQL query option in the Views UI does not actually solve the problem because the result row is technically distinct. This module aims to give a simple GUI method to remove or aggregate these "duplicate" rows.

---
Tags: views, commerce
---


# Question
Title: Creating multiple image crops with each instance of an image upload
Can anyone tell me if there is a way to define multiple image sizes and create those images sizes each time an original image is uploaded?

I've been using imagecache but unless I'm wrong, it doesn't help when you want to create multiple images of various sizes when an original is uploaded.

Can anyone help?

# Answer
You are using imagecache. Here you can create different type of image styles. And you can use below code for display multiple images of various sizes of an original uploaded image.

```
 $style = 'thumbnail_200_by_200';
 $image_uri = 'public://image_name.jpg';
 $img_url = image_style_url($style, $image_uri);

 <img src="<?php echo $img_url;?>"/>

```
> 0 votes

# Answer
For drupal 7: Create the image styles in Admin \> Configuraion \> Media \> image styles. Next, in the display settings for your content type, select which image fields to display, and which image style to display them in, for that display.

For drupal 6, the procedure is practically identical, except that you'll need the imagecache module to be installed and enabled. Instead of going to media \> image styles, you'll have to create "imagecache presets" in the imagecache module settings.
> 0 votes

---
Tags: files, media
---


title: Required Checkbox Field Has No Effect

text:
# Question
Title: Required Checkbox Field Has No Effect
I used `hook_form_alter` to add a required 'confirmation' checkbox to the node deletion form and the #required status is not honored.

The fields/fieldset are property displayed 'node-delete-confirmation' form.

Here is the hook\_form\_alter content:

```
$form['warning'] = array(
    '#type' => 'fieldset',
    '#title' => t('Warning! - You Must Check The Box Below To Continue'),
    '#weight' => -30,
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
);
$form['confirm_delete'] = array(
    '#title' => t('I fully understand that this action cannot be undone and that statistics linked to this item will be permanently removed.'),
    '#type' => 'checkbox',
    '#required' => TRUE,
    '#default_value' => 0,
);

```

How can I enforce the 'required' status so that nodes cannot be deleted until the confirmation is acknowledged.

If I change the code, to completely remove the added fieldset everything works as it should.

Works:

```
$form['warning']['confirm_delete'] = array(
'#title' => t('I fully understand that this action cannot be undone and that statistics linked to this item will be permanently removed.'),
'#type' => 'checkbox',
'#required' => TRUE,
'#default_value' => 0,

```

);

# Answer
You can add your form validation handler (hook\_form\_alter):

```
$form['#validate'] = array('delete_validation_handler') + $form['#validate'];

```

Your validation handler:

```
function delete_validation_handler($form, $form_state){
    if(!$form_state['values']['confirm_delete'])
        form_set_error('confirm_delete', t('Message about to confirm it first'))
}

```
> 3 votes

# Answer
Try this one: http://drupaldeveloper.in/codelet/drupal-make-single-checkbox-required-field It will always work! Please note, its for Drupal 6.x, but you can use it for 7.x as well!
> 2 votes

---
Tags: 7, forms
---


# Question
Title: How do I remove a DIV from the rendered result of a BEF exposed form?
I'm using Bootstrap as my theme and Better Exposed Filters to generate check boxes for term filters that are exposed to my visitors/users. Unfortunately, Bootstrap adds a "form-group" class to all elements of a form that aren't radio buttons and/or check boxes. BEF (or something) adds a DIV around each of the check boxes and thus Bootstrap adds the form-group class and that messes with the formatting of the check boxes.

So it looks like:

```
    <div class="form-type-bef-checkbox form-item-edit-field-list-crit-tags-tid-591 form-item form-group">
 <input type="checkbox" name="field_list_crit_tags_tid[]" id="edit-field-list-crit-tags-tid-591" value="591"  multiple="multiple" class="form-control" /> <label class='option' for='edit-field-list-crit-tags-tid-591'>WAAC</label>
</div>

```

I need to remove either the DIV entirely or figure out a way to NOT put the form-group class on that particular div.

# Answer
> 2 votes
why not just write CSS that targets this item and removes any css applied by the default bootstrap `.form-group` ?

For example the rule could look like:

```
div.from-type-bef-checkbox.form-group {
  /* then "undo" whatever .form-group is doing -- you can see whatever it's
     doing by using Firebug or Google Chrome and inspecting the Element
     on the page.

     for example:
  */
  margin: 0 0 0 0;
}

```

By fixing just the CSS and not removing the css class or the div entirely you dont break or worry about upgrading these modules (of course you'll still have to check this CSS fix works in newer versions of the theme).

You can do this in your theme by adding or using a default custom stylesheet provided by your theme.

---
Tags: 7, theming
---


# Question
Title: How do I add a text field that links to the taxonomy_index table
When I add a taxonomy tag to a node, I also want to be able to add 1 (or more) text fields specific to that tag and that node. I know how I would set up the underlying db table (compound foreign key of nid and tid with a many-one join to the taxonomy\_index table, a primary key and a text field).

How would I implement this? Or does a module already exists that has this functionality?

I am fairly new to the world of Drupal so unsure if this would require writing a module, adding a new content type or another approach entirely.

Many Thanks, Pete

# Answer
Use the field collection module.

Create a new field collection field attached to your content type, and then in your field collection put 2 fields: 1 taxonomy term reference field, and 1 text field.
> 1 votes

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


# Question
Title: Cron failed with drush: Segmentation fault
In Drupal 6, whenever I run cron from web interface I get an Internal server error and when I run

```
drush cron

```

I just get

```
Segmentation fault

```

What can be wrong here and how can I fix it?

# Answer
> 4 votes
It sounds like a resource problem. Memory limits tend to be the culprit.

Check to see that drush is using the same php.ini file your site is.

```
drush status

```

Tells you what php you are using for drush.

Running the following will give you memory output information when running cron

```
drush cron -d

```

if that memory stack is near what your php.ini limit is.. raise it up an integer of 32Mb. (i.e. 128mb to 160mb) and then test again.

# Answer
> 0 votes
After starting cron from the web interface check your apache access and error logs for more information.

When starting cron with drush, make sure you have xdebug installed. It can record traces, memory usage and give you a stack trace in case php crashes.

# Answer
> 0 votes
According to Metaltoad, Views (among other modules that execute regexs with `preg_match()`) can create runaway regex's that eat up memory and cause segfaults because `preg_match()` can't prevent backtracking overflows.

---
Tags: 6, drush, cron
---


title: Adding a custom Sort field in Drupal

text:
# Question
Title: Adding a custom Sort field in Drupal
In our business we assign tasks to users based on the last digit of a company ID. When I created the view for these users, it was simple to create a "Formula" field and use RIGHT(field name, 1) to get this value.

I'd like to make an exposed filter that will allow users to only see companies ending in, say, 5 (for example).

Question: Is using the "Sort" function the best way to do this, or is there another way to add filtering to a table created by a view? It would be wonderful to add text search filters to each column, but I'm not sure if this is possible.

Question: How do I create a new field and make it available in the "add field" interface?

Thanks! Rich (who isn't the normal drupal developer and was left to learn on his own)

# Answer
Hi Rich who isn't the normal Drupal developer and was left to learn on his own. Welcome to Drupal.

I've encountered scenarios in which I had an exposed sort with a dropdown list and I needed to remove all the options that didn't fit my pattern. I used a `hook_form_alter()` that modified the `'#options` list for the element to `unset()` the items I didn't want to allow the user to select. However, this method doesn't prevent those items from showing when `-All-` is selected, so that may not work if that's an option for your users.

The way you'd add a new field is to create a custom field handler but it sounds like what you want might instead be a custom sort handler or a custom filter handler. The three are similar but not identical in their implementation.
> 0 votes

---
Tags: entities, views
---


# Question
Title: D7 form field #ajax callback not called on autocomplete field
I have an entity reference field, and I'd like to do some ajax so that when a value is selected for that field, some text is displayed in a div below the field. Since it's on a node edit form, I'm using a form alter hook:

```
/**
 * Implementation of hook_form_FORM_ID_alter()
 */
function mymodule_form_blog_node_form_alter(&$form, &$form_state, $form_id) {
  $form['field_video_reference']['#ajax'] = array(
    'callback' => 'mymodule_video_ajax_callback',
    'wrapper' => 'my-path-div',
  );

  $form['my_path'] = array(
    '#markup' => t('My path'),
    '#prefix' => '<div id="my-path-div">',
    '#suffix' => '</div>',
    '#weight' => 6,
  );

  if (!empty($form_state['node']->field_video_reference)) {
    $form['my_path']['#markup'] = 'Token path: http://www.mysite.org/node/' . $form_state['node']->field_video_reference['und'][0]['target_id'];
  }
}

function mymodule_video_ajax_callback($form, $form_state) {
  return $form['my_path'];
}

```

The code works fine when a the form is displayed and the field already has a value. However, the most likely use will be when the node is first being created, so I want this to trigger when a value is first added. The problem is, my callback is not being triggered at all. I'm following the first example in the "Javascript in Drupal" chapter in "Drupal 7 module Development," so from what I see, I it should be called when the field value is changed. Does this not work for fields that are already using ajax to get a value in the first place (i.e. an autocomplete field like this one), or is there something else I'm missing?

Thanks.

**UPDATE**: In case it is an issue with doing this on an autocomplete field, I added another test field that is a select list and attached the ajax to it as above, but the form is still not rebuilt when I select a value.

# Answer
> 5 votes
I think the problem is that `$form['field_video_reference']` is a container and you want to attach the ajax event to the actual text field element.

If you inspect the $form array you should see the correct place to put it. In needs to be at the same level as the `#type => 'textfield'` (or entity reference) property.

I think the path will be something like:

```
$form['field_video_reference'][LANGUAGE_NONE][0]['value']['#ajax'] = array(
    'callback' => 'mymodule_video_ajax_callback',
    'wrapper' => 'my-path-div',
);

```

---
Tags: ajax, forms
---


title: DB Error after upgrading

text:
# Question
Title: DB Error after upgrading
I upgraded a Drupal 6 site to Drupal 7. After upgrading, everything works fine. I had migrated all the content types and content. I am able to view all the content.

When I edit or add a content which contains an image field, I get the following error:

> PDOException: SQLSTATE\[42S22\]: Column not found: 1054 Unknown column 'field\_image\_alt' in 'field list': `INSERT INTO {field_data_field_image} (entity_type, entity_id, revision_id, bundle, delta, language, field_image_fid, field_image_alt, field_image_title, field_image_width, field_image_height)`

I came to know that field\_image\_alt is not found.

How can I manually add the field? I had run update.php specified in drupal documentation. But still i found that the field is missing. Anyone pls help me to add those fields.??

# Answer
> 1 votes
It looks like your image table field\_data\_field\_image is not having the field\_image\_alt column. Which is strange, since Drupal creates that by default.

Are you sure you ran update.php after migration? Do that first. If so, then try these steps.

I guess the best thing to do would be installing devel module and then with devel reinstall the image module. (Make backups as you might lose data!)

If that doesn't work you could add the column manually, and hope it was only this column that was off. See the following image for the fields you should have.

---
Tags: 7, media, upgrading
---


title: Image with title over top

text:
# Question
Title: Image with title over top
I am trying to create a view that has a image that is linked to another node, which I can do. However, I want to take the title (of content) and place it over top of the image like this.

I tried with CSS. Am I missing something?

# Answer
> 2 votes
This isn't really a Drupal question.

One of the usual methods is to use absolute positioning to remove the title from the document flow. Starting from HTML looking something like (e.g., rewriting with views):

```
<div class="my-frame">
  <img src="my-image.png">
  <div class="my-title">Image title</div>
</div>

```

Then use CSS rules something like:

```
.my-frame { position: relative; }
.my-title { position: absolute; top: 10; left: 10; }

```

---
Tags: views, nodes, media, theming
---


title: Views UI options do not work

text:
# Question
Title: Views UI options do not work
I am building a drupal 7 site.

Lately I made a lot of changes and install many modules.

Currently, when I enter into a view, everything looks fine. but, when I enter a field settings inside a view, I see that some of the option are not available - meaning the collapsible option is not available.

I tried to replace the views folder on my server with a folder I backed-up 4 days ago. ran cron, flushed all caches, ran upadte.php - nothing helped.

* Can someone please help me solve this issue?

Here is a screen-shot (you can see they are not clickable and not collapsible):

# Answer
> 0 votes
I found the problem.

The problem was an option on the advagg module that move all JS to the footer (which is usually a good thing).

The "All" option was problematic. when I chose "Disabled" - the views UI worked correctly.

here is a screen-shot:

# Answer
> 0 votes
From Eliminate render-blocking JavaScript and CSS in above-the-fold content Sometimes moving all JS to the footer can cause unintended side effects. Under advagg/mod under "Move JS to the footer" try "All but JavaScript Libraries". This will decrease your pagespeed score but a working site is better.

---
Tags: views
---


# Question
Title: Drupal cannot generate the derived image ANYMORE?
OK, My situation is really complicated (or Im stupid). I start my website http://rlsgame.org with Drupal System (even if Im .NET developer)... After 3 month, my website start grow up (about 2000 article and 3000 members) But a problem appear !!! I didnt touch anything, It appear just like that !!

When I want submit a Node, I have an issue with Images, I cant see the preview image :

**and After submiting the Node, here is the result:**

**I refresh the page and the nothing, But after i press CTR+F5, the article is fine:**

you can check the page here: http://rlsgame.org/PC/Games/ArmA-III All is fine...

But the big problem is that Drupal System cannot generate the derived image of User Picture !! Even if I press CTR+F5 like before, the problem is still here, look an exemple of a profile page:

Link: http://rlsgame.org/users/gamer

The old users profile is fine, because the picture is generated before the problem, exemple:

Link: http://rlsgame.org/users/mgs

And one more thing it start to appear too, Drupal start Caching comments (not like before this problem), when I post comment, sometimes it apear without Caching, and sometimes I must wait about 10 sec, for exemple, I post a comment and nothing appear, and I navigate to the homepage, and here we go, the msg appears:

I think if I fix the issue, All those problems will disappear ...

Im looking for fixing that 10 days ago, So Just for info:

* All files permission Are OK: sites/default =\> 555 sites/default/files =\> 755 (and all sub-folders too including styles)
* And paths of File system are OK
* Drupal is updated to 7.26 (latest version)

And the problem is not from the server (Im working on Shared Server) because I downloaded my website and run it in Local but I see the same problem plus My website work before so the problem is not from the server.

Ah, one thing, when i check Reports Log, I see a lot of warning, here is an exemple:

Thats all, plz help me to fix that, Im losing traffic....

Thanx for advance.

# Answer
In your settings.php file add this

```
$conf['image_allow_insecure_derivatives'] = TRUE;

```

In the future you should use image\_style\_url() when using image styles as this will then add in itok parameter for images. Usage: image\_style\_url doesn't create images

More info about this: https://drupal.org/drupal-7.21-release-notes
> 5 votes

---
Tags: 7, caching, media
---


# Question
Title: trending topics view based on read counts
I am trying to setup a view where it shows the most popular articles and couldn't find any answer to this. My readers will all be anonymous as it's my company's blog.

Looking forward an answer as this is pretty useful on blogs!

Cheers!

# Answer
If your site is relatively low traffic, you could possibly use the statistics module, or as @clive pointed out, the radioactivity module.

For higher traffic sites, I'd be wary of writing to the db for every visit, however. Moreover, if you're using varnish or some other reverse proxy caching system (which you probably should), Apache and PHP normally aren't invoked for anon visitors, so you'd need to do something different.

I've landed on using google analytics for this. To do it, the site obviously needs a google analytics account, and you need to install the google analytics and google analytics reports modules. Once you've configured them, you can fetch an array of the most visited nodes from the google analytics api. You can then simply serialise it, and save it to the variable table. This uses hook\_cron, and needs to be done in a custom module:

```
function YOUR_MODULE_cron() {
  $last_time = variable_get('YOUR_MODULE_last_time', 0);
  // DO EVERY 24H
  if ((REQUEST_TIME - $last_time) > (60 * 60 * 24)) {
    $data = array();
    $dates = array();
    $params = array(
      'metrics' => array('ga:uniquePageviews'),
      'dimensions' => array('ga:pagePath'),
      'segment' => 'gaid::-11',
      'filters' => 'ga:pagePath=@/PATH/TO/NODES',
      'sort_metric' => array('-ga:uniquePageviews'),
      'start_date' => strtotime('-7 days'),
      'end_date' => strtotime('-1 day'),
    );
    $feed = google_analytics_api_report_data($params);
    if (!$feed->error) {
      $k = 0;
      $nids = array();
      foreach ($feed->results as $f) {
        // SAVE 6 MOST VIEWED
        if ($k < 6) {
          $nids[] = (int) array_pop(explode('/', drupal_lookup_path('source', ltrim($f['pagePath'], '/'))));
          $k++;
        }
      }
      $nids = serialize($nids);
      variable_set('YOUR_MODULE_ga_items', $nids);
      variable_set('YOUR_MODULE_last_time', REQUEST_TIME);
    }
  }
}

```

Every 24 hours, this would save a serialised array of the most popular nodes that appear under the path http://yoursite.com/PATH/TO/NODES/REST\_OF\_PATH. To use the nids, you'd simply unserialise the variable after retrieving it:

```
$nids = unserialize(variable_get('YOUR_MODUE_ga_items', '');
foreach($nids as $nid) {
   $node = node_load($nid);
   ...
}

```
> 2 votes

---
Tags: views
---


title: Deployment for staging and production

text:
# Question
Title: Deployment for staging and production
I need to make the deployment easy between my staging and production servers.

How can I do this? I need to deploy all the changes, so if I pull from Github and run the script, the changes are applied!

Has anyone written any script or module for this?

I am using Drupal 7.

# Answer
You should look into drush, drush deploy and especially features. Not all Drupal configuration options are supported by features, and you will need to do some work to create a deployment process that works for you. There is no single script that will do everything correctly for you.
> 9 votes

# Answer
There is Beanstalk

> Advanced Deployment Tools Deploy your repositories to (S)FTP, SSH and Amazon S3 in one click.

And there is GitHub's post-receive hooks.

GitHub will POST to a supplied URL when someone pushes to the repo. Just write a short PHP script to run on your linode VPS and pull from GitHub when it receives said POST.
> 4 votes

# Answer
You may be interested in Fabric

> Fabric is a Python library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.
>
> It provides a basic suite of operations for executing local or remote shell commands (normally or via sudo) and uploading/downloading files, as well as auxiliary functionality such as prompting the running user for input, or aborting execution.

You may also be interested in drush for command line access to Drupal.

e.g, some relevant drush commands:

```
archive-dump    Backup your code, files, and database into a single file.
archive-restore Expand a site archive into a Drupal web site.
core-rsync (rsync)    Rsync the Drupal tree to/from another server using ssh.

```

or both :)
> 3 votes

# Answer
Although the question is a year before I would suggest using these 3 tools.

Git \+ Capistrano \+ Drush.

It just works for such kind of tasks.

Here are some **Capistrano gems/files** related to Drupal to help you automate Drupal development:

And here are some useful resources so you don't have to search all over the web:
> 3 votes

# Answer
These are my finding. Drush provides the sync, using mysql dump and restore as complete, not the changes made after some interval.

Many things can be tracked with \- Configuration Module \- Features \- Extra Features

Please see the presentation for further. https://docs.google.com/file/d/0B6Sp-HBmxgGMMnhhQXVrR1hDUVU/edit?usp=sharing
> 2 votes

---
Tags: deployment
---


# Question
Title: How to create a menu from content type fields found on a node?
I have a content type with 4 text areas I would like to make into 4 separate "pages" by creating a menu dynamically based on fields.

Is this possible? Reason I'd like to do this is to create a single content type a person creates with the necessary fields and then has a menu created dynamically from these fields if they contain data.

The only other option I can think of is creating multiple content types and then combining them.

# Answer
You could build this with the Field Group (https://drupal.org/project/field\_group) module, which will allow you to group your content fields into horizontal tabs, vertical tabs, accordions and more. By default, groups with only empty fields will be hidden, i.e., they will not display in the "menu".

While this would not create separate pages, your use of the word in quotes makes me think this would be an acceptable answer.

There is a decent tutorial at https://www.youtube.com/watch?v=5GU\_tb4K-f4.
> 1 votes

---
Tags: 7, routes, nodes
---


# Question
Title: Why is my custom theme template not found?
In my theme's template.php file, I defined a new theme hook using `hook_theme()`:

```
function MYTHEME_theme() {
  $hooks = array(
    'custombody' => array(
      'template' => 'custombody',
      'variables' => array(
        'content' => array(
          'body' => '',
        ),
      ),
      'path' => drupal_get_path('theme', 'MYTHEME') . '/templates/custom',
    ),
  );

  return $hooks;
}

```

I also placed a file named `custombody.tpl.php` under `templates/custom`.

But I can't get this template working. It's not found from Drupal. I keep getting this warning in the log:

> Theme hook custombody not found

Details:

I am trying to use this template to style the body part of HTML emails. I'm using Swift Mailer to send HTML emails and I want to theme the body part with my custom theme. There is no problem on the swiftmailer part.

Normally `swiftmailer.tpl.php` prints the body text as it is:

```
<?php print $body; ?>

```

I've changed this in my own implementation of swiftmailer.tpl.php in my theme folder like that:

```
<?php print render($body); ?>

```

And I'm sending a render array as `$body`, instead of a string, what normally would be expected.

The array I'm sending is:

```
$variables['body'] = array(
  '#theme' => 'custombody',
  '#content' => array(
    'body' => 'Actual body text here',
  ),
);

```

What am I missing, that my `custombody` template is not being found?

UPDATE:

I also created a `theme_custombody()` function in my template.php file to test it, but it also doesn't work.

```
function theme_custombody($variables) {
  return 'TEST';
}

```

# Answer
> 0 votes
Try something like this:

```
function mytheme_preprocess_page(&$variables, $hook) {
  $variables['theme_hook_suggestions'][] = 'custombody';
}

```

to add a theme hook suggestion a template called 'custombody.tpl.php'.

However it sounds like what you really want to do might be to render the `$body` directly, before it gets passed to the default template. In that case you'd use a process or preprocess function to do that directly instead of doing it in the template itself.

# Answer
> 0 votes
I had no trouble getting your code to work as-is.

I copied and pasted your theme function into my theme, created the template file at path-to-MYTHEME/templates/custom/custombody.tpl.php and cleared caches.

Then I created a test script, script.php and ran it with drush php-script script.php.

```
<?php
  echo theme('custombody', array('content' => array('body' => 'Hello, World!')));
?>

```

Some things to try:

1. Make sure that the path attribute is actually being set to what you expect. Using the PHP filter, a bootstrapped script, a drush script, or somewhere in your code,

echo drupal\_get\_path('theme', 'MYTHEME') . '/templates/custom';
2. Make sure that the name of your theme is correct, no typos, both in the function name and in the path attribute.
3. Also check that the name of your theme (e.g. MYTHEME) is unique. Make sure you don't have a module using that same key for a name.
4. Make sure that your theme is enabled.

---
Tags: 7, emails, theming
---


# Question
Title: Custom template for a specific page within module for Drupal 7
I'm writing a module for Drupal 7 that gives every user with the right permissions a new page in his profile. I want this page to only display the Drupal header and a div with a specific ID, for a JS web app to attach itself to. AFAIK, the easiest way to do this would be by using a template file that only prints those two things.

From what I read in Create a template for a custom page in Drupal 7?, I just need to create a page--user--%--POD.tpl.php file, which I have (the new page resides at the path user/%/POD). I have als added this file to my .info file.

```
name = Module with some template problems

...

files[] = page--user--7--POD.tpl.php

```

As a way of minimizing factors, I've started by creating a page for user 7 only, but this will have to work for any user eventually. I have uninstalled the module, cleared all caches and reinstalled it again, but it still doesn't get used when I browse to user/7/POD.

Any help would be greatly appreciated.

According to https://drupal.org/node/1089656, the correct hook suggestion that I need to implement would be page--user--POD.tpl.php. I've renamed my template file accordingly. No success yet.

# Answer
> 0 votes
I believe the original template name you had with the percent symbol was correct. The problem is you are doing it in a module, not in a theme.

By default, you have to put the template in your theme for it to be picked up automatically.

Also, in module info files, the use of `files[] = something.ext` is only for files that contain classes, so Drupal can autoload them. Files like template files, module files, installation files, etc. don't go in there.

# Answer
> 0 votes
I found a solution at https://drupal.org/node/715160 .

Apparently, in order to do this, you need to alter the theme registry in order to let Drupal know that there are templates to be found in your module's directory. You can specify which hooks it can find modules for and what path(s) it needs to search.

---
Tags: 7
---


# Question
Title: Google analytic module - demographic track does not work
I am building a drupal 7 site, and using the Google analytics module.

I installed it, and made the needed adjusments on my Google analytic account.

But, when I am on the Demographics tab on Google analytics, I can't see any data regarding the "overview", "Age" and "Gender".
Note: "Track DoubleClick data" was always enabled.

In addition, I get the following message:

```
Some data in this report may have been removed when a threshold was applied

```

Learn more

How can I solve this issue?

# Answer
You will have to enable `Track DoubleClick data` under the Search and Advertising tab in the GA module settings. You should also make sure your privacy policy is up to date with the correct info found here.
> 2 votes

---
Tags: google-analytics
---


# Question
Title: How to place every node of a content type under a menu item?
I'm looking for a module that will let me add every node of a content type as a link with a common parent link.

# Answer
You can use Default Menu Link module for this and core menu settings for content type..

> Provides the user with a check box on all content types to set the "provide a menu link" value to true by default.
>
> This is basically a nice way to ensure the menu system is adhered to by all content authors.

You need to set Menu settings for content type..
> 1 votes

---
Tags: 7, routes
---


title: Customize create content page

text:
# Question
Title: Customize create content page
I'm wondering if there's a way to customize the create content page (not the content display page), including recordering and repositioning things.

ATM it's "Title" on top, followed by "Body" on the bottom, followed by other fields like "Upload" and "Save".

Is there a way to customise the labels, reorder and repositon this page?

For example: To move "Upload" on top and in the middle, followed by "Title" and "Body" below it while changing the label of Body to "Description", and changing the caption of the "Save" button to "Submit"?

Thank you very much.

# Answer
I looked around for a long time and found that the very powerful Display Suite module that has a great screencast series covering it here on youtubewas what I was looking for.
> 0 votes

# Answer
Yes, it is possible. Firstly you need to read and understand the Drupal 7 Template (Theme Hook) Suggestions documentation to render and rearranging field items.
To alter Title , Body, Save etc you will need to understand hook\_form\_alter, it is used for altering a form and hook\_form\_FORM\_ID\_alter is a smarter way to do the same as hook\_form\_alter.
There is a cool hook\_form\_alter tutorial hope will help you.
> 3 votes

---
Tags: nodes
---


title: Views Ajax error with jquery 1.8

text:
# Question
Title: Views Ajax error with jquery 1.8
I'm using Bxslider which required jquery 1.8 to be responsive. However, when using jquery 1.8 I get errors with views when trying assign and change values.

How should I solve this problem?

# Answer
> 0 votes
Installing the 7.x-2.x-dev version of jquery allowed me to select version 1.5 of jquery for administrative pages and solves my problems.

---
Tags: views, javascript
---


# Question
Title: How to create a page view of two content type in Drupal 7
I have two content type named as workshop and meetings. I wanted to create a new page view (say events) of these content type such that event page should have titles of post from each content grouped with content type.

I tried to create this view but I can't select multiple content type while creating a view.

# Answer
> 2 votes
Here's how you do it: Once you've created your view, selecting either one of your content types:

1. Under "filter criteria", click the filter called "content type (= YOUR\_CONTENT\_TYPE).
2. Select "is one of", and then select all the content types you want to include.
3. Click Apply (all displays).
4. Save the view.

---
Tags: views
---


# Question
Title: Fatal error: Cannot use object of type stdClass as array in
I get an fatal error on the 'add content page'.

Fatal error: Cannot use object of type stdClass as array in

```
function mymodule_form($form, $form_state){
    $form['mymodule'] = array(
        '#type' => 'textfield',
        '#description' => t('Please enter your text here.'),
        '#required' => TRUE,
    );
    $form['mymodule_submit'] = array(
        '#type' => 'submit',
        '#value' => 'Submit this form'
    );

    return $form;
    return node_content_form($node, $form_state);
}

```

The problem's happen when I add my form, when I use only the

```
return node_content_form($node, $form_state);

```

it is working fine, what do I wrong?

# Answer
> 1 votes
There are two related but distinct concepts that seem to be conflated in your code, i.e. hook\_form, and the notion of a drupal form builder function. Hook\_form uses the template explained by @gisleHannemyr.

The template for a form builder function is:

```
function mymodule_example_form($form, &$form_state) {
  ...
  return $form;
}

```

Use hook\_form to create or override node creation forms, and a form builder function for any other (non-node-related) form.

If you simply want to alter an existing (node or other) form, you should use hook\_form\_alter, instead.

# Answer
> 1 votes
It always a good idea to read the documentation.

The template for `hook_form` is:

```
hook_form($node, &$form_state)

```

The first parameter passed into the (`$node` in the template) is an object. In your hook, you've called it `$form`. That is confusing. You're also treating it as an array. That is just wrong, and is what triggers the error message you see.

Additional quirks:

The second parameter is passed as reference. You're implementation is passing it as a value (it won't bite you, since you're not using it, but you better get it right anyway).

You've got a spurious second return statement at the end. It will not do any harm, since it is never executed, but it is confusing.

Here is how your hook should start and end (the bit in the middle looks OK),

```
function mymodule_form($node, &$form_state) {
    $form = array();

    // build the form array.

    return $form;
}

```

---
Tags: hooks
---


# Question
Title: How to display article from category and show it in block
I have created a content type which has some fields, and I want these fields to be displayed as a block.

I need to display some article like 5 articles from category called sport news only.

how can i do that in drupal 7

# Answer
Not sure of your exact need, between articles, your content type... Try something like that :

Go to **admin/structure/views/add**. Fill in the form : Show Content of type *article* (or *Your content type*). If *sport news* is a taxonomy category, tagged with *sport news*.

Uncheck *create page*, check *create a block*, display format *table of fields*, five items, then continue and edit.

Now in the left side of the form, click on add fields, choose the fields you'd like to display and settings for each field. Give a admin name to your block in Block settings, at the top of the middle column. You now have a block view with 5 items of content type article and the fields you selected.

Go to **admin/structure/block**, look for the block you've just created, and set the region where you'd like to display it, or click on configure to be more specific, displaying it on specific pages, for specific roles or whatever.
> 0 votes

# Answer
You must install the views plugin. After installing the plugin, you can go to structure-view-add a view to make a list of posts with condition that the content type is of specific criteria and set the display type to be a block. After that go to the block setting and set region the block belongs to.
> -1 votes

---
Tags: views, blocks
---


# Question
Title: Drupal modules to display external RSS feed
what Drupal modules should be installed and enabled to display external RSS feed? I mean not default Drupal Aggregator module, but another, more flexible way to display feed in any page as content. (I had all this preconfigured, but a long time ago)

# Answer
> 1 votes
Feeds (previously FeedsAPI) is the one you want. Here is a quote about it (from the module's project page):

> Import or aggregate data as nodes, users, taxonomy terms or simple database records.
>
> * One-off imports and periodic aggregation of content
> * Import or aggregate RSS/Atom feeds
> * Import or aggregate CSV files
> * Import or aggregate OPML files
> * PubSubHubbub support
> * Create nodes, users, taxonomy terms or simple database records from import
> * Extensible to import any other kind of content
> * Granular mapping of input elements to Drupal content elements
> * Exportable configurations
> * Batched import for large files

---
Tags: views, 7, feeds
---


# Question
Title: Select organic group on the user registration form
There's a post already on the post installation forum, but I'm not sure if this is a OG bug. http://drupal.org/node/1108884

I am using Drupal 7 and OG 7.x-2.1 version. There is no "Group Audience" in the manage fields page and I think it is replaced with "Group membership", the field type is "Entity Reference" and the widget is "OG Reference". Also there is no input type in the field setting page and I can not find any field that has a "Always show other groups" option. I have checked the option "Show on registration form of that field, but the combo box on the registration form does not have any option. Any suggestion?

# Answer
At last I found how to do that.

For displaying a group in the registration form, after enable "show on registration form" option in the admin/config/people/accounts/fields/og\_user\_node page, you should:

1. Add the group register field to the group fields on the "groups field setting page"
2. Then you should check the "Show on registration page" option on the group editing page
> 2 votes

# Answer
I managed to get this working. These very short instructions are indeed correct. But the first few times I tried to follow them I did not have any success. Therefore I thought it would be useful to explain the steps and potential pitfall in more detail.

I have broken this answer up into two parts. You may have already done the work in Part A of these instructions. I have included them so that if you are really struggling you can go back on a new Drupal installation and ensure that you have followed exactly the same steps as me. You may find this unnecessary, if so skim read Part A and check you are at the right stage before skipping to Part B.

**Part A:** Steps to install OG and Create an Organic Group (Can be skipped if already completed)

1. Install Organic Groups and enable it and its submodules (Organic groups register, organic groups UI etc.) as normal (You will need the Entity reference and Views\_bulk\_operations modules installed to enable these modules). You may need to rebuild the permissions after doing this – you should get a warning if required.
2. Install *Organic groups register* which is a submodule of Organic groups - You will need to in order to complete the steps
3. Create the content type that will be your group (Administration \> Structure \> Content types). I am calling my example content type ‘Special Group’. Important: in the Organic groups section at the bottom of the create content type select the ‘Group’ checkbox to allow this content type to be a group. Save the content type, you can add the other fields you need once you have everything working.
4. Create a piece of content using your group content type. (Content \> Add Content \> Special Group) I called mine My test Group.
5. In a new browser where you are not signed in, view the new piece of content e.g. ‘My test Group’. You should be able to see the ‘Group: request group membership link’.
6. Clicking on the request group membership asks you to sign in or register, and then you have to go back to the group to be able to join it. It is this step that we want to improve, by allowing a user to join a group from the registration form.

**Part B:** Steps to enable group sign up during registration

7. First we need to add the 'Group register' field to your group content type. To do this go to Configuration \> Organic groups \> OG field settings.

1.a. From the Bundles drop down, in the node section, select your group content type (mine is called Special Group).

1.b. From the Fields drop down select ‘group register

1.c. Click the ‘Add field’ button at the bottom of the page. After this has been done you should be able to see that the field ‘Group Register’ has been added to the list at the bottom of the page.

2. Next we need to add field to the user registration form.

2.a. Go to Configuration \> People \> Account settings \> Manage fields

2.b. Edit the 'Group membership' field.

2.c. Select the 'Display on user registration form' checkbox and then save.

2.d. You can now see the ‘Group membership’ field in the Account settings field list with a machine name of ‘og\_user\_node’ and a field type of Entity Reference.

2.e. Warning: Because you have checked ‘Display on user registration form’ there is a temptation to believe that you have completed the task. If you go to register a new account you will be able to see the ‘Group membership’ field, however there will be no groups in the list. Obviously we do want the groups to be listed here. This is where a lot of users were getting stuck. Don’t worry about this. Simply continue to the next step.

3. Next we need to select which groups appear on the registration page (solving the problem discussed in 2.e.) The default behaviour of the 'Group membership' field that we created in step 2 is set to 'Do not show on registration page' in our group content type that we created in Part A step 2. We need to do two things – change the default so that new groups that are created have the right setting automatically and then update any groups that have already been created.

3.a. First we will change the default so that new groups that are created have the right setting automatically.

3.a.i. Go to Administration \> Structure \> Content Types and edit the group content type you created in Part A step 2 (mine is called Special Group).

3.a.ii. You can see the Group register field in the list of fields with a Boolean field type (see screenshot 6). Click edit to edit this field.

3.a.iii. In ‘Default value’ change the radio button to ‘Show on registration page’ and click save settings. Doing this means that all new groups that are created will be listed in the drop down on the registration page by default

3.b. Second we need to update any groups that have already been created.

3.b.i. Go to Content and filter the content by the group content type that you created in Part A step 2 (mine is called Special Group).

3.b.ii. You now need to edit each of the groups that have already been created. For each find the ‘Group register’ radio button group and change it to show on registration page.

4.Now you can test that this has worked.

4.a. First we will test our existing groups. In a browser where you are not logged in create a new account. You should be able to see the group that you created in Part A step 3 (mine is called ‘My test group’) in the Group membership list.

4.b. Second we will test that new groups that are created have the group register setting correct by default. Create a piece of content using your group content type. (Content \> Add Content \> Special Group) I called mine My second test Group. You should see that the ‘Group register’ radio button is already set to ‘Show on registration page’ as you are creating the content. In a browser where you are not logged in create a new account. You should be able to see the group that you just created in the Group membership list.

I have also added these instructions to the Drupal Community Documentation.
> 8 votes

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


title: Edit user profile form

text:
# Question
Title: Edit user profile form
I have found many articles about showing sections of the user profile edit page based on `$user->roles` but none that deal with other custom fields.

For example,

```
global $user;
if (in_array('administrator', $user->roles)) {

}
else {
  drupal_add_css(drupal_get_path('theme', 'my_theme') . '/css/normal-user.css');
  //Disable admin-only fields
  $fields = array('field_employee_types');
  foreach ($fields as $field) {
    $form[$field]['#disabled'] = TRUE;
  }
}

```

BUT what I am needing to do is check a custom user profile field (which happens to be a taxonomy term array) and if the user has a certain term, then do something such as show fields. Can someone lead me in the right direction? I am doing all of this in a custom module to alter profile form.

thanks!

---

So I somewhat got the info to print on the user profile page

```
[field_affiliation] => Array
    (
        [und] => Array
            (
                [0] => Array
                    (
                        [tid] => 28
                        [taxonomy_term] => stdClass Object
                            (
                                ...
                            )
                    )
            )
    )

```

# Answer
(upon writing back and forth, the solution to this problem is listed underneath ***Edit 2***)

not sure where exactly you are stuck. are you asking how to check which taxonomy term they have assigned in a field, or how to show/hide fields?

if you already have access to the taxonomy term id and you need to further check the content of the taxonomy term, you can assign that id to a variable like`$tid`, and then do something like this:

```
$myfield_term = entity_load('taxonomy_term',array($tid))[$tid];

```

I find myself doing this a bunch of times, because of the way I use taxonomy terms. this gives you an object with all the content of the taxonomy term. if you wanna fetch information out of it, keep in mind that php uses a different approach for objects than for arrays. so if you need the title value, instead of doing `$myfield_term['title']`, you need to do `$myfield_term->title`

---

**EDIT 1:**

can you please show us what the structure of the array looks like?
this can be done in various ways. drupal has its own technique of printing arrays (I believe it's caled devel or something), but I still prefer the good old native php way via `print_r`.

how I'd do it:

* assign the array to a value, e.g. `$user_apartments`
* then in the next line add `print_r($user_apartments);`
* switch back to your browser, right click \> view page source (may vary depending on your browser, this would be Chrome)

somewhere at the beginning or further down the code (depending on the file that executed the `print_r` command) should be a printed list of an array, that may look something like this:

```
Array
(
[0] => 4
[2] => 11
[3] => 28
[4] => ...
)

```

but it may as well be more complicated than this, if for example it not only lists the term IDs but all the content of the terms as well.

* now just grab it and past a part of it here please (if it is a huge list, no need to post the repetitive part)

the way the `print_r` command works is it takes the object that you feed into it and displays the content in a more human-readable manner, giving you an insight of its structure, whether something is an object, an array, what else it contains etc.

so depending on what this array looks like, we will need to use a different approach on checking the array for your specific ID, this is why I am asking for an insight of the array we want to check.

---

**EDIT 2:**

so upon looking at the structure of the array, this is how you check for your term ID: the array that we need to look at is `...['field_affiliation']['und']`. you can (optionally) assign it to a variable, e.g. `$field_affiliation`, and then do something like this:

```
$hasDepartment28 = false;
foreach( $field_affiliation as $thisTerm ) {
    if( $thisTerm['tid'] == 28 ) {
        $hasDepartment28 = true;
        break;
    }
}

```

then, where- and whenever needed, you can simply check by doing

```
if( $hasDepartment28 ) {
    // do..
}

```

and here is how it works:

* `$hasDepartment28`: we declare a boolean, and we say by default the department with the term id 28 is not listed
* using `foreach`, we loop through every entry that is listed in the taxonomy term array we named `$field_affiliation` and every time we assign current entry to the variable name `$term`
* now, as we could see in the structure of the array, what we want to look for is the `'tid'` key of every entry
* we compare it with the ID you mentioned in the comment below, and if we have a match, we set `$hasDepartment28` to `TRUE`
* and via `break;` we stop the current `foreach`. since we found what we were looking for, there is no need to loop through any other entry in the array that may come after it
* if we found no entry at all where the `tid` equals `28`, the boolean we set earlier will still equal `FALSE`

let me know if it worked!

keep in mind all the variable names are arbitrary and you should use whatever describes the variable best.

one last thing I'd add is if you were delete and re-create that term entry, you'd have to update this code and check for a different Term ID. perhaps a more readable and future-proof approach would be to check inside the `foreach` loop for something like:

```
if( $thisTerm['taxonomy_term']->name == 'Apartment A' ) { ... }

```

but this in return only works if the `[taxonomy_term]` gets loaded into your array for every entry. chances are only the first entry has all the term content, but based on the array you submitted I cannot tell you if this is the case. if you wanna stick to this approach though, this is exactly where drupal's `entity_load` function becomes super useful!
> 0 votes

---
Tags: users
---


# Question
Title: Views - show only items not in a given nodequeue
Is there a way to filter on the value that is in nodequeue? I want to have a top 5 article list nodequeue, but I want a list of articles after that in terms of most recent is highest, except for those given nodequeue items. Is there a way to do this?

# Answer
> 1 votes
Alright the answer is this:

You have to create a relationship with the nodequeue(s) in question that you wish to filter against. You have to make it so that the checkbox, "relationship required" is unchecked - otherwise it will primarily filter all items that are not in the nodequeue.

At this point, this will provide a filter to you termed, "in queue" - set this queue to false.

At this point, all items that are NOT in the nodequeue will be listed.

---
Tags: views, nodes
---


# Question
Title: Show hook_form on specific content type Drupal 7 Programmaticaly
How can show a form that is created with the drupal \_hook form api, on a specific content type? So, as example:

I created new content for the content type 'outside' when I click on save I see the content type like this:

* Titel
* Date
* Description

What I want is a form below this. I created one with a \_hook form and it is working an saves data to my database but I have no idea, how can I show them on the same page as my content. It may not show on the content type 'inside'! Now it's a other page the link is /outside-form and only the form shows up there, no content type.

How can I get them below my content on every page that has the content type 'outside'? I have written a own module, but only this is not working/showing up on specific content(type).

Can someone explain it to me?

# Answer
You need to create a block that's content contains following code:

```
$form = drupal_get_form('YOUR_FORM_ID');
print drupal_render($form);

```

Set the block visiblity only on content type 'outside' & place this block in any region as per your suits.
> 0 votes

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


# Question
Title: D7 : Plupload version could not be determined
I have installed the Plupload module and downloaded the library files v1.5.8.

I then uploaded the 'js' folder to '/sites/all/libraries/plupload/'

Having done so, 'admin/reports/status' now returns a message saying 'Plupload version could not be determined.'

Have I missed something obvious?

* I have also tried the same with the latest v2.1.1 , with the same results.

# Answer
Ok.

The problem was that i never uploaded the changelog.txt along with the js folder.
> 3 votes

---
Tags: files
---


title: Drupal 8 Add Javascript

text:
# Question
Title: Drupal 8 Add Javascript
What is the best way to add javascript to Drupal theme now that drupal\_add\_js is gone?

I want to use specifically jQuery ui animate, which I suspect is in Core, but I cant find out how to add it to my theme.

# Answer
Use the following function in template.php of your theme.

```
function MYTHEME_preprocess_page(&$vars, $hook) {
  $path = drupal_get_path('theme', 'MYTHEME');
     // Render the main scripts file.
  $local_js = array(
    '#attached' => array(
      'js' => array(
        $path . '/js/scripts.js' => array(
          'group' => JS_THEME,
          'weight' => 9999),
      ),
    ),
  );
  \Drupal::service('renderer')->renderRoot($local_js);
}

```
> 0 votes

# Answer
If you'll look at seven theme you'll see a note saying that libraries should be attached in hook\_page\_alter. I have similar issue https://drupal.stackexchange.com/questions/106842/whats-the-proper-way-to-load-themes-libraries
> 0 votes

---
Tags: javascript, 8
---


# Question
Title: How to make user profile image reflect a transparent background?
I made a site with Drupal 7.26. Added on the Advanced Forums module with some other things.

Everything works fine except the user profile image is displayed with a white box/background instead of being transparent in the forums and user profile when clicking on the user name. I'm using a png image that has a transparent background.

Here's a cropped screenshot of how the picture is being displayed in the forums.

As you can see there is a white box/background instead of it being transparent. The strange thing is that when I hover over the image with my mouse the white box/background disappears and the image displays as it should.

Here's a cropped screenshot of what it looks like when the cursor is hovered over the image.

That is how I would like the profile pictures to be displayed in the forums should a picture have a transparent background.

Does anyone know of a setting or something on how to get this done?

I'd really really appreciate any help with this as I'm pretty clueless.

Thanks in advance for any replies

Barrels

# Answer
If the image background is transparent when you hover over it, then the picture has transparency, and must be a .png or .gif file.

Therefore the white background must be down to CSS

In Chrome or Firefox, right click on the image and select "Inspect Element". Find the CSS controlling the div or img, and change the CSS from

```
.picture {
   background:#FFFFFF;
}

```

to

```
.picture {
   background:none;
}

```
> 1 votes

---
Tags: media, users
---


# Question
Title: How can I have a block show only on the /user page, but only for users with specific role?
I have users with the role "authors" and a block in /user showing publications so that visitors can see the publications of every "author". The problem is that the block is showing at every user profile page even if the user has not an "author" role. How can i set this block to show only to user profile pages that have a role "author"?

# Answer
On the configure block page, at the bottom in the vertical tab menu, click on the roles tab, and select which user role you want it to display for.
> 1 votes

# Answer
Call this function for visiblity settings: block visiblity settings \> Pages \> 'Pages on which this PHP code returns TRUE (experts only)'

```
function _user_block_visiblity() {
  if (arg(0) === 'user') {
    global $user;
    if(in_array('authors', $user->roles){
        return TRUE;
    }
  }
  // Default is to not show the block
  return FALSE;
}

```
> 0 votes

---
Tags: blocks, views, users
---


# Question
Title: what permissions are needed to give a role ability to access: admin/content list page
what permission do i need to give a role to give them access to the list page of content. path: admin/content

This is for drupal 7.

# Answer
> 1 votes
found it! its under this:

```
Access the content overview page
Get an overview of all content.

```

---
Tags: 7
---


# Question
Title: views use the same css class for both sidebar and article, blocks me from resizing main content
I have a front page view of articles that are displayed as trimmed as well as a sidebar block. This is all fine I have my layout all good. The issue is, if I click on an article to go to it's full page view then the article retains the css class from the front-page so I am stuck with a 70% full page article.

The main issue is that both my articles and latest articles (sidebar) use the same class name "content". I tried to edit templates in order to override this but to no avail. All blocks use the "content" class which makes it uneditable!

*edit* in fact every block I have uses the class="content"!

Any help would be appreciated! Cheers!

# Answer
Surely you can either define different classes for the teaser and fullpage views of your content type using templates, edit the views template or define your css using the class .front or .node-type-article ?

For 1) create a node--content-type-name.tpl.php file and use the `if (!$page) { // teaser view` switch to output a different class or template.

For 2) create a views-view-unformatted--view-name.tpl.php file and wrap it in a different class

For 3) use the built in drupal classes that are outputted into your themes body tag in your themes html.tpl.php file with `<?php print $classes; ?>`. Edit your css to specify your style usinf `.front .article {} .not-front .article {}` etc ..

Or edit your block.tpl.php file and remove the class .content
> 0 votes

# Answer
I have finally found the culprit! It's the pager that for some reason decides to take 100% of width, so it forces the sidebar to break apart! :)
> 0 votes

---
Tags: views, theming
---


# Question
Title: how to? if is_front = div class "front-content" else "content"
I have a view that displays the latest articles on the front page and it links to the full article. I want to force a div class to the front page to 70% so I tried to add these lines to both block.tpl and page.tpl and it doesn't take into account the condition, it just sets to front-content on both displays.

Here is the code:

```
<?php if (!$is_front): ?>
    <div class="front-content"><?php print render($page['content']); ?></div>
    <?php else: ?><div class="content"><?php print render($page['content']); ?></div>
    <?php endif; ?>

```

# Answer
> 1 votes
Instead of adding a new class (and a div) you can simply target and override the layout for the front page in your style sheet with:

```
.front .content {
  width: 70%;
}

```

It's possibly you need to be more specific though, so you don't target all `.content` on the page. I don't know how you theme code looks, but it should be something like `.front #main .content`.

This assumes that your theme uses the default body classes in html.tpl.php for Drupal 7

```
<body class="<?php print $classes; ?>" <?php print $attributes;?>>

```

Or page.tpl.php for Drupal 6.

```
<body class="<?php print $body_classes; ?>">

```

Cheers,

---
Tags: views
---


# Question
Title: Which modules help with loading of large images in a nice transition?
Currently I am using the single\_page module that does the anchor page sliding thing on the page, but currently I'm loading big images onto this single page. Which modules or recommendations on how to streamline the loading of these large image files? I tried the image\_lazyloader module but none of the images show up when activating this on the single\_page module. I'm guessing these two modules have a conflict. What other possible options do i have? it seems that spotify.com has the same setup, how are they doing it there?

# Answer
> 0 votes
Take a look at JAIL. You will also need the jquery jail plugin.

---
Tags: 7, media, performance
---


# Question
Title: How to save in a different subfolders the attachments of my users?
I want each user's attachments (they will be school assignments docs, photos, maps) to be saved in user's own subfolder in order to be able to collect them easily and separately.

How would this made possible and what are the best modules to utilize in order to achieve it?

# Answer
> 0 votes
In Drupal 7, the core File module and the Token module (https://drupal.org/project/token) will let you do this.

In the settings for your file field, specify a file directory using a user token. I recommend prefacing the token'd directory with users/ (or something) so that you can easily find all of these files separate from other files on the site.

For example to use the user ID as the directory, set the 'file directory' to

```
users/[user:uid]

```

You can see all the user-related tokens available to you on your site at admin/help/token.

# Answer
> 0 votes
filefield and Token module can do it, nice and clean.

> The File (Field) Paths module extends the default functionality of Drupal's core Upload module, the FileField module and many other File Upload modules by adding the ability to use node tokens in destination paths and filenames.
>
> In simple terms, File (Field) Paths allows you to automatically sort and rename your uploaded files using token based replacement patterns to maintain a nice clean filesystem.

---
Tags: 7, users
---


# Question
Title: Url adds zero at the end and duplicate contents appearing
Some of my contents have duplicate contents meaning it creates two path for the same content and I don't know how it track this and it adds zero(-0) at the end of the url like the below

```
www.example.com/fully-furnished-one-bed-southridge-area-1061-sqft-0

www.example.com/fully-furnished-one-bed-southridge-area-1061-sqft

```

now I am manually redirecting the url's using global redirect module for the purpose of SEO. Is this correct way to do this ? or I have to set anything to block those url's in ROBOT.txt and yes it shows duplicate title in webmaster tool, any idea on how to solve this issue ?

# Answer
This is a common way how url aliases are generated - if there are nodes with the same title, it appends the "0" (and "1", "2" for more duplicates).

So if you really need nodes with duplicate title, you can edit the path alias manually on node edit form to something else. But from the seo point of view, its not a good practice to have multiple pages with same title.

The best option in my opinion is to avoid such duplicates completely. For your situation, you can use Remove Duplicates module to delete duplicate nodes based on the node title. (For drupal 6, you have to do some coding - here)

One more idea: if the case is that you have multiple content types and you need two nodes of different types to have the same title, change the alias rules so that different types have different urls (e.g. blog/my-title and article/my-title)
> 1 votes

---
Tags: 6, path-aliases
---