# Question
Title: How to use a tpl.php file for a theme function
I am using LoginToboggan which provides a theme function. You can use this theme function in a template.php file to control the mark up.

However, the code becomes quite unwieldy in template.php. Is there any way to modify the function so it can use a tpl.php file?

---

## More info

This is the function LoginToboggan provides:

```
function theme_lt_unified_login_page($variables) {

  $login_form = $variables['login_form'];
  $register_form = $variables['register_form'];
  $active_form = $variables['active_form'];
  $output = '';

  $output .= '<div class="toboggan-unified ' . $active_form . '">';

  // Create the initial message and links that people can click on.
  $output .= '<div id="login-message">' . t('You are not logged in.') . '</div>';
  $output .= '<div id="login-links">';
  $output .= l(t('I have an account'), 'user/login', array('attributes' => array('class' => array('login-link'), 'id' => 'login-link')));
  $output .= ' ';
  $output .= l(t('I want to create an account'), 'user/register', array('attributes' => array('class' => array('login-link'), 'id' => 'register-link')));

  $output .= '</div>';

  // Add the login and registration forms in.
  $output .= '<div id="login-form">' . $login_form . '</div>';
  $output .= '<div id="register-form">' . $register_form . '</div>';

  $output .= '</div>';

  return $output;
}

```

# Answer
Create a template file **lt-unified-login.tpl.php** in your theme directory and put this function inside **template.php** to override **theme\_lt\_unified\_login\_page** & return the HTML output of **lt-unified-login.tpl.php**.

```
function YOURTHEME_lt_unified_login_page($variables) {
  $template = drupal_get_path('theme', 'YOURTHEME').'/lt-unified-login.tpl.php';
  return theme_render_template($template, $variables);
}

```
> 2 votes

---
Tags: theming, authentication-authorization
---


# Question
Title: How can I create a menu item corresponding to a link to another (external) site?
In my menu I can create an **internal** link corresponding to a path like → '/path/to/node'.

But when trying to create a link to an external website (like `→ http://www.external.com`), the link actually becomes `→ https://www.mywebsite.com/http://www.external.com`

So basically, external links are not recognized as external. But instead they get added to the base URL.

How can I make this to work?

# Answer
You are not allowed to add external link to menu items as this link confirms it too.
> 0 votes

---
Tags: routes, navigation
---


# Question
Title: How to remove a taxonomy term with an empty required field without having to fill it?
I'm having a problem while trying to delete a taxonomy term that has an empty required field. To proceed and delete it, I have to fill the empty field to be able to delete it.

How can I remove the taxonomy term without having to fill the empty required field?

For me there is no problem by adding a letter to the field and then delete the taxonomy, but my client is getting crazy with this issue and he is getting me crazy.

Any solution?

Thank you in advance.

# Answer
> 1 votes
I usually write out code when I need to bypass validation for deletion. You can use taxonomy\_term\_delete to remove the items and bypass validation:

```
$tids = array(); //Add your term ids that you need deleted in the array
foreach($tids as $tid) {
  taxonomy_term_delete($tid);
}

```

---
Tags: taxonomy-terms
---


# Question
Title: Add user to Organic group after commerce product order with rules
I would appreciate any help, I have been searching for a solution for over a week now.

I have tried this tutorial https://drupalcommerce.org/blog/10809/selling-organic-groups-using-drupal-commerce but unfortunately the first component can't be completed because of an error message of data type not matching. Several people have complained about this but I'm yet to find a solution.

I also tried http://s1l.org/selling-access-organic-groups-drupal-commerce but the loop in the component doesn't give me the field that is in the tutorial.

I have also tried the Commerce License module with the Commerce License OG module. It expects the group to exist before the product is created. You are to select the group from a list of groups when creating the product. This doesn't match my use case. My groups are created after a product has been created.

# Answer
I was able to do this finally by tweaking the tutorial posted on this site: http://s1l.org/selling-access-organic-groups-drupal-commerce. I removed the loop in the components since my field only takes one value and I removed the condition to check if the order has been paid and now it's working.
> 1 votes

# Answer
I think you're struggling because your use case is very specific. I would start by creating Rules components to do just one thing as you can call Rules components as actions in other Rules, etc.

First start by creating a Rules component that assigns the user to the group and work backwards from there.
> 0 votes

---
Tags: 7, commerce, rules, organic-groups
---


title: Drag and Drop Sort Custom Entities

text:
# Question
Title: Drag and Drop Sort Custom Entities
I am looking for a simple way to sort my custom entities through a drag and drop interface and display them in the custom order in my views.

The best way would probably be to add a weight basefield to the entity type and let the drag and drop interface change the weight on each entity through ajax. Are there any examples on how to do that?

# Answer
> 1 votes
You can created an administration page views with you custom entities and to sort it you can use use the DraggableViews module. You would have to create another view to display your entities.

---
Tags: forms, 8, entities, ajax
---


title: Translation of the OG's User Roles

text:
# Question
Title: Translation of the OG's User Roles
I have a view which contains the relationship **"OG membership: OG Roles from membership"**, and the only thing I need is to translate the retrieved values from this relationship.

What is your recommendation?

# Answer
> 0 votes
This is an open issue which is worked on here:

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

---
Tags: 7, views, organic-groups, i18n-l10n
---


# Question
Title: Reload only the content area of a website while the sidebars remain static
Is it possible to reload only the content area of my website while the rest of the sidebars remain static? I notice that twitter does this, i am wondering if it is achievable in drupal. Thanks

# Answer
Yes, it's possible to update the content area without updating the sidebars using Ajax or Ahah. There are multiple modules for implementing ajax functionality in various parts of Drupal:

It will depend on the specific requirements of your site and its content as to which method would make the most sense.

Besides Ajax modules, another more advanced option is an idea often referred to as "Headless Drupal" in which you use Drupal as a backend in conjunction with a dynamic front-end framework like Angular or Backbone.

If you're just getting started with Drupal though, I would encourage you to get a bit of experience building simple Drupal sites before getting too focused on Ajax functionality. If you're not already familiar with Javascript, you'll likely end up being somewhat limited in terms of what you can do with the out-of-the-box functionality available from community contributed modules.
> 2 votes

---
Tags: 7
---


# Question
Title: Additional filter for (image)fields to filter node display
I need to display nodes on multiple places. For some fields I have multi values. On every place I'd like to display other values of the field. I'd like to have maybe some checkboxes as filter.

For example:

An multi value image field. 3 places to display these image on the site. For every place a checkbox (area1, area2, area3). When checkbox 1 and 3 are checked, this image is displayed only in area1 and area3. When checkbox 2 and 3 are checked for an image, the image is displayed in area2 and area3.

Does anyone knows a solution for that?

# Answer
I'm not sure if it quite meets 100% of your requirements, but you might want to take a look at the Display Suite module. It lets you customize multiple displays per node type, each of which can be configured to display different fields.
> 0 votes

---
Tags: entities
---


# Question
Title: How do I redirect access denied to front page?
I asked this a while back and got nowhere. Sorry for the repost but it needs to be resolved (somehow).

If a visitor types in a URL for which they are not authorized, I do -not- want them to see a 403 page. I just want them to be redirected to the site home page.

I entered...

```
<front>

```

...in the 403 field under admin/config/system/site-information but that apparently does nothing. We're using LoginToboggan which (I think) overrides this.

How can I do this?

TIA,

# Answer
Instead of `<front>` try using `node` or 'home page path' if you have customized home page.

...in the 403 field under admin/config/system/site-information.

Ref: Redirect 404 errors to home page?
> -1 votes

---
Tags: 7, redirection, authentication-authorization
---


# Question
Title: How to access the links variable from a template?
I have created a views template for a block and I would like to insert the list of links that normally appears at the bottom of teasers and/or pages (the $links variable) into the template like it is done in `page.tpl.php`.

However I can't find how to get this information given a node's id.

How do I accomplish this? Is there a Drupal 7 command that accomplishes this?

# Answer
I have found the solution to this problem. You need to do the following in your template:

```
<?php $node = node_load($fields['nid']->raw);
global $language;
node_build_content($node, 'full', $language->language);
if (!empty($node->content['links'])): ?>
    <div class="links">
      <?php print render($node->content['links']); ?>
    </div> <!-- /links -->
<?php endif; ?>

```
> 0 votes

---
Tags: 7, navigation
---


# Question
Title: Creating dependencies between fields in content type creation form
I have two fields in my content type that I'd like to have depend on each other. The two fields are category (the dependee, a field list) and icon (the dependent field and also a taxonomy term field). They are both select lists. I want the dependent field (icon) to not be available to authors creating records in the admin interface. It should just automatically select the correct term based on the category selection above it.

I looked into 'Conditional Fields' but I'm not certain it does what I'm looking for.

Any suggestions?

# Answer
If you are looking out to do this through code, you can use hook\_form\_alter to hide the dependent field and hook\_node\_presave to set the value for dependent field.
> 1 votes

---
Tags: nodes, database
---


# Question
Title: Dynamically change views entity reference filter based on current form value
Is it possible to change the result of the view depending on the value being selected on the form, **node creation form without saving it first**?

Last time, my problem was filtering the views depending on the field value of current node and I found the answer using

Filter View by Entity Reference Value From Current Node -

```
$node=menu_get_object(); return $node->field_venue_for_catering['und'][0]['target_id'];

```

But when I tried this on an entity reference view, it doesn't show any result unless I save the form.

The case from the link given above is almost the same for this post, the difference is filtering the view dynamically without saving the form first.

Is there anyone that will be able to help?

Thank you very much!!!

# Answer
> 1 votes
Here's my solution:

I used Entity Reference Prepopulate for my "venue" for my case (linked from my question), so whenever I choose a venue it will pass a parameter to the url.

Then I used Views Contextual Filter Query to get the value of the parameter from the URL and automatically filter the view without saving the form.

BTW, Entity Reference Prepopulate doesn't work on edit form, so you need to create a node\_load function on your custom module. Check this for code reference

Then I created a code for edit link that has the param of venue and it's target id.

```
<?php
    $nid = arg(1);
     $node=menu_get_object();

    $l = l( t('EDIT'), 'node/'.$nid.'/edit',   array('query' => array('field_product_venue' => $node->field_product_venue['und'][0]['target_id'] )  ));
    echo $l;

```

?\>

I hope this will of help to somebody!

Thanks!

---
Tags: views, entities
---


# Question
Title: How to hide empty ratings using Rate module?
I run a site that uses the Rate module on Drupal 7, using the 5 star rating. A lot of the items haven't got any ratings yet, so are displayed as 5 blank stars, which makes it look like they've got a score of 0 out of 5. Is there a way of only displaying a score if there is at least one rating?

# Answer
How would people rate the item the very first time if the widget is hidden?

Look in Rate module's template folder for rate-template-fivestar.tpl.php. Copy it over into your theme's template folder then make changes.

I think the variable $count might be available (Number of votes), so you could print out a message if $count is 0 to say that the item has not yet been rated.
> 0 votes

---
Tags: rating
---


title: field renders with 2 spaces

text:
# Question
Title: field renders with 2 spaces
In a template I'd like to get an html tag from a field:

```
<?php print '<' . render($content['field_headline_format']) . '>'; ?>

```

This should render or depending on the value of the field. But before the value it renders 2 spaces: \< h2\>.

I have no idea where it comes from.

# Answer
```
<?php print '<' . trim(render($content['field_headline_format'])) . '>'; ?>

```
> 0 votes

---
Tags: theming
---


# Question
Title: How can I execute a JavaScript function before the form submission handler is called?
I am trying to save an image using the following code.

```
function mymodule_user_page_form() {
  $form = array();

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Save',
    '#attributes' => array(
      'id' => 'myid_save',
    ),
    '#submit' => array('mymodule_save'),
  );

  return $form;
}

function mymodule_save($form, &$form_state) {
  $save = db_update('student',array('target' => 'import'))
    ->fields(array('id_status' => '1'))
    ->condition('stud-id', '101-03043', '=')
    ->execute();

  if ($save) {
    drupal_set_message("Successfully saved.");
  }
}

```

The JavaScript file contains the following code.

```
$('#myid_save').on('click', function(e) {
  myid_save_signature();
  myid_save_photo();
});

```

In my case, the JavaScript functions aren't called; the page refreshes before they are executed. I want to run those functions before `mymodule_save()` is called.

How can I achieve this?

# Answer
> 0 votes
Remove `#submit` from the form submission button.

```
$form['submit'] = array(
  '#type' => 'submit',
  '#value' => 'Save',
  '#attributes' => array(
    'id' => 'myid_save',
  ),
);

```

Your submission function should be `mymodule_user_page_form_submit()` rather than `mymodule_save()`. If form builder is `myform_form()`, the the submission handler is `myform_form_submit()`. It will be automatically invoked.

Now change the JavaScript code to the following.

```
$('#myid_save').on('click', function(e) {
  myid_save_signature();
  myid_save_photo();
  $('#myid_save').submit(); // Add this line
});

```

It will submit your form.

---
Tags: 7, forms, javascript
---


# Question
Title: How to move my site files outside the Drupal folder on local computer?
I like the Windows file structure that keeps program files separate from my data files. This allows me to organize my stuff logically by content and makes it easy to do regular backups of all of my stuff without needing to back up the program files, which are more easily replaced if necessary.

I have several websites that I've developed in ASP over the years and I keep the HTML, ASP, and other content files for each site in subfolders of a folder called "Web root". When I want to update a site, I first test the changes locally and then just FTP the modified files from the correct "Web root" subfolder to the online server.

Can this philosophy work for Drupal?

I'm now looking at revamping those sites in Drupal and I'd like to keep this separation of program and data files if I can. I've installed XAMPP and am getting ready to install Drupal. I've figured out how to move the MySQL "data" folder out of the MySQL folder and confirmed that the configuration works, so that's taken care of. Now the question is how to do the same thing with the site content files for Drupal.

What I want to do is keep the Drupal core along with downloaded modules and themes in XAMPP's "htdocs" folder where they're designed to go, but put content that I develop elsewhere outside the XAMPP folder. I think this means basically the contents of subfolders of the "sites" folder.

Can this be accomplished with configuration settings or symlinks or some other method?

I found the following related forum post that recommends symlinks:

but it only talks about putting the contents of the "files" folder elsewhere. I don't know Drupal enough yet to know if that's enough or if I need to be able to put other contents of "sites" subfolders elsewhere as well.

Can someone point me to information on how to do this?

Thank you.

# Answer
Yes you can separate files folder out of Drupal core installation. Follow these steps:

1. Go to `admin/config/media/file-system`
2. See public file system path, this needs to be relative to drupal installation. So if I want to make the files folder in parent folder of Drupal core installation, I need to give path like `../test_files`
3. Go to `admin/config/development/performance`
4. Clear cache and if you have aggregated css and Js, disable them, clear cache and again enable them.

This works
> 2 votes

---
Tags: files
---


# Question
Title: How to update/change anonymous author to authenticated current user upon logging in?
This is the case:

* Anonymous user can create nodes
* Anonymous user will leave their email address
* Anonymous user must register with the same email to "claim" the contents they created
* When that user logs in, the contents with anonymous author but same email address will update then the author will change from "anonymous" to current user.

I created a rule:

I've read some posts that I just need to add events on rules, there are no "AND" "OR" to events then rules will trigger that event but I noticed that it doesn't trigger the event "user logged in".

I tried testing this rule. changing **Action**, setting the value of author to ="1" ("admin") and removing **condition** of data comparison.

It does change the author to "admin" when saving new content either logged in or not.

When I saw that was working I returned the data comparison for the email.

Then If a user with the same email address logged in it does not change/update the author.

I tried placing the when user logged in first before the event after saving new content, as a result I wasn't able to use the \[node:etc\] on comparison and action. I also tried creating a rule with just one event = "User logged in". same result, I can't find the necessary token/arg I need.

Is there something wrong with my settings? Anyone here could point me to the right direction and steps?

Thank you very much!

# Answer
I used the updated Anonymous Publishing in the end.
> -1 votes

# Answer
Try using the trigger 'after saving a new user account'. You don't want to check for content every time they log in, just when they create an account that matches email addresses with those node.

For security purposes you should probably prevent people from being able to change their email address too or they might somehow steal someone else's content.

As for people who create content when they already have an account but are not logged in: create a rule that checks for accounts when a new node is saved. So in summary:

1. New users should claim existing content when the 'after saving a new user account' is triggered.
2. New content by existing users (that are not logged in) should be automatically claimed by the user account upon saving the node.

Neither of these events require you to check when a user logs in.
> 0 votes

---
Tags: rules
---


# Question
Title: New site appearing in folder structure after first hit on homepage?
This one has me scratching my head. I'm new to Drupal and am trying to restore a backup of a Drupal 7 site to a 3rd party hosting provider (hostgator as it happens.)

I purchased a business account and domain name to experiment with, and via their interface installed Drupal 7 in the `public_html/myaccount` subfolder.

I then restored the backup to that same folder. Beneath `myaccount` is the typical drupal file structure-- `includes`, `scripts`, `sites` etc.

Beneath the `sites` folder were subfolders `all` and `default`, exactly as restored from the backup and a typical Drupal structure. But that has changed.

When I browse to `www.myhostedsite.com/myaccount` I get an unstyled version of my site along with messages on the page that say things like: `Undefined index: highlighted in include() (line 126 of /home4/xyz/public_html/myaccount/modules/system/page.tpl.php).`

...and to my surprise, under the `sites` folder there's now a new folder with the name of the old site, with js and css subfolders beneath it.

How did *that* appear, and would anyone know what I may be doing wrong? I've noodled with .htaccess and settings.php values but am not sure I know what to look for in either location (though I did set the database connection correctly in settings.php, I'm pretty sure.)

# Answer
It would be good if you ask HostGator support guys to assist you through your problem. Got to Support and create a support ticket.
> 1 votes

---
Tags: installation
---


# Question
Title: Drupal 7 ckeditor relative path setup issue
We are developing a site using drupal 7 So we created drupal site with name of myapp, so the url is http://localhost/myapp

Also another developer is working for same site in his development machine with the name of myapp2 so its http://localhost/myapp2

I have installed ckeditor for rich content and configured relative path for inserting images.

When I insert an image in myapp site the relative path comes like 'myapp/sites/all/files/images/img1.jpg' instead of 'sites/all/files/images/img1.jpg'

hense when I share my database with my other team member uses myapp2 they are not able view the inserted images. their path looks like this 'myapp2/myapp/sites/all/files/images/img1.jpg'

I have used pathologic to setup the two users urls in Text Format setting page like http://localhost/myapp and http//localhost/myapp2 but not works as expected.

any one help me what else I can do to solve the issue.

# Answer
Finally I tried the solution found by searching various sites.

I put these two path items into text formats setting

```
http://localhost/myapp/
/myapp/
/

```

now its working. :)

So, since the other user who have myapp2 in his development system, there would chances for forming images path like myapp2/sites/..., hence we have to add more filter items like below

```
http://localhost/myapp2/
/myapp2/
/

```
> 0 votes

# Answer
Pathologic will solve your problem, in the configuration of the filter put both http://localhost/myapp & http://localhost/myapp2 and the filter should work everything out
> 0 votes

---
Tags: input-formats
---


title: Can't manage display for article

text:
# Question
Title: Can't manage display for article
I have done something and can no longer edit the manage display pages for the article content type . When I try to visit them I fall out of the usual rich html interface into a page whose code is attached below. I think that this is happening because I have accidentally damaged or removed the full content view mode for the article, but I am a newbie so I am really not sure. I was playing with Display Suite when this problem began.

Any ideas what is going on? and how to fix it? Thanks.

```
  <div id="branding" class="clearfix">
    <h2 class="element-invisible">You are here</h2><div class="breadcrumb"><a href="/drupal7/">Home</a> » <a href="/drupal7/?q=admin">Administration</a> » <a href="/drupal7/?q=admin/structure" title="Administer blocks, content types, menus, etc.">Structure</a> » <a href="/drupal7/?q=admin/structure/types" title="Manage content types, including default status, front page promotion, comment settings, etc.">Content types</a> » <a href="/drupal7/?q=admin/structure/types/manage/article">Article</a></div>              <h1 class="page-title">Article</h1>
        <div class="add-or-remove-shortcuts add-shortcut"><a href="/drupal7/?q=admin/config/user-interface/shortcut/shortcut-set-1/add-link-inline&link=admin/structure/types/manage/article/display&name=Article&destination=admin/structure/types/manage/article/display&token=sfNEjW3fhzg0KSwbxJKEEx_mwmWcqqCQjgxWGn5Q27A"><span class="icon"></span><span class="text">Add to <em class="placeholder">Default</em> shortcuts</span></a></div>    <h2 class="element-invisible">Primary tabs</h2><ul class="tabs primary"><li><a href="/drupal7/?q=admin/structure/types/manage/article">Edit</a></li>
<li><a href="/drupal7/?q=admin/structure/types/manage/article/fields">Manage fields</a></li>
<li class="active"><a href="/drupal7/?q=admin/structure/types/manage/article/display" class="active">Manage display<span class="element-invisible">(active tab)</span></a></li>
<li><a href="/drupal7/?q=admin/structure/types/manage/article/comment/fields">Comment fields</a></li>
<li><a href="/drupal7/?q=admin/structure/types/manage/article/comment/display">Comment display</a></li>
</ul>  </div>

  <div id="page">
          <div class="tabs-secondary clearfix"><ul class="tabs secondary"><h2 class="element-invisible">Secondary tabs</h2><ul class="tabs secondary"><li class="active"><a href="/drupal7/?q=admin/structure/types/manage/article/display" class="active">Default<span class="element-invisible">(active tab)</span></a></li>
<li><a href="/drupal7/?q=admin/structure/types/manage/article/display/teaser">Teaser</a></li>
</ul></ul></div>

    <div id="content" class="clearfix">
      <div class="element-invisible"><a id="main-content"></a></div>
                    <div id="help">
            <div class="region region-help">
    <div id="block-system-help" class="block block-system">

  <div class="content">
    <p>Content items can be displayed using different view modes: Teaser, Full content, Print, RSS, etc. <em>Teaser</em> is a short format that is typically used in lists of multiple content items. <em>Full content</em> is typically used when the content is displayed on its own page.</p><p>Here, you can define which fields are shown and hidden when <em class="placeholder">Article</em> content is displayed in each view mode, and define how the fields are displayed in each view mode.</p>
  </div>
</div>
  </div>
        </div>

```

# Answer
> 0 votes
Did you enable text format as Full Html.

In your html code there were two closing div are missed. here is the closing div added.

```
<div class="clearfix" id="branding">
    <h2 class="element-invisible">You are here</h2>

    <div class="breadcrumb"><a href="/drupal7/">Home</a> » <a href="/drupal7/?q=admin">Administration</a> » <a href="/drupal7/?q=admin/structure" title="Administer blocks, content types, menus, etc.">Structure</a> » <a href="/drupal7/?q=admin/structure/types" title="Manage content types, including default status, front page promotion, comment settings, etc.">Content types</a> » <a href="/drupal7/?q=admin/structure/types/manage/article">Article</a></div>

    <h1 class="page-title">Article</h1>

    <div class="add-or-remove-shortcuts add-shortcut"><a href="/drupal7/?q=admin/config/user-interface/shortcut/shortcut-set-1/add-link-inline&link=admin/structure/types/manage/article/display&name=Article&destination=admin/structure/types/manage/article/display&token=sfNEjW3fhzg0KSwbxJKEEx_mwmWcqqCQjgxWGn5Q27A"><span class="text">Add to <em class="placeholder">Default</em> shortcuts</span></a></div>

    <h2 class="element-invisible">Primary tabs</h2>

    <ul class="tabs primary">
        <li><a href="/drupal7/?q=admin/structure/types/manage/article">Edit</a></li>
        <li><a href="/drupal7/?q=admin/structure/types/manage/article/fields">Manage fields</a></li>
        <li class="active"><a class="active" href="/drupal7/?q=admin/structure/types/manage/article/display">Manage display<span class="element-invisible">(active tab)</span></a></li>
        <li><a href="/drupal7/?q=admin/structure/types/manage/article/comment/fields">Comment fields</a></li>
        <li><a href="/drupal7/?q=admin/structure/types/manage/article/comment/display">Comment display</a></li>
    </ul>
</div>

<div id="page">
    <div class="tabs-secondary clearfix">
        <h2 class="element-invisible">Secondary tabs</h2>

        <ul class="tabs secondary">
            <li>
                <ul class="tabs secondary">
                    <li class="active"><a class="active" href="/drupal7/?q=admin/structure/types/manage/article/display">Default<span class="element-invisible">(active tab)</span></a></li>
                    <li><a href="/drupal7/?q=admin/structure/types/manage/article/display/teaser">Teaser</a></li>
                </ul>
            </li>
        </ul>
    </div>

    <div class="clearfix" id="content">
        <div class="element-invisible"> </div>

        <div id="help">
            <div class="region region-help">
                <div class="block block-system" id="block-system-help">
                    <div class="content">
                        <p>Content items can be displayed using different view modes: Teaser, Full content, Print, RSS, etc. <em>Teaser</em> is a short format that is typically used in lists of multiple content items. <em>Full content</em> is typically used when the content is displayed on its own page.</p>

                        <p>Here, you can define which fields are shown and hidden when <em class="placeholder">Article</em> content is displayed in each view mode, and define how the fields are displayed in each view mode.</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

```

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


# Question
Title: how to get previous step values in next step in drupal multi step form?
How to get previous step values in drupal in the next step in a multiform. I want to display the values other than drupal\_set\_message(). I want to use these previous values in other function in the next step.

```
function form_example_wizard_previous_submit($form, &$form_state) {
  $current_step = &$form_state['step'];
  $form_state['step_information'][$current_step]['stored_values'] = $form_state['values'];
  if ($current_step > 1) {
    $current_step--;
    $form_state['values'] = $form_state['step_information'][$current_step]['stored_values'];
  }
  $form_state['rebuild'] = TRUE;
}

function form_example_wizard_next_submit($form, &$form_state) {

  $current_step = &$form_state['step'];

  $form_state['step_information'][$current_step]['stored_values'] = $form_state['values'];

  if ($current_step < count($form_state['step_information'])) {
    $current_step++;
    if (!empty($form_state['step_information'][$current_step]['stored_values'])) {
      $form_state['values'] = $form_state['step_information'][$current_step]['stored_values'];
    }
    else {
      $form_state['values'] = array();
    }

    // Force rebuild with next step.
    $form_state['rebuild'] = TRUE;
    return;
  }
}

function form_example_wizard_personal_info($form, &$form_state) {
   $form = array();
  $form['pagenumber']= array(
      '#title' =>t('Page Number'),
      '#type' => 'textfield',
      '#required' => TRUE
      );
  $form['wordscount']= array(
      '#title' =>t('Words count'),
      '#type' => 'textfield',
      '#required' => TRUE
      );
  $form['calcvalue'] = array('#type' => 'hidden',
  '#value'=>'test' );
  return $form;
}

function form_example_wizard_location_info($form, &$form_state) {
  $form = array();
  $form['quoteprice'] = array(
    '#type' => 'textfield',
    '#title' => t('Editing Your Document Will Cost'),
    '#value'=>$quoteval,
    '#required' => TRUE,
  );
  return $form;
}

```

# Answer
> 1 votes
There are so many ways to send data from one from to other.

1. You can use session
2. You can also pass value in url

Example of pass by value

```
function register_form_submit($form, &$form_state){
$name = $form_state['values']['name'];
$age = $form_state['values']['age'];

$data = array(
    'query' => array(
         'name' => $name,
         'age' => $age,
        )
    );

$form_state['redirect'] = array('/success', $data);
}

```

here is a link you can refer for send data

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

# Answer
> 0 votes
You need to set `$form_state['storage']` for this. Checkout the linked blog.

---
Tags: forms
---


# Question
Title: Can't create table when installing module
I have a simple 'form\_example' module and I want to add a database table when instaling module. I created this form\_example.install file:

```
<?php

function form_example_schema() {
    $schema['form_example_table'] = array(
        'description' => 'Table for form_pokus module',
        'fields' => array(
            'id'        => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
            'name'      => array('type' => 'varchar','length' => 30,     'not null' => TRUE, 'default' => ''),
            'gender'    => array('type' => 'varchar','length' => 30,     'not null' => TRUE, 'default' => ''),
            'message'   => array('type' => 'text', 'not null' => TRUE,   'default'  => ''),
            'status'    => array('type' => 'text', 'not null' => FALSE ),
            'created'   => array('type' => 'int',  'not null' => TRUE,   'default'  => 0),
        ),

        'primary key' => array('id'),

    );

    return $schema;
}

```

I disabled this module, then deleted it from directory, flushed all chaches and then installed and enabled again this module, now with .install file. But new table is not appearing in database. Im using PostgresSQL. What I am missing?

# Answer
> 0 votes
Follow the standard procedure to unisntall a module.

In short, once the module is disabled it may appear in the Uninstall tab of the modules page. Select the module in that tab and click 'Uninstall'.

When you disable a module its configuration and tables are kept, so if you enable again all data and configuration remains the same. When you uninstall a module you tell Drupal to wipe out any configuration and data by that module. When enabling it again Drupal detects that there's no configuration nor tables of that module and creates them again. If you only disable the module and enable it Drupal doesn't create configuration and tables because they should be in the database,m as Drupal knows module was enabled once.

In module list you have the available modules, some them enabled and some them disabled. If oyu want to comnpletely remove a module you have to disable, uninstall and delete the folder manually.

---
Tags: 7, installation, database
---


# Question
Title: Ajax http request terminated error while installing a Drupal 8 site
I have installed WAMP Server for Postgresql and during the time of installation of Drupal (version 8), I got this error:

> Drupal\Core\Config\UnmetDependenciesException: Configuration objects (block.block.bartik\_search, core.entity\_form\_display.node.article.default, core.entity\_form\_display.node.page.default, rdf.mapping.comment.comment, rdf.mapping.node.article, rdf.mapping.node.page, rdf.mapping.taxonomy\_term.tags) provided by standard have unmet dependencies in Drupal\Core\Config\UnmetDependenciesException::create() (line 89 of core\lib\Drupal\Core\Config\UnmetDependenciesException.php). Drupal\Core\Config\UnmetDependenciesException::create('standard', Array) Drupal\Core\Config\ConfigInstaller-\>checkConfigurationToInstall('module', 'standard') Drupal\Core\Extension\ModuleInstaller-\>install(Array, ) install\_install\_profile(Array) install\_run\_task(Array, Array) install\_run\_tasks(Array) install\_drupal(Object)

How can I solve this?

# Answer
The UnmetDependenciesException is something you get when Drupal tries to install a configuration that depends on other modules/configuration which are missing.

You shouldn't see this error installing one of the standard install profiles. My hunch is that the source to your errors is PostgreSQL which is not fully supported by Drupal 8 at this time of writing.

See more in the issue queue: https://www.drupal.org/node/2157455 for running Drupal 8 on postgreSQL.
> 1 votes

---
Tags: ajax, 8, installation
---


# Question
Title: Change CKEditor config.js without modifying module code?
I'm using the CKEditor module and I need to adjust config.js in the module's root. The problem is I don't want to make changes to any files part of the module because all those changes will get blasted when I do a code update.

How can I apply changes to CKEditor's config.js without modifying the module's copy of config.js?

# Answer
> 3 votes
Can you add the setting inside the *Custom JavaScript* configuration field of the *Advanced Options* for a particular profile?

There's also the ability to load your own custom config.js file in the 'Load ckeditor.config.js from the theme path' setting under the 'Advanced' section in the CKEditor profile settings.

# Answer
> 3 votes
Add a custom javascript to your theme/module with next content:

```
(function ($) {
  Drupal.behaviors.MYMODULE = {
    attach: function () {
      if (CKEDITOR !== undefined) {
        // Extend CKEDITOR.config here...
        // For example:
        CKEDITOR.config.wordcount = {
          showWordCount: true,
          showCharCount: true
        }
      }
    }
  }
}(jQuery));

```

# Answer
> 1 votes
Well, since you are not using the WYSIWYG module but the CKEditor module, you can put a ckeditor.plugin.js in your theme root dir.

You will then have to check the "**Load ckeditor.config.js from the theme path**" radio button in your module Advanced Options. It is located at /admin/config/content/ckeditor/edit/"Profile" and read:

> When enabled, the editor will try to load the ckeditor.config.js file from the theme directory.

You could also put string settings in the "Custom JavaScript configuration" UI area directly.

Edit: in short you could have accepted "geerlingguy" answer back then, I would have noticed it.

# Answer
> 0 votes
If you use the WYSIWYG module you can install CKEditor as a library and then it is separate from the module code.

**EDIT**: As Lester pointed out, this wont work out of the box, see my answer on his other post WYSIWYG CKEditor config.js not being used?

---
Tags: 7, wysiwyg
---


title: How does module_hook() function work?

text:
# Question
Title: How does module_hook() function work?
I need to check whether a hook is implemented in a module, so I chose `module_hook` function. In the documentation it states that the Return Value will be:

> TRUE if the module is both installed and enabled, and the hook is implemented in that module.

Now, I named a callback function (not a hook) in my module as **"`my_module_abc()`"**

*Note: my\_module is the name of my module.*

> If I test this function in `module_hook` like below:

```
module_hook('my_module', 'abc');

```

> It returns **TRUE**.

1. I thought It would return TRUE only for registered hooks and not for any function callbacks. Does `module_hook` know the difference between a function and a hook?
2. Is there any function like `hook_information($hook)` which returns information about a hook?

Is this right? Am I missing something?

# Answer
It's important to understand that a 'hook' is literally a function that's named in a certain way.

If you have a function

```
function my_module_abc() { }

```

That *is*, by the nature of the hook system, `my_module`'s implementation of `hook_abc()`.

Whether `hook_abc()` was ever *intended* to be a hook is a completely different matter. The fact that the hook system works entirely on a naming convention means that it's inevitable. In fact it's working exactly as designed.

Hooks are very loose, they are not structured; they don't have meta data, beyond what the module author may choose to document in MODULE.api.php. The 'information' you're looking for doesn't exist, and until someone changes the way Drupal's hook system works, it can't and won't.
> 3 votes

# Answer
`module_hook()` only uses `function_exists()` to check whether the named function is in the module or not. It doesn't check to see if that function is implementing a hook or not.

Looks like the intended purpose is to check whether a *known hook* is implemented in a module. If you use it for its purpose, it works fine.

If you use it for a purpose other than intended, results may vary. Granted they probably should call it `module_function()` instead.
> 2 votes

---
Tags: 7, hooks
---


# Question
Title: Can't insert data to database on form submit
I am trying to insert some datas into database table on form submit like this:

```
function form_example_submit($form, &$form_state) {

    if ($form_state['values']['select']=='1') $gender = 'male';
    else $gender = 'female';

    db_insert('form_example_table')->fields(array(
      'name'    => $form_state['values']['name'],
      'gender'  => $gender,
      'message' => $form_state['values']['message'],

    ))->execute();

    drupal_set_message("Message is successfully saved");

    return $form;

}

```

My schema in .install file looks like this:

```
function form_example_schema() {

    $schema['form_example_table'] = array(
        'description' => 'Table for form_pokus module',
        'fields' => array(
            'id'        => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
            'name'      => array('type' => 'varchar','length' => 30,     'not null' => TRUE, 'default' => ''),
            'gender'    => array('type' => 'varchar','length' => 30,     'not null' => TRUE, 'default' => ''),
            'message'   => array('type' => 'text', 'not null' => TRUE,   'default'  => ''),
            'status'    => array('type' => 'text', 'not null' => FALSE ),
            'created'   => array('type' => 'int',  'not null' => TRUE,   'default'  => 0),
        ),

        'primary key' => array('id'),

    );

    return $schema;
}

```

But nothing happens on form submit, only page is reloaded. What I am mising?

# Answer
> 0 votes
your schema

```
<?php
function form_example_schema() {

    $schema['form_example_table'] = array(
        'description' => 'Table for form_pokus module',
        'fields' => array(
            'id'        => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
            'name'      => array('type' => 'varchar','length' => 30,     'not null' => TRUE, 'default' => ''),
            'gender'    => array('type' => 'varchar','length' => 30,     'not null' => TRUE, 'default' => ''),
            'message'   => array('type' => 'text', 'not null' => TRUE,   'default'  => ''),
            'status'    => array('type' => 'text', 'not null' => FALSE ),
            'created'   => array('type' => 'int',  'not null' => TRUE,   'default'  => 0),
        ),

        'primary key' => array('id'),

    );

    return $schema;
}
?>

```

needs to look like:

```
function form_example_schema() {

    $schema['form_pokus_table'] = array(
        'description' => 'Table for form_pokus module',
        'fields' => array(
            'id'        => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
            'name'      => array('type' => 'varchar','length' => 30,     'not null' => TRUE, 'default' => ''),
            'gender'    => array('type' => 'varchar','length' => 30,     'not null' => TRUE, 'default' => ''),
            'message'   => array('type' => 'text', 'not null' => TRUE,   'default'  => ''),
            'status'    => array('type' => 'text', 'not null' => FALSE ),
            'created'   => array('type' => 'int',  'not null' => TRUE,   'default'  => 0),
        ),

        'primary key' => array('id'),

    );

    return $schema;
}

```

you had the wrong table name as the schema index.

# Answer
> 0 votes
The problem was that the proper hook name is not `form_example_submit` but `form_example_form_submit`.

---
Tags: database, forms
---


title: Problems with migration

text:
# Question
Title: Problems with migration
I'm using the modules Migrate and Drupal to Drupal Migration modules to migrate some Drupal 7 content to another Drupal 7 site.

It works very well for users and their pictures; the nodes are migrated too with all the fields but the image field.

What data should I use for *\[field\_product\_image:destination\_dir\]*, *\[field\_product\_image:destination\_file\]*, and *\[field\_product\_image:source\_dir\]*?

The image field is *field\_product\_image*. I have exported/imported the content types to the new Drupal 7 installation. The images are stored in *default/files/image/galerien*.

# Answer
Thanks very much Sumit Madan,

he gives me the solution:

Mapping:

for the file class of the image field enter this as "standard value": MigrateFileFid

set "TRUE" for preserve\_files of your image-field.

thanks again!
> 0 votes

---
Tags: 7, migrations
---


# Question
Title: How to define settings from an install profile
I am looking for the way to set some settings at the install step.

```
function genius_profile_final() {
  // Enable default permissions for system roles.
  $filtered_html_permission = filter_permission_name($filtered_html_format);
  user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content', 'access comments', $filtered_html_permission));
  user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access content', 'access comments', 'post comments', 'skip comment approval', $filtered_html_permission));

  // Create a default role for site administrators, with all available permissions assigned.
  $admin_role = new stdClass();
  $admin_role->name = 'administrator';
  $admin_role->weight = 2;
  user_role_save($admin_role);
  user_role_grant_permissions($admin_role->rid, array_keys(module_invoke_all('permission')));
  // Set this as the administrator role.
  variable_set('user_admin_role', $admin_role->rid);
  // Assign user 1 the "administrator" role.
  db_insert('users_roles')
    ->fields(array('uid' => 1, 'rid' => $admin_role->rid))
    ->execute();

  // Create a role for webmaster
  $webmaster_role = new stdClass();
  $webmaster_role->name = 'webmaster';
  $webmaster_role->weight = 3;
  user_role_save($webmaster_role);
  user_role_grant_permissions($webmaster_role->rid, array_keys(module_invoke_all('permission')));

  variable_set('taxonomy_menu_vocab_menu_rubric', 'menu-genius-navigation-menu');
  variable_set('taxonomy_menu_vocab_parent_rubric', 0);
  menu_rebuild();

  // Set the regional settings First day to Monday
  variable_set('date_first_day', 1);

  // The return message is optional, if you omit it the default will be used.
  return '<p>'. (drupal_set_message() ? t('Please review the messages above before continuing on to <a href="@url">your new Profile Name site</a>.', array('@url' => url(''))) : t('You may now visit <a href="@url">your new Profile Name site</a>.', array('@url' => url('')))) .'</p>';
}

```

In `genius_profile_final()`, where as I understood Drupal is fully bootstrapped, I have `variable_set('date_first_day', 1)`, but the first day of the week still is set to *Sunday*, after the installation. So it is not working as I expected.

I am using the taxonomy\_menu module, and I would like to set at the installation step the menu to be linked with the taxonomy. Because I am installing something known, I know the variable names that might be set are:

```
variable_set('taxonomy_menu_vocab_menu_rubric', 'menu-genius-navigation-menu');
variable_set('taxonomy_menu_vocab_parent_rubric', 0);

```

This is not working neither.

I have been following https://www.drupal.org/node/1022020 and looking at other examples but I have had no luck to find how to do this.

Is it possible to change settings in an install profile or are there any restriction? In that case, what restrictions are?

What am I doing wrong?

# Answer
> 3 votes
I can't find a hook called hook\_profile\_final on drupal.org. I also can't see where you found it on the link you're using (https://www.drupal.org/node/1022020). You are using an outdated version of the tutorial (https://www.drupal.org/node/67921).

You need to implement hook\_install\_tasks\_alter https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook\_install\_tasks\_alter/7 and change a task, or do a form alter of the config page.

# Answer
> 1 votes
Another solution would be to set the variables and other stuff in hook\_install() in your profile.install file. I'm doing this in different installation profiles to set admin theme, user roles, date settings and settings for contrib modules.

# Answer
> 0 votes
The easiest way is to use profile\_builder module and endorse the box variable! Reccomended: https://www.drupal.org/project/profiler\_builder

# Answer
> 0 votes
Please make sure that everything gets registered by calling

```
    drupal_flush_all_caches();

```

at the end of the profile. This will help having all data that you stored while final step.

Please have look at includes/install.core.inc line number 1561 to 1564 following will help you,

```
    // Flush all caches to ensure that any full bootstraps during the installer
    // do not leave stale cached data, and that any content types or other items
    // registered by the installation profile are registered correctly.
    drupal_flush_all_caches();

```

---
Tags: configuration, installation-profiles
---


# Question
Title: DRUPAL 7: insert images via URL instead of via "file-upload"
My boss asked me to edit an existing page (in which is already possible insert text and images) in order to be able to **insert images not only by uploading them from local pc but also via Remote URL**.

My version is **7.31** and is already installed "File Field Sources" module that SHOULD be the most useful to achieve desired behaviour.

My questions are:

1. After entered in Edit Mode of a specific page, how to verify which module is actually used to manage images uploads?
2. In case that it is already "File Field Sources", how to configure it to be able to put remote URL?

Thanks

# Answer
I guess you are having problem to use the module File Field Sources.

Use below steps

1. Download and install the module
2. Edit any image field, for ex. Article content type is having image field. Let's use this module over there.
3. Go to URL : `admin/structure/types/manage/article/fields`
4. Edit the field `field_image`
5. Check the option to use remote URL there. See screenshot.
6. Create article content and see there option to use remote URL in image field. See attachment.
> 1 votes

---
Tags: media
---


# Question
Title: How to display the same nodes with two different themes?
I have some content types normally displayed with the default theme of my site.

Now, I want to show such content types also in another section that is displayed with another theme and layout.

What is the best way to do it?

# Answer
> 0 votes
Yes simplest way to do it is using Themekey module. See the demo config for article type nodes.

---
Tags: 7, theming
---


# Question
Title: excluding non english field values from search_api index (or facet)
I have a CT `product` and a CT `factory`. Products have an entity reference field pointing to factories. I use node translation on factories (en, fr, de) but products are not translated (en only).

Creating facet on the product's factory (entity reference field) and indexing works well but the problem is that the facet displays all translated versions of factories. e.g:

```
china factory in english (14)
china factory in french (14)
china factory in german (14)
taiwan factory in english (6)
taiwan factory in french (6)
taiwan factory in german (6)
EU factory in english (2)
EU factory in french (2)
EU factory in german (2)

```

Since the search page regards products which are only in english, I'd like to be able to remove the `fr` and `de` values from that facet, or even better, not allow them to be indexed at all.

I've tried the `facetapi_bonus` module but its options for values exlusions doesn't suit me because I don't know the titles of the factories or their node ids beforehand.

# Answer
> 1 votes
I will venture a guess that when choosing indexed fields for the Product CT, you selected 'Factories' field and created the facet against this. Since you are using node translation, it is quite sensible that all available nodes (in various languages) are displayed in the facet. I suggest you try the following:

* Remove/disable field 'Factories' from the list of indexed fields and remove the respective facet
* At the bottom of the fields configuration for the index, you will find an option labeled 'Add related fields'. Choose field 'Factories'. With this action, all fields of the referenced Factory CT will become available for indexing
* Enable the field that is correlated with the translation source node. Label should be something like this 'Factories \>\> Translation source node'. Create a new facet against this field
* Clear indexed data and re-index

Most probably, the new facet will only display the facet terms in the default translation language (English in your case)

---
Tags: i18n-l10n, search
---


# Question
Title: Display a Block for mobile only without creating new theme
I'm trying to display a main navigation menu block but ONLY for the site when it's viewed on a mobile. I need to do this without creating a new theme to do so though so it all works on 1 theme only.

Any ideas how this can be done?

Thanks

# Answer
Take a look at the Browscap Block module. Here is a quote about it (from the module's project page):

> ... adds visibility options to block configuration settings to allow you hide or show blocks in mobile devices.
>
> If you are looking for the same thing for Panel panes check out Browscap CTools.
> 5 votes

# Answer
You could try CSS and media queries.

* Enable the block through the blocks admin page
* In your theme's default stylesheet, hide the block by default using `display: none;`

**Option 1:**

* Use media queries in your theme's main stylesheet to hide/display the block (see bottom of article/article snippet in answer)

OR

**Option 2:**

* Create another CSS file (ex. mobile.css) in your theme and add rules to show the block
* Use media queries in your theme's .info file to determine to use the mobile stylesheet

To learn more about media queries in Drupal, see Media queries & Drupal.

From the article:

> To define a CSS file in your Drupal theme's info file you would usually write declarations such as
>
> ```
> stylesheets[all][] = style.css
>
> ```
>
> or
>
> ```
> stylesheets[screen][] = style.css
>
> ```
>
> etc.
>
> To use media queries you can write declarations such as
>
> ```
> stylesheets[screen and (max-width: 600px)][] = screen-600.css
>
> ```
>
> or
>
> ```
> stylesheets[screen and (orientation:landscape)][] = screen-landscape.css
>
> ```
>
> You can also define media queries within your CSS file.
>
> ```
> @media screen and (max-device-width: 600px) {
>
> }
>
> ```
> 2 votes

# Answer
You can try the ThemeKey module.

Also check out the Context module.
> 0 votes

# Answer
I found a difficulty of using CSS to exclude blocks due to the very similar css output for each block. I found that the block\_class module works very nicely in this case. I just place a css class for that block, and then I can modify my css code in my css files. The block\_class module can be found here: https://www.drupal.org/project/block\_class
> 0 votes

# Answer
I use this code to hide blocks in mobile view and it works perfectly. past this code in your page.tpl.php file and add ID hidden to the block or in my case adsenese Ad unit.

```
<script type="text/javascript">

jQuery(document).ready(function($){

if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
 $("#hide").css("display", "none");
 }
});
</script>

```
> 0 votes

# Answer
You don't really need to load the block and hide that with css. Loading a block will be overkill for page. Use the Context Breakpoint module instead (for D7, currently in Beta3).
> 0 votes

# Answer
I've solved this myself. I used a combination of Context module and Mobile Tools module. From here, the context for mobile device is available where i select 'Mobile'. Then i set a reaction for the Blocks and then can select blocks to show just for mobile.
> -1 votes

---
Tags: blocks, theming
---


# Question
Title: Use contextual filter value in a view's header "rendered entity"
I want to render a Taxonomy term in a Header for a Page view which uses the Taxonomy term as a Contextual filter. I found that I can add an Entity: Rendered entity to the Header of a View, which I can set to display a Taxonomy term, but it needs an Entity ID, and I don't know how to reference the Contextual filter value.

I suppose I can use a Global: PHP or Global: View in the header to achieve this otherwise, but I wanted to know whether I can use the Rendered entity to do this.

# Answer
> 1 votes
It looks like this isn't currently possible. There's a feature request on d.o to make this work. You can achieve it with Views PHP as you mentioned by using the following code:

```
<?php
$entity_type = 'taxonomy_term';
$id_arg = 1;
$view_mode = 'full';

if ($entity_id = $view->args[$id_arg - 1]) {
  $entity = entity_metadata_wrapper($entity_type, $entity_id);

  // Rendering without title ($page = TRUE).
  $render = $entity->view($view_mode, NULL, TRUE);

  // You may need to unset the title, even when rendering without it.
  $render[$entity_type][$entity_id]['#term']->name = NULL;
  print drupal_render($render);
}
?>

```

Note: this code requires the `entity` module. Shouldn't be hard to port it to native Drupal code, but `entity` is rather widespread.

---
Tags: views
---


title: Why views retrieves results one by one

text:
# Question
Title: Why views retrieves results one by one
I'm actually trying get the count of total rows retrieved by view. When I added `count($row)` in `Global:PHP` of views field it returned `1`. That also ten times, Means query executed 10 times to retrieve 10 row of data. When I printed the query with `dpq($view->build_info['query']);` it returned same query 10 times. How can I avoid multiple execution of same query.

# Answer
> 0 votes
You can list the number of results instead with a snippet of php code in the header:

```
<?php
  $view = views_get_current_view();
  print $view->total_rows;
?>

```

Learned this trick from: https://stackoverflow.com/a/2989197

# Answer
> 0 votes
You can also achieve it by taking the number of records in the view. For that you can use the **Global: Result summary** in that you have @total -- the total records in the set. You can use this. I don't know whether this answer meets your need. Just give a try:)

---
Tags: views
---


title: Group sub sub theme CSS separately

text:
# Question
Title: Group sub sub theme CSS separately
I have a base, sub theme, and sub sub theme. I don't want the sub sub themes CSS to be grouped to CSS\_THEME due to support for legacy IE browsers and the issues associated with large CSS files.

```
$value['group'] = 100 = CSS_THEME = (Theme-Layer CSS)
$value['group'] = 0 = CSS_DEFAULT = (Module-Layer CSS)
$value['group'] = -100 = CSS_SYSTEM = (System-Layer CSS)

```

Possible to add to this with a different weighting?

```
$value['group'] = 200 = CSS_SUB_THEME = (Sub Theme-Layer CSS)

```

Adding CSS to separate group.

```
  // Add sub sub theme css to separate group.
  drupal_add_css(PATH_TO_THEME/sub_sub_theme.css',
    array(
      'group' => CSS_SUB_THEME,
    )
  );

```

NOTE: not looking for related answers to legacy IE browser limitations as solutions such as css\_splitter are already in place, simply can the above be done or is there a good reason you can't.

# Answer
> -1 votes
May not be the answer you're looking for but have you considered Advanced CSS/JS Aggregation as one of the features is "Prevent more than 4095 CSS selectors in an aggregated CSS file (IE 6-9 limitation)"

---
Tags: 7
---


# Question
Title: How can I save/load an entity from a different database?
For a custom Drupal 8 module I am integrating data from a separate database (other than the default drupal database) by defining a new Drupal entity in my module.

How can I configure my Entity class (or an EntityStorage class?!) to get the data of this entity from a different database? Can I change the injected (?) Database Connection object from which the entity is queried?

My question is similar to Drupal entity from different database dealing with Drupal 7. However, I think Drupal 8 has some different approaches.

Note: This other database is currently running on the same server.

# Answer
At least if the "external" database is on the same server, there is an easy solution. The `base_table` of an entity can refer to a different database using `.` as a separator.

Just adapt the EntityType annotation in the comment above your Entity class. The following example uses the table `myentity_table` from the `my_database` database for this Entity's data:

```
@ContentEntityType(
 *   id = "myentity",
 *   base_table = "my_database.myentity_table",
 *   [...]
 * )

```
> 5 votes

---
Tags: entities, 8, database
---


# Question
Title: Replace field label in content type template
I'm outputting fields in a template for my content type like so:

```
print render($content['group_details']['field_city']);

```

However, I would like to replace the default label that is attached to the 'city' field. I cannot alter the label in Drupal's content type so I'd really need to do so directly in the template. How can I instruct Drupal to hide the current label and replace it with a custom label in the content type template?

# Answer
> 1 votes
OK it's a bit round the houses, but you should be able to do:

```
$content['group_details']['field_city']['#label_display'] = 'hidden';
print '<h2>Title</h2>'; // change to any HTML
print render($content['group_details']['field_city']);

```

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


# Question
Title: Is there a module for automatic menu translation?
I need to automatically translate menu items into all enabled languages when created. Is there a module for that or how can I do it programmatically ?

# Answer
**Short answer**: no

**Long answer**: I wouldn't recommend to try to 'automatically translate' any of your content – especially not translating the navigation while keeping the content in the original language. You will probably rather quickly have lots of frustrated users (or no users at all) that don't find content in *their* language, even when they are '*clicking the right link*'.

Additionally you will probably be penalized by search engines for duplicate content.

Maybe you should ask over at the ux forum what people think of the idea? I suppose hardly anybody would recommend to have that type of mis-leading navigation structure on a website.

There are however various modules to tranlate menues (and fields and taxonomies etc.) on the fly, while you are creating new content items – but that you probably already know – and that's probably not what you were looking for.
> 0 votes

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


# Question
Title: how to get user name in a view instead of uid
I have a drupal 7 website that uses a view to show the content. The Content UID shows as a field I can display, but I want to display the username instead. It says "The user authoring the content. If you need more fields than the uid add the content: author relationship" , which I don't understand . Where do I add the content author relationship? thank you,

# Answer
> 8 votes
it's in the advanced configuration (click on add relationship):

search and select the uid field (this applies also for entity references for instance)

add a new field to the output, select User: name

select the relationship you created earlier (you can have multiple relationships, e.g. if you have multiple entity references)

# Answer
> 0 votes
* Clicked on Advanced in the view
* Clicked on Relationships -Clicked on add
* clicked Content:author
    + clicked no relationship -now in fields theauthor shows up as an field I can add.

---
Tags: views
---


title: How to set count in "bundled" product?

text:
# Question
Title: How to set count in "bundled" product?
I have created a content type called "product". On this product, I need to create a "entity reference" field to other products, should this product be a bundled product.

For example, I might create a "Playstation 4" product, but add "Call of Duty" as a FREE bundled addon item. I want to then be able to specify the number of these "sub products" are applicable. For example, if you buy the playstation, I might have it come bundled with 2 copies of the exact same Call of Duty. So I need to be able to specify that all though Call of Duty is the bundled product, two of them are relevant.

How do I do that with Drupal, without using entity nodes (as they are very slow in practice)?

# Answer
> 1 votes
A solution that comes to mind is using the field collection module to create a collection with a quantity and entity reference field. I've not used that module with Drupal Commerce so there might be a more commerce-centric solution there.

---
Tags: entities
---


# Question
Title: Anyone know how to build a menu like this?
We are redesigning a site for a client and they're wanting to create a menu similar to the one found here (the big menu below the header, ***not*** the hamburger menu at the top left):

http://www.business.vic.gov.au/

Looks like it may have been built from scratch w/ jQ but thought someone might know of an existing module or theme that could get us started in the right direction. Appreciate any advice or help.

Thanks!

# Answer
> 0 votes
Welcome to stackexchange. When asking a question **please** try to be as specific in your question as possible. Try describing what you want to know – also using screenshots or wireframes is ok – but please avoid forcing others to ckick on a link to understand your question. Questions like "How can I do `<link>`*this*`</link>`?" are usually not very likely to get a lot of attention from the community.

That said – I did click the link – and I suppose whether there is a module providing this effect/functionality or not is probably not that important since you could achieve a fairly similar effect with either a drupal menu or a drupal view **and** some javascript / jquery / ajax (for loading the second level dynamically) and some additional css3 for the sliding effect.

You could probably even skip the scripting part, display a standard list of links, hide the non-active second level items and use css3 to slide the second level in once it's needed. Asking ofer at stackexchange might be the more suitable forum to ask about this (here is for example everything about 'slidetoggle').

I'm sorry this is probably not the answer you were looking for – but maybe if you provide more information on what you want to achieve someone else can point you to an appropriate module.

---
Tags: theming, routes, javascript
---


title: How to get node IDs from drupal.org?

text:
# Question
Title: How to get node IDs from drupal.org?
In Drupal, we can get argument values using `arg()` function. drupal.org uses path alias. For example https://www.drupal.org/project/elysia\_cron is actually https://www.drupal.org/node/274365, the node with ID equal to 274365.

How can I get the node ID of a project page from drupal.org?

# Answer
> 2 votes
As already mentioned in the comments, you *could* parse the HTML from the web page and extract the node ID from a class value.

But that's very messy, and it'll break if Drupal.org changes its markup for node pages.

A more robust approach would be to use the API, and consume the project's update feed. That feed contains the raw URL of the project node, from which you can get the ID.

I'll leave the PHP implementation to you, but the steps are as simple as:

I realise that method also relies on the XML not being changed, but I think that's less likely to change than the markup on the HTML version.

# Answer
> 0 votes
You can use PHP Simple HTML DOM Parser

Following is a sample code I wrote that you can use in drupal/php

```
include_once 'simple_html_dom.php';
$html = file_get_html('https://www.drupal.org/project/elysia_cron');
$real_link = '';
foreach($html->find('link') as $element) {
    $real_link = $element->href;
    break;
}
echo $real_link;

```

This will give your the full link with node ID. Hope you can filter out the ID.

---
Tags: path-aliases, community-official-site
---


# Question
Title: Feature with Content Types is not reverted
I am stuck watching the Feature state as Overriden. I tried different solutions as:

* Disable and re-enable the feature
* Restart apache to ensure the APC cache is cleared
* Clear All caches from Drupal administration

But I get stcuk with the overriden state.

Doing a Diff within the Diff module, I see the following differences:

But if I check the current feature code the Line 732 doesn't seems to be the same as the Diff module is detecting.

So I don't understand where is the difference.

I do the revert of the feature, clear cache, ... several times, and the Feature is always on Overriden state.

Please, any idea to discover the reason why I can't do the revert and a solution to perform the revert?

# Answer
Please check whether there are two copies mistakenly placed inside drupal modules. Just recreate the feature with a new name and a version number. Download new feature then disable current feature and remove module completely from source. Then make sure the feature is completely removed and not appearing in the module list. Then add new feature and see.
> 1 votes

---
Tags: features
---


# Question
Title: How do I attach a link or image to a radio/select input element
I want to attach an image-link to every input element. Is it possible to do it on entity fields or on webform fields? I prefer to it on server side.

# Answer
> 1 votes
ok, so then you need two parts both stored in a custom module:

1. an admin interface where the client can upload images for each relevant form element. Use drupal\_get\_form('FORM\_ID') and loop through the form elements. Create a new admin form with image form elements corresponding to the webform elements. save the images and create a mapping table mapping the image urls to the form elements.
2. an invokation of hook\_form\_alter() adding prefixes to the webform elements as stored in your mapping table.

# Answer
> 1 votes
The Webform Select Image module does exactly what you want to do. Here is a quote from the modules project page:

> The purpose of this module is to add an images select component for webform (checkboxes or radios buttons).

# Answer
> 0 votes
For now I decided to use Webform Options Markup Component module even it's kind of hacking.

---
Tags: webforms, input-formats
---


# Question
Title: ApacheSolr - No Documents or Data in Index
For reasons unknown to me, Apache Solr isn't indexing any of the Articles that I create.

I have about 10 articles, just for testing, and Solr tells me that no documents have been indexed, nor have any documents been sent to the server for indexing.

I've tried reinstalling everything and deleting the Solr & Search Index to no avail.

What am I doing wrong?

# Answer
> 0 votes
Fixed the problem by reinstalling Solr. I might have missed something along the way the first time.

As for the original issue, I have no idea, but I'm considering this solved.

---
Tags: 7, search
---


# Question
Title: Using Drupal's session inside a PHP script
I need to pass parameters from a Drupal page to a PHP script. There's no way to pass that directly and I need to use SESSIONS. I've searched around and added this at the top of the script:

```
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);

```

With that I can use Drupal's session but I'm getting this error:

```
Warning: session_start(): Cannot send session cache limiter - headers already sent

```

It's not so bad since it's just a warning and I can use CSS to make it not visible to the user. But I was wondering if there is a cleaner way to do so.

# Answer
> 1 votes
In instances where I've had to do things like this I've done the following. It's worked for D6/D7 without any warnings for me.

```
  $current_path = getcwd(); //Current app path

  //Remove any HTTP headers/output
  header_remove();
  ob_clean();

  //Bootstrap Drupal w/ dir change
  //$drupal_root being the root Drupal install path
  define('DRUPAL_ROOT', $drupal_root);
  chdir($drupal_root);
  require_once "$drupal_root/includes/bootstrap.inc";

  /*Execute Code Dependant on Drupal Environment */

  chdir($current_path); //Return to existing app path

```

# Answer
> 0 votes
Verify that you do not print anything to the output buffer (with functions like echo or print) before setting/defining headers (with functions like header)

---
Tags: sessions
---


# Question
Title: How to make a page the home page of another domain
I have some pages with urls like this:

```
http://example.com/landing/abcd
http://example.com/landing/efgh

```

as menu items:

```
    $items['landing/%'] = array(
        'title' => 'Landing page',
        'description' => 'Landing page',
        'page callback' => 'mymodule_landing_display',
        'page arguments' => array(1),
        'access arguments' => array('access content'),
        'type' => MENU_NORMAL_ITEM,
    );

```

Now i want to use them as the home page of the domains:

```
http://abcd.com/
http://efgh.com/

```

I don't want to use a simple redirect.

What is the best way to do it ?

# Answer
Use Domain Access: https://www.drupal.org/project/domain

Core Drupal + Domain Access can do this, you don't need any code or custom modules. Your Drupal can load different content on each configured domain name.

1. Point all domains in Apache/Nginx at the same Drupal install directory.
2. Install Drupal using your primary domain.
3. Create your Landing Page nodes using the default Page Content Type.
4. Install Domain Access.
5. Add a new Domain at: http://example.com/admin/structure/domain/create
6. Edit the Domain settings at: http://example.com/admin/structure/domain/view/:id/config and specify the *Site frontpage*.
7. Done.

If you want it in code, you can export the entire configuration with the Features module: https://www.drupal.org/project/features
> 2 votes

# Answer
If you actually just want to use these pages as one-pager / landing-pages (as the url 'landing' suggests) it could also be done by adjusting your domain settings for `abcd.com` and `efgh.com`.

At least with my webhost I can adjust where a domain would look for its content. Setting the 'home' path to `/landing/abcd` (or actually seting the 'A-entry' of the dns registry accordingly) would do the trick on the server I'm working on – at least when all three domains share the same webspace.

So you might also consider asking your question over at stackoverflow.com or webmasters.stackexchange.com since it could be a more technical question.
> 1 votes

# Answer
If you need to accomplish this with a custom module instead of following Shawn Conn's suggestion of a multisite setup, you can do something along the lines of adding a menu handler whose callback will examine the http host that the request came in on and pass that along to your `mymodule_landing_display` function. Then set this new menu item's path to site\_frontpage using the "Default front page" setting on `admin/config/system/site-information`. Something like this:

Item for hook\_menu:

```
$items['landing'] = array(
  'title' => 'Landing page chooser',
  'description' => 'Landing page chooser',
  'page callback' => 'mymodule_landing_display_chooser',
  'access arguments' => array('access content'),
  'type' => MENU_CALLBACK,
);

```

Callback function:

```
function mymodule_landing_display_chooser() {
  $choice = str_replace('.com', '', $_SERVER['HTTP_HOST']);
  if($choice == 'example') {
    // If this is the main 'example.com' domain, use default front-page content, or change this to whatever content you want to deliver for your main domain
    return node_page_default();
  }
  else {
    return mymodule_landing_display($choice);
  }
}

```
> 0 votes

---
Tags: 7, multi-sites
---


title: Move drupal site from web to local host

text:
# Question
Title: Move drupal site from web to local host
I have a site that's already on the host. So what I want to do is to put in on my PC , and so I could edit it. I have already installed WAMP and download a backup with the site from the host, and downloaded the DB from the host also.

What I have to do next?

# Answer
> 1 votes
1. Put your project in WAMP's www folder.
2. Start wamp and make sure both aparche and mySQL is up and running
3. Go to phpmyadmin http://localhost/phpmyadmin
4. Create a new database and import your database backup
5. Go to wamp/www/\[your project folder\]/sites/default and edit settings.php file.
6. Set database connection and $baseurl in settings.php file.
7. Go to http://localhost/\[your project folder\]

# Answer
> 0 votes
Now, you need to add your DB credentials on your local environment to MySQL. Using phpmyadmin is the easier way to that. After that you would have to pull all your website files in the wamp root directory.

Once you import the database and have the files in the root directory you can visit your website at localhost on any browser.

# Answer
> 0 votes
Double check that your permissions for your files and folders are accessible by your wamp server. I always forget that step.

---
Tags: backups
---


# Question
Title: Sending client to channel messages with nodejs integration
I've been struggling with this for some weeks now and so far I have not found a proper solution yet. I guess this is a bug, but since there is no response on nodejs issue queue I'd like to ask this question here as well. (Drupal.org issue)

**The situation:**

I am working on a conference plugin using webRTC, where the initial handshake is done using Nodejs integration module. (Needed Nodejs for some other applications as well so I thought this would be the best way.) There is some documentation on how to send messages from *client \> node server \> backend (\> other clients)*. However for my handshake it has no added value to use the Drupal backend, so I want messages to go *client \> node server \> channel*.

The Nodejs integration module has settings for allowing clients to write to channels and in fact the messages arrive on the server, the server sends them to the connected clients and the clients reject the messages.

**The idea:**

I've tracked it down to the following piece of client side javascript in the nodejs module, where both `message.clientSocketId` and `Drupal.Nodejs.socket.sessionid` are undefined (thus equal) and the callback is left.

```
Drupal.Nodejs.runCallbacks = function (message) {
  // It's possible that this message originated from an ajax request from the
  // client associated with this socket.
  if (message.clientSocketId == Drupal.Nodejs.socket.sessionid) {
    return;
  }
  ...
}

```

Is there somebody who managed to get *client \> node server \> channel* communication using only JavaScript? Did I miss an authentication step somewhere?

Commenting out the return statement does work, but then clients respond to their own messages, leading to undesired behavior.

# Answer
I can no longer reproduce this. Since the module did not update in the meantime I guess it a new version of socket.io that got updated via npm update.

The posts here have been of great help in further development of the functionality: http://theoleschool.com/tags/nodejs
> 0 votes

---
Tags: 7, javascript
---


# Question
Title: Drupal 7 module recommendations for mailman listserv?
From what I've seen the only mailman integration module is Mailman Manager which is only D6.

Does anyone know of another module or any other tool that I could use to implement the same functionality for D7? I.e.:

* administer the lists
* allow users to subscribe
* unsubscribe
* etc ...

# Answer
you can try http://www.drupal.org/project/simplenews .. i personally use mailchimp with the drupal mail chimp module drupal.
> 0 votes

# Answer
As of Jul 19, 2013, there is a 7.x-1.0-RC1 release of the module in the questionavailable. As of today, it seems to be used (= reported installs) in 28 D7 sites, which is about 11% of the total number of sites (255).

In its issue queue there are 3, out of 71 issues related to D7 ... 1 specific one is issue # 2043971.

That makes me wonder if it's yes or no worth giving that RC1 version a try these days ...
> 0 votes

---
Tags: 7
---


# Question
Title: D6 to D7: How can I get all the migrated content to have the "Text format" of "Full HTML" for the body
I am migrating content using both the migrate, migrate\_d2d and my own custom module which references the 2 migrate modules. The below code successfully migrates content from Drupal 6 to Drupal 7 when registering and running the migration of "PressMigration" within the .module file but I always want the Drupal 7 migrated content body area to have the "Text format" of "Full HTML". How can I get all the migrated content to have the "Text format" of "Full HTML" for the body.

Thanks,

## John

```
class PressMigration extends DrupalNode6Migration {

  protected function query() {
    $query = parent::query();
    //Only include specific nodes in migrationj
    $query->addJoin('LEFT OUTER', 'term_node', 'tn', 'n.vid=tn.vid');
    $query->addField('tn', 'tid', 'tn.tid');
    $query->addField('tn', 'vid', 'tn.vid');
    $query->condition('tn.tid', '115', '=');
    return $query;
  }

  public function __construct(array $arguments) {
    parent::__construct($arguments);

    $this->addFieldMapping('field_release_date', 'field_release_date');
    $this->addFieldMapping('field_contact', 'field_contact_information');

    $this->addFieldMapping('field_subtitle', 'field_sub_title');
    $this->addFieldMapping('field_teaser', 'field_media_excerpt');
    $this->addFieldMapping('field_custom_title', 'field_custom_title');

    $this->addFieldMapping('field_alt_lang', 'field_alternate_lang');
    $this->addFieldMapping('field_related_item', 'field_media_related');
    $this->addFieldMapping('field_archiving_date', 'field_archive_date');
  }

}

```

# Answer
When we migrated from Drupal 6 to Drupal 7 we used a format\_mapping like this so that everything became filtered\_html:

```
'format_mappings' => array(
               '1' => 'filtered_html', // Filtered HTML
               '2' => 'filtered_html', // PHP code
               '3' => 'filtered_html', // Full HTML
               ),

```

The comments above show the Drupal 6 names we had for the numeric format codes. `format_mappings` is an element of the arguments passed to the registerMigration() method, such as:

```
Migration::registerMigration('FooMigration', $arguments['machine_name'], $arguments);

```
> 2 votes

# Answer
You should try to set the input format on the body field in this way:

```
$this->addFieldMapping('body', 'body')
 ->arguments(array('format' => 'full_html'));

```
> 2 votes

# Answer
It is recommended to use the module Drupal-to-Drupal data migration: migrate\_d2d.

There you can map your legacy filters to the destination filters, by passing a format\_mappings argument when registering the node migration, as described in the issue *Set text filter for migrations*. Note that before Drupal 7 an integer value was used instead of machine names.

```
$arguments = array(
  'source_connection' => 'legacy',
  'source_version' => 6,
  'description' => t('Migration of core blog nodes from Drupal 6 to custom blog nodes'),
  'machine_name' => 'ExBlog',
  'source_type' => 'blog',
  'destination_type' => 'custom_blog_type',
  'user_migration' => 'ExUser',  // Machine name of our user migration above
  'format_mappings' => array(
    '1' => 'filtered_html',
    '2' => 'full_html',
    '3' => 'plain_text',
  ),
);
Migration::registerMigration('DrupalNode6Migration', $arguments['machine_name'], $arguments);

```
> 1 votes

# Answer
In the past I've succesfully used the abstract Node migration class (the first code block) here: https://drupal.org/node/1513766.

It assumes the default migration module (I didn't use migrate\_d2d so I don't know about compatibility).

This part that matches the D6 numeric notation to the D7 string notation worked for me.

```
public function prepareRow($current_row) {
  $formats = array(
    '1' => 'filtered_html',
    '2' => 'full_html',
    '3' => 'plain_text',
    '4' => 'markdown',
  );
  $current_row->format = isset($formats[$current_row->format]) ? $formats[$current_row->format] : 'plain_text';
}

```

Since you want all nodes to be Full HTML, I'd say adding the following should work.

```
public function prepareRow($current_row) {
  $current_row->format = 'full_html';
}

```
> 0 votes

# Answer
This one worked for me for every field:

```
$node_options = MigrateDestinationNode::options(LANGUAGE_NONE, 'filtered_html');
$this->destination = new MigrateDestinationNode('node', $node_options);

```
> 0 votes

# Answer
The field mapping arguments() method is now deprecated - please use subfield notation instead.

-\> You can also set the textformat for the whole destination:

```
$this->destination = new MigrateDestinationNode('lexiconentry',array('text_format' => 'full_html'));

```
> 0 votes

---
Tags: migrations
---


title: Date picker field

text:
# Question
Title: Date picker field
I'm using Drupal 7 and Clean theme.

Can i add date picker in content type field?

Searched about this but i not found any solution.

Users, when click date field, come date picker. Is it possible?

# Answer
The Date module has a submodule called "Date Popup" which provides a jQuery UI popup widget for fields.

Just install that module, add a new field to your content type, and when choosing the widget select "Pop-up calendar":
> 4 votes

# Answer
If you want to do it with code it would look something like this.

The callback

```
function callback($date){

  drupal_add_library('system', 'ui.datepicker');
  drupal_add_js("(function ($) { $('.datepicker').datepicker(); })(jQuery);", array('type' => 'inline', 'scope' => 'footer', 'weight' => 5));

  return theme('my_theme');
}

```

The template

```
<input type="text" class="datepicker" name="renewaldate" />

```
> 0 votes

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


# Question
Title: Add 'Last modified by ...' footer to each page
How do I add a footer to each page generated by Drupal (7) so to show the identity of the last user that modified that page? (together with the modification date)

# Answer
I think you should be able to do this with something like this, note that this is only pseduo code and is not tested:

```
 // get the user that made the latest modification
 // for a node of type 'page'
 function getLatestPageUpdater() {
     $query = "SELECT n.changed, u.* FROM node n
               INNER JOIN users u ON u.uid = n.uid
               WHERE n.type = 'page'
               ORDER BY changed DESC
               LIMIT 1";
     return db_query($query)->fetch();
 }

```

Then in your `page.tpl.php` you could do like this:

```
 <?php $user = getLatestPageUpdater();
       if($user):
 ?>
 <p>Last edited <?php print $user->changed; ?> by <?php print $user->name; ?></p>
 <?php endif; ?>

```

Like @tostinni pointed out Drupal doesn't track the last editor of a node, so the above code would always display the original author of the node. If you're using node revisions I think you should be able to do something like this (again this is only pseudo code and is not tested):

```
function getLatestPageUpdater($node) {
  $query = "SELECT u.name
            FROM node_revisions nr, users u
            WHERE nr.uid = u.uid
            AND nr.nid = ".$node->nid."
            ORDER BY timestamp DESC
            LIMIT 1";
  return db_query($query)->fetch();
}

<?php if($node->type == "page"): ?>
<?php $user = getLatestPageUpdater($node);
      if($user):
?>
<p>Last edited <?php print $node->changed; ?> by <?php print $user->name; ?></p>
<?php endif; ?>
<?php endif; ?>

```
> 0 votes

# Answer
I've written a *Last Modification* Date module for drupal that does exactly that.

ATM this is still a sandbox project, but it is in approval state.

It just creates a block that spits out the last modification date of any node in the system. There is no database polling, saving of that date is done *at node save time*. So no overhead.
> 0 votes

---
Tags: 7, nodes
---


# Question
Title: How to active payment pane in Commerce Kickstart?
I am using Commerce Kickstart and I am trying to configure the checkout process.

But control is not going in payment module. Instead it's going in last step directly.

Can anybody help me find out what is wrong?

# Answer
> 0 votes
I think you are looking for Commerce Checkout Pane Payment or Commerce Checkout Pages.

```
Commerce Checkout Pane Payment Module Feature:

```

This module creates a Checkout Pane that shows the selected payment method on the review page of the checkout. This is a contrib module for Drupal Commerce. Drupal Commerce Contrib. This module creates a Checkout Pane that shows the selected payment method on the review page of the checkout.

```
Commerce Checkout Pages Module Feature:

```

Commerce Checkout Paages gives site administrators the ability to create additional pages for the checkout process through the admin user interface.

---
Tags: commerce
---


title: unsetting css is not working

text:
# Question
Title: unsetting css is not working
I am trying to unsetting the deafult CSS through a foreach loop, but seems its not working in

```
hook_preprocess_html(&$variables)
```

here is my code, please have a look.

```
$arrCSS = drupal_add_css();
          foreach ($arrCSS as $key => $value) {
            unset($arrCSS[$key]['data']);
          }
          $all_css = drupal_add_css();
          print_r($all_css);

```

# Answer
CSS should be manipulated using `hook_css_alter()`, not in an HTML preprocess (where it's too late).

```
function hook_css_alter(&$css) {
  // Remove defaults.css file.
  unset($css[drupal_get_path('module', 'system') . '/defaults.css']);
}

```
> 3 votes

---
Tags: theming
---


# Question
Title: Get translated taxonomy terms with Entity Translation
I'm using Entity Translation for Taxonomy Terms.

I've a Cities Vocabulary and I need to get translated names of some 1600 cities.

Using taxonomy\_get\_tree without arguments returns the term names in English. However if I pass the last parameter $load\_entities= TRUE then it currectly returns $term-\>name as translated one.

But it seems fully loading 1600 terms by setting $load\_entities can slown down the site performance heavily as mentioned in the api page.

**Is there any faster way to do it?**

I'm thinking of caching the results in a temp file. Or can use some query as in When using Entity Translation and the Title module, how can I get the translated term from the term ID programmatically? to fetch it myself.

# Answer
> 3 votes
You are using Entity Translation, so keep in mind there can't be any translated term load because you're translating fields not whole term. Term will load by

`$term = taxonomy_term_load($tid);`

use in devel mode or by dpm see the `$term` object. There you'll see structure

```
$term->name_field['en'][0]['value']

```

You can fetch it this way or by `field_get_items()` for en language.

```
$name = field_get_items('taxonomy_term', $term, 'name_field', 'en');

```

AND

```
$term->name_field['fr'][0]['value']

```

You can fetch it this way or by `field_get_items()` for fr language.

```
$name = field_get_items('taxonomy_term', $term, 'name_field', 'fr');

```

This is how you can get the data per language

---
Tags: 7, i18n-l10n
---


# Question
Title: How to let simplenews send email instantly without through cron?
I'm using simplenews and MIME mail in my drupal 7 site to send newsletter.

When I click send newsletter, the sending of newsletter is in pending status and waiting for cron to run and send email.

Is there any method I can send newsletter email directly without waiting for cron?

# Answer
Instead of using cron (either manually or waiting for it) you could use:

**Drush**

`drush simplenews-spool-count`

> Print the current simplenews mail spool count

`drush simplenews-spool-send`

> Send the default amount of mails, as defined by the simplenews\_throttle variable.

`drush simplenews-spool-send 100`

> Send 100 mails.

`drush simplenews-spool-send 0`

> Send all mails.

**Alternative cronjob usage**

If you can't use drush you can trigger cron manually at `/admin/reports/status/run-cron`, but this will also run all other cronjobs. As an alternative you could install and use elysia cron or ultimate cron (currently the later looks like to be the more active version). Both modules will allow you to run specific cronjobs manually and separated from others.
> 2 votes

# Answer
You can run cron manually by accessing /admin/reports/status/run-cron in drupal 7

Please have a look at this page https://www.drupal.org/node/369754 which gives more information about newsletters
> 0 votes

---
Tags: emails
---


title: show content in a modal / popup window

text:
# Question
Title: show content in a modal / popup window
I'm using views in my drupal site and I want to show a popup window containing custom information (the information from the content type I guess) when I click on a view item.

Something really similar to this: http://conference.99u.com/#speakers

Is there an easy way to do this in Drupal? Which is the best module for that?

Thanks you in advance!

# Answer
> 4 votes
sounds like colorbox\_node might be the module you want.

> Gives the user the ability to display ANY page inside a colorbox modal without the header and footer. Those pages include:
>
> * Node Pages
> * User Pages
> * Views Pages
> * Webforms (requires Webform Ajax Module)
> * Integration with Views
> * Integration with Context
> * Integration with Panels

---
Tags: views, javascript
---


# Question
Title: How to load the required modules only on Drupal site?
I have a site which contains more than 100 modules. So, for each page every module is getting loaded.

Is there any way to load only required modules to that particular page?

# Answer
No, there's no such way. Or may be answer is: Yes, it's done automatically. Keep in mind that Drupal loads only the .module file always, and other files (includes, classes, etc) are only loaded when needed. Is true that that 'when needed' may be always for some of the files, but not all.
> 2 votes

# Answer
No need to worry to much about the number of modules loaded since drupal's caching system is quite sophisticated. All nodes are pre-rendered or actually preprocessed – and once you have caching on, your on the safe side.

You should of course (always) ask yourself if using \>100 modules is really necessary – or if the same functionalities could also be accomblished by using frewer 'broader' modules – you can for example mimic the functionalities of many tailored modules with the help of a few powerful modules like rules.

So besically *afaik* the number of modules doesn't really affect the processing time or the loading time for the user, at least if caching etc. is activated. But it can become difficult to actually maintain the site – especially when it comes to keeping modules up to date.
> 1 votes

---
Tags: 7
---


# Question
Title: How to remove the word "New" for the new comments
When I add a new comment, the word "New" is printed at the top:

I don't need it. This word can be removed by editing the file `/modules/comment/comment.tpl.php`:

```
//remove these 3 lines, and the word will disappear
<?php if ($new): ?>
  <span class="new"><?php print $new ?></span>
<?php endif; ?>

```

But I don't think, that changing core modules is a good idea.

How can I remove the word without changing the core files?

# Answer
copy `/modules/comment/comment.tpl.php` to your theme folder e.g. `sites/all/themes/mytheme/(templates/)comment.tpl.php`.

That theme file will override the comment.tpl.php from core, in that file you can remove this block:

```
<?php if ($new): ?>
  <span class="new"><?php print $new ?></span>
<?php endif; ?>

```

This way is perfectly fine, you are not changing/ hacking core. The theme system was meant to be used that way :)
> 6 votes

# Answer
add .new {display:none;} to your stylesheets or inject it with ccs\_injector
> 1 votes

---
Tags: 7, comments
---


# Question
Title: How to add a class to a List field based on the content?
I have a List Field for the Articles that will work like a Category.

This is an image of the PSD file:

There are 6 options on the list so the user can select the appropriate one when creating the Article. The problem is that each of those options needs a different CSS class and it should still be possible to make a View for those contents and show them as shown on the next image.

The boxes with colors is what I need to create as the Category, but I cannot add CSS classes for each content on the list while having the View that shows those 4 articles.

Any idea how can I get this to work?

# Answer
Found the solution with the **Field Formatter CSS Class** module to get the css added, then for being able to use it on the Views module, the instructions from are (Drewpal's instructions):

'm using the views module. In order to pass the css property captured with the Field Formatter CSS Class module through to the Views module, you have to do the following:

> Go to ../admin/structure/views and edit the view that's displaying the field(s) where you want the css to be applied
>
> In the "Fields" section, add the content field that's capturing the css class (in my case it was Content: Style)
>
> On the configuration page, uncheck the "Exclude from Display" box and set "Formatter" to Key (if using Select List as in the video), then click apply
>
> Next, edit the field that you'll want the CSS class to be applied
>
> On the config page, in the "styles" section, check "Customize Field HTML" and then check "Create a CSS class"
>
> In the "CSS class" textbox enter the token from the field that holds the css class (note: the token should be the name of the field like this \[feild\_fieldname\] - mine was \[field\_style\])
>
> The select apply and it will pass the css class through.

More info here: http://codekarate.com/daily-dose-of-drupal/drupal-7-field-formatter-css-class-module#comment-7154
> 1 votes

---
Tags: views, entities
---