title: Request new password form id

text:
# Question
Title: Request new password form id
I want to know the Request New Password form id. (www.example.com/user/password).
I found out that the register form is "user\_register\_form" and tried same for password (user\_password\_form / user\_pass\_form / user\_pass\_reset) but nothing worked.

Hope you can help me! Thanks a lot!

Edit: If you could tell me the account form id in the same breathe, the answer would be simply awesome.

# Answer
> 3 votes
Note that print\_r will be better in this case because to see the form he desires one must be logged out otherwise you'll get the password reset for the active user, which is different.

Leandros, try putting this in your theme's template.php and visiting user/password (not logged in)

```
function YOURTHEMENAME_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'user_pass':
        print '<pre>';print_r($form); print '</pre>';
      break;
  }
}

```

It will give you an array of everything that's in there. Then, say you wanted to change the text "Username or e-mail address" and the text on the submit button you could do this:

```
function YOURTHEMENAME_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'user_pass':
        //print '<pre>';print_r($form); print '</pre>';
        $form['name']['#title'] = 'Please type your username/email quickly.';
        $form['actions']['submit']['#value'] = 'Email it to me!';
      break;
  }
}

```

# Answer
> 1 votes
install the Devel module. Then implement hook\_form\_alter() and use dpm().

Then goto any page you want to see a form details on, you will see it in the System Messages block.

```
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  dpm($form, '$form info for $form_id '.$form_id);
}

```

# Answer
> 0 votes
The IDs for these are:

* **User register:** `user_register_form`
* **User login:** `form_user_login`
* **User pass:** `user_pass`

I suggest you to use the hook\_form\_FORM\_ID\_alter.

e.g. For change something in the User pass form:

```
/**
 * Implements hook_form_user_pass_alter().
 */
function my_module_form_user_pass_alter($form, &$form_state) {
  // Change text button.
  $form['actions']['submit']['#value'] = t('Send password');
}

```

---
Tags: 7, forms, users
---


# Question
Title: Redirect HTTPS to HTTP for a bilingual site
I set up a bilingual site pointing to 2 different domains for a client. My client then started receiving comments about unusual behavior, and digging a little I found out they (unknowingly) signed up for an HTTPS account while being on shared hosting and not having an SSL certificate.

I understand I can revert this by going to settings.php and force HTTP writing:

```
$base_url = 'http://example.com';

```

My question is if this is the correct way to handle this and I don't need to change anything else (like .htaccess); also, I have a different domain for a Spanish version of the site, could this domain be affected by pointing `$base_url` to the English domain? should I add both?

# Answer
> 1 votes
I would do the https to http redirect inside of .htaccess. Setting the base\_url in settings.php will only fix it after the user clicks on a link. The landing page will still be https. I would use something like this in your .htaccess file:

```
RewriteCond %{HTTP_X_FORWARDED_PROTO} ^https$ [or]
RewriteCond %{HTTPS} ^on$
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

```

---
Tags: 7, redirection
---


# Question
Title: Theme call for block returning as an empty string
I have a call for a block generating that is returning an empty string when it should be returning with generated content. I have cleared out the theme cache and the results remain the same. I've gone through most of the documented steps on the official docs and am pretty baffled as to why it isn't working as intended.

Here is the code from generic.module

```
/**
 * Implements hook_block_info()
 */
function generic_block_info() {
  $blocks['gen_1'] = array(
    'info' => t('Project Information'),
  );
  return $blocks;
}

/**
 * Implements hook_theme()
 */
function generic_theme() {
  return array(
    'block_projectinfo' => array(
        'variables' => array(
            'completionPct' => NULL,
        ),
        'file' => 'theme/block-projectinfo'
    )
  );
}

/**
 * Implements hook_block_view()
 */
function generic_block_view($delta = '') {
    global $conf;

    switch ($delta) {
        case 'gen_1':
            $block['subject'] = t('Project Status');

                 $variables = array(
                  'completionPercentage' => 45
                     );

            $block['content'] = theme('block_projectinfo',$variables);
            break;
    }
    return $block;
}

```

Theme

```
<?php

/**
 * @file
 * Provides rendered output of the Project
 */

?>

<div class='invest-wrap'>
    <table class='total-stat cont2'>
        <tr>
            <td class='funded'>Percent Complete</td>
            <td class='percentage'><?php print $completionPct; ?>%</td>
        </tr>
    </table>
</div>

```

# Answer
> 0 votes
Assuming your template file can be found at theme/block-projectinfo.tpl.php, you just need to change the `file` property to `template` in `hook_theme()`:

```
function generic_theme() {
  return array(
    'block_projectinfo' => array(
        'variables' => array(
            'completionPct' => NULL,
        ),
        'template' => 'theme/block-projectinfo'
    )
  );
}

```

`file` is

> The file the implementation resides in. This file will be included prior to the theme being rendered, to make sure that the function or preprocess function (as needed) is actually loaded; this makes it possible to split theme functions out into separate files quite easily.

And refers to situations where you implement a `theme_foo()` function, rather than a template file.

---
Tags: 7
---


# Question
Title: View with relationship to custom entity via computed property
View with relationship to custom entity via computed property

I have nodes connected to a custom entity (called here "myentity") via a computed property, like this:

```
  $info['node']['properties']['myentity'] = array(
    'label' => t("Myentity"),
    'type' => 'myentity',
    'computed' => TRUE,
    'queryable' => TRUE,  // setting this to FALSE doesn't change anything
    'entity views field' => TRUE,
    'getter callback' => 'mymodule_node_property_myentity_get',
  );

```

The callback function extracts some values from the node and calls another function, which fills these values into an entity field query, returning the wanted myentity instance.

This entity connection is working, so I can get the property "myprop" of myentity via an entity API wrapper `$node_wrapper->myentity->myprop->value()`.

Now I want to add myprop in a simple view for nodes. After creating a relationship to myentity, "Content: Myentity" shows up in the "Add fields" list, as well as all of myentity's properties.

Selecting "Content: Myentity" works - myentity's default label is displayed in the view output. (With some magic - the displayed SQL query is `SELECT node.nid AS nid FROM {node} node`).

However, selecting "Myentity: Myprop" does not work. Even before executing the view, Drupal shows a SQL error:

```
SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "myentity" LINE 1: SELECT node.nid AS nid, myentity.myprop AS myentity_myprop, no... ^

```

The displayed SQL query here is `SELECT node.nid AS nid, myentity.myprop AS myentity_myprop FROM {node} node`. myentity is referenced in the select clause, but not in the from clause, nor is there any join statement.

Has somebody managed to add properties of a custom entity, connected via a computed node property, to views?

# Answer
Finally figured out a workaround: Pull every needed entity property as a "virtual field" into the node itself.

```
// define additional property information for node
function mymodule_entity_property_info_alter(&$info) {
  $properties = & $info['node']['properties'];
  foreach (array('myprop') as $property) {
    $properties[$property] = array(
      'label' => $info['mymodule']['properties'][$property]['label'],
      'description' => $info['mymodule']['properties'][$property]['description'],
      'type' => $info['mymodule']['properties'][$property]['type'],
      'computed' => TRUE,
      'queryable' => TRUE,
      'entity views field' => TRUE,
      'getter callback' => "mymodule_node_property_verbatim_get",
    );
  }
}

// getter callback
function mymodule_node_property_verbatim_get($data, array $options, $name, $type, $info) {
  $myentity = mymodule_get_from_node($data);
  return !empty($publication->{$name}) ? $publication->{$name} : array();
}

// obtain the related entity from the node
function mymodule_get_from_node($node) {

  // some custom code to get myentity

  return $myentity;
}

```

Thus, the properties can be adressed as views fields as well as for any other purposes. It's possible to extend this to access properties of nested entities, too.

One drawback, however: The fields cannot be used as views sort criteria.
> 1 votes

---
Tags: 7, views, entities
---


# Question
Title: Install APC and Memcache and their extensions
I am building a drupal 7 site. My site is currently hosted on the bluehost - shared hosting.

When I tried to install APC module I got the following error: "The APC module needs the apc extension see: http://www.php.net/apc. (Currently using APC Not available)"

I have no idea how to install the extension (even after I read not-so-clear guides).

I spoke with the support of bluehost, and they told my I can't install the APC extension on shared hosting.

I also tried to install the Memcache Module.
I also got here the following error: "(Currently using Extensions not available Either the memcache or memcached extensions must be installed in order to use memcache integration.) You must enable the PECL memcached or memcache extension to use memcache.inc."

I really can't use the APC module? Can someone please help me install the APC module & extensions?

What about the Memcache Module? How can I install & enable the PECL?

# Answer
> 1 votes
If your stuck with shared hosting there are a couple of options to make Drupal faster.

Use some form of a file cache for the page cache. Boost & filecache's filecache\_fast\_pagecache option will serve cached pages a lot quicker than core does. For the other cache tables filecache or Drupal's core database cache might be quicker; you'll have to test to see what one works better on your shared hosting.
https://drupal.org/project/boost
https://drupal.org/project/filecache

Optimize your database. This is a post of things that can be done on the drupal side; there is a lot more that can be done if you can change the mysql side. Drupal 7: Database select query FROM cache\_bootstrap brings server down

---
Tags: caching
---


title: How to add an image within a header?

text:
# Question
Title: How to add an image within a header?
I am new to Drupal and currently working on a theme from scratch. I have been using the tutorial How to create a simple Drupal 7 theme from scratch to help me. I have got most the things working required for the site I am working on apart from the header. I would like to add an image to the header which would be floated to the left of the text.

**So far I have tried** to create a content type with an image and assign it to the header block I have created. When I tried assigning a content type the header disappeared.

Any suggestions?

# Answer
> 1 votes
I would not create a content type just for adding a single image to the header in any case, but even more so in this case as it appears that is you website's logo (is that right?).

If it is your logo then the best way to achieve this is via the settings of your theme. Almost all themes have a setting for the logo image.

Go to admin/appearance then click the settings link for your theme. You will see a "Logo image settings" section on the settings form, which usually by default has a check box "Use the default logo", which will be checked by default.

You can un-check that check box and then enter a path to your logo image file, however the easier and better way is to leave that check box checked and then in your theme directory replace the default logo with your own, by renaming your logo image to logo.png and copying it over the one that is already there.

On that theme settings page there is also a section for "Toggle display". In this section make sure that "Logo" is checked.

Then the site will be using your logo, which normally by default will be in the header already.

Then you just have to use a little css to position it as you want it, or if it is not in the right place for you, edit the page.tpl.php of your theme and move the logo to where you want it, then tweak styles with css as needed.

If you only want the logo on the home page, make a copy of your page.tpl.php in your theme and call it page--front.tpl.php - This means it will only apply to your front page (see drupal 7 template suggestions for more info).

Then you can have the logo printing on the front page but you can remove it from your normal page.tpl.php so it doesn't appear on other pages.

If I was wrong about it being your site logo or it is the logo but for some other reason you don't want to use the site logo setting, you can do one of a few things.

If the image is purely decorative, it is generally considered a good idea to make it a css background image, in which case just add the image to your theme's images directory and add some css to your theme to set it as the background image of your text block in your header and use padding so that the contents don't overlap the image.

If the image is not purely decorative and it actually has meaning to the user, you want screen readers to read it as an image so disabled users can see it.

In this case you need to use an img tag.

So you can do one of these things:

Make the page--front.tpl.php and manually add an img tag in the place you want it, put the image in the images directory of your theme, then style with CSS.

The other option is to create a custom block via the block UI.

To do this go to admin/structure/block and click the "Add block" link. In the block body field add the img tag you want. The easiest way to do this is make sure you have a wysiwyg text editor (for example, ckeditor or wysiwyg module) and use it for block creation. Then you can upload an image directly via the wysiwyg editor instead of messing around uploading files manually to your server, which is not ideal.

In this way you can either make a block for your image and a block for the text to the right of it, or if they directly relate to each other you can add them in the same block.

Then in the block visibility settings you can make it so that it only shows on the home page (or you can use some other block management system to do that if you prefer).

# Answer
> 0 votes
The easier solution i can think of involves only CSS.

You can style the block to have that image as background, and set the left padding wide enough to keep the block content from covering it.

---
Tags: 7, nodes, blocks, media
---


title: Use safe_key in webform emails

text:
# Question
Title: Use safe_key in webform emails
I want to be able to send the safe\_key through the internal email.
The website was doing this before, and for some reason is not any longer.

I've tried %value\[safe\_key\] and %safekey.
I read some information here, but no one seemed to have an answer that worked.
Is there another token that works? I saw %email\[key\] but was not sure that it would map right.

# Answer
> 0 votes
I had a similar problem, the solution I found was here: https://drupal.org/node/1340010

If you are using webform v3.x, then you will need to apply patch #19.

If you are using webform v4.x, patch #22 (I have not tried this one).

For me, to apply the patch (on a Linux system), I did the following (adjust the first line to match where your webform module is):

```
cd /etc/drupal7/all/modules/webform
wget https://drupal.org/files/webform-1340010-19.patch
patch < webform-safe_key.patch

```

Then I had access to a new token called "%safe\_key" that did exactly what I wanted (e.g. "%safe\_key\[field\]" gave me the value of the safe\_key in the email, rather than the display value.

---
Tags: emails
---


# Question
Title: Can I install Drupal Commerce as a site in a multi-site architecture, preferably using Commerce Kickstart?
Commerce Kickstart comes bundled with the latest version of Drupal and modules necessary for it to operate.

I already have a Drupal install where various sites make up a multi site architecture. Can I use Commerce Kickstart to install a store as one of those sites in that architecture? Note, this would be stand alone. I don't want the default install to be Commerce where there would be an attempt at a multi store setup, I just want one of the sites to be a Drupal Commerce site.

The CK project pages says, "Who should use Commerce Kickstart? Anyone who wants to skip weeks of configuration to build a commerce site on the Drupal Commerce framework."

Certainly I would like to avoid weeks of configuration and setup.

Is this possible? And if so, what's the best workflow to get it installed and the demo store setup?

If this is not possible, please indicate as much, and let me know if it's possible to install Drupal Commerce as a site in a Drupal multi site architecture nonetheless. If this is the direction I need to go, what would be the folder structure under sites/store.mysite.com? Would I simply follow the directions on the Drupal Commerce project page as if it were an independent installation?

Thanks!

# Answer
> 6 votes
After much research, I've found out the following:

**Can Commerce Kickstart be added to a multi-site installation?**

The answer is **No**.

As Clive pointed out, CK ships with patches to Drupal core, so it's definitely not unmodified. Additionally, CK will break if one tries to migrate an already existing, stand alone installation to be one of the sites in an existing multi site setup. CK depends on the installation profile to be present to continue to function correctly. Finally, Bojanz, a contributor to the project, points out, CK is a distribution and has to stand alone.

**Can Drupal Commerce be added to a multi site installation?**

The answer is **Yes**.

In that same answer above, Bojanz also points out that Drupal Commerce can be added to a multi site architecture. The caveat is that it has to be built out a la cart with modules as needed that make up the Commerce Kickstart distribution.

# Answer
> 1 votes
You want to follow the Alternatives, Recipes and Issues Documentation for Commerce Kickstart.

> You have many options as an advanced sitebuilder:
>
> * Move modules into sites/all/modules or sites/all/modules/contrib: Although installation profiles build with the modules in the profiles directory, many developers want them in sites/all/modules. Before running the installation process, just move the modules from profiles/commerce\_kickstart/modules into sites/all/modules with any tool you like. For example, mv profiles/commerce\_kickstart/modules/\* sites/all/modules/
> * Add Commerce Kickstart to an existing Drupal codebase: Visit the releases page, find your release, and download the -no-core.tar.gz or -no-core.zip version of commerce\_kickstart and uncompress it into profiles/commerce\_kickstart OR drush dl commerce\_kickstart. Either of these will include the required modules. NOTE: This does not mean we recommend installing kickstart on an existing site. A big part of kickstart is the installation process, which this will skip and may not even work.
> * Updating the PHP memory limit if necessary: Commerce Kickstart installation involves the installation of 3 major contributed modules all at once on top of Drupal 7 itself, which may cause you to hit your memory limit during installation. If this happens, installation fails, and you will need to drop all tables from your database and reinstall with a higher memory limit (recommended 96M or higher to be safe; decrease as needed afterward).

---
Tags: 7, commerce, multi-sites, installation
---


# Question
Title: Form - Prepopulate and hide field with given argument
I have two content types: City and Request. Request is entity referenced to city.

Now i created a custom themed node /berlin. On this page i have a button that says "send request", which brings you to the node/add/request form.

The form should now somehow pre-populate the field "field-city" with the previously selected city entity/node.

Additionally the field should be hidden.

Could you guys point me in the right direction?

# Answer
There appears to be a dev version of the Prepopulate module for Drupal 7:

> The Prepopulate module allows fields in most forms to be pre-populated from the $\_REQUEST variable.
>
> For example, the following URL,
>
> http://www.example.com/node/add/blog?edit\[title\]=this is the title
>
> will automatically fill the Title field on a new blog post with the words "this is the title". Any field can be prepopulated this way, including taxonomy and CCK fields. You can prepopulate more than one field at a time as well. Prepopulate is excellent for creating bookmarklets. For examples on usage for all of these cases, please read the USAGE.txt file that comes with the module or you can read the online handbook page.

So you would just have to craft that button on your City node page to include the additional variable for your city field.

If for whatever reason this doesn't work exactly to your liking, eg, I am not sure if it allows for hiding of the prepopulated field, it would be fairly trivial to craft the functionality in a form\_alter() hook in a custom module.
> 1 votes

# Answer
After some more research i came across a module that does exactly what i need! Prepopulating a entity reference field and hiding the form field.

https://drupal.org/project/entityreference\_prepopulate
> 1 votes

# Answer
The Prepopulate module allows fields in most forms to be pre-populated from the $\_REQUEST variable. Maybe you could use that module to fill the city field on the add form.
> 0 votes

# Answer
You can try Node Reference URL Widget to auto-populates the field form url and its value can't be change later on. For More information go through the documentation of this module. For Entity reference use Entityreference prepopulate module.
> 0 votes

---
Tags: entities
---


title: How is the display in a view renamed?

text:
# Question
Title: How is the display in a view renamed?
When you make a copy of one of displays of a view the new display is given a name like `Page 2`. How do you rename that display? I can't seem to find a way of renaming the pge but I suspect there must be a link to edit it.

I have done it before and wonder whether some module or CSS change may be occluding the link required to change it.

# Answer
If you want to change its machine name their option available in advance option of view or want to change its display name that will change form display.
> 5 votes

---
Tags: views
---


# Question
Title: New multisite server: should I use CPanel? And Symlinks?
I'm commissioning a new server to host a mix of D6 and D7 sites.

My old server had Plesk, which was a bad idea for Drupal, as I spent most of my time trying to get around its security to allow a multisite configuration to work.

The first question I have is whether to install CPanel or manage the site through the command line?

My second question is a bit more involved.

Currently I structure my Drupal setup as follows:

/var/www/drupal/drupal-7.26 (Current Drupal version)

/var/www/drupal/drupal7 (Vhost points here - Symlink to drupal current version)

/var/www/drupal/sites7 (Drupal sites directory - keeps it separate from the current drupal version)

/var/www/drupal/drupal-7.26/sites (Symlink to above sites7 directory)

I've found that keeping the sites directory separate from the Drupal install directory helps when upgrading the core Drupal version, but it does seem to break the ability to use D7's module upgrading.

Any thoughts on whether it's worth sticking with this structure, or should I switch to plain directories?

Thanks,

James

# Answer
From the information you've provided, it sounds like CPanel would not be a good setup for you. CPanel is great if you want an easy way to manage separate accounts that don't have access to each other. That's why many resellers use CPanel. You will likely spend just as much time getting around CPanel to do what you want.

However, keep in mind that CPanel offers a lot out of the box, like email, easy SSL Cert management, DNS management, and monitoring, not to mention security and software updates. If you spin up your own environment, you will need to make sure you set up a firewall of some sort, and an email server, at the very least. Server setup can be a large topic, and is very dependent on your particular hosting needs.

You didn't mention it, but have you looked at Aegir? It may provide you with the multi-site management and update management that you're looking for: http://www.aegirproject.org/

Regarding your proposed directory structure, I have not tested a setup like that so I can't provide a direct answer to your question, but I would look into using Drush and aliases if you haven't already.
> 4 votes

---
Tags: multi-sites
---


# Question
Title: Form - Show partial form in block then populate full form with partial data
I have a content type with various fields. Now i would like to show a couple of it's fields in a block globally and on submission post that data to the full form page and pre-populate the already provided fields.

Can this be done easily with the drupal core or is there a helpful module you guys can recommend?

# Answer
> 0 votes
As contrib is an extension of core there are always ways to do stuff in core that you can do with contrib, it's just often contrib makes it easier, quicker, and more easily maintainable at the sacrifice of more code.

For this I would look at the prepopulate module which allows fields in most forms to be pre-populated from the $\_REQUEST variable:

https://drupal.org/project/prepopulate

If you want to use just core then you know what you're outputting in the block, at a guess you could form\_alter the form linked to prepopulate.

---
Tags: entities, blocks
---


# Question
Title: Override taxonomy term display page with panel page
* I am having a menu built using taxonomy terms which links to a URL pattern like shop/\[Term name\] this is a dropdown menu.
* I have created a panel page which takes an argument in the URL i.e (shop/!argument).
* In the panel I have added a contextual filtered(has Taxonomy term) view and checked "send arguments" option in settings.
* so obviously the taxonomy term display page is where I land when clicking the links.
* I don't want to use the taxonomy term panel or the views page for taxonomy which comes with drupal core itself.
* I want my panel page to override the taxonomy term display page this is only for two types of vocabulary terms, any ideas how?

# Answer
Have you tried this tutorial? http://drupaleasy.com/blogs/ultimike/2010/10/taxonomy-term-pages-steroids-using-panels-views
> 2 votes

---
Tags: 7, views, panels, taxonomy-terms
---


# Question
Title: How to add a prefix - suffix to a node title from a module
I loaded a renderable array within a hook\_block\_view. I need to add a prefix and suffix to the title before rendering it. How can I manage to do that ?

# Answer
You have an error in the very title. Adding prefixes and suffixes is not a job for a module. You do it in template. If you need to wrap it in html tags, do it in `node.tpl.php`. If you need some more elaborated logic, see template\_preprocess\_node().
> 1 votes

# Answer
In hook\_preprocess\_node($variables) set $variables\['title\_prefix'\] = 'test';
> 1 votes

# Answer
locate the title in question, and add the prefix and suffix as you do in a form like this:

```
$array['the_title']['#prefix'] = "<div class='wrapper'>";
$array['the_title']['#suffix'] = "</div>";

```

Hope it helps
> 0 votes

---
Tags: theming
---


# Question
Title: What can set a view's results to empty despite SQL queries to be the same?
I have a view that displays results correctly for the admin user (uid = 1) but no result at all for the others and I can't figure out why:

* The view's permission is set to "view published content" =\> not a permission problem;
* The SQL queries are exactly the same for both users which means that the context is the same for both =\> not a building query problem;
* For the admin user, the results are as expected, while for the others, it seems that the view does not display any result since the "no result message" appears for them.

The question is therefore: **Why is this view displaying no result for other users than the admin when the context is the same, that it's not a permission-related issue and that the SQL queries are the same?**

Thanks a lot!

EDIT:

The export of my views is the following:

```
$view = new view();
$view->name = 'clone_of_og_extras_group_admin';
$view->description = 'Délégués d\'un comité';
$view->tag = '';
$view->base_table = 'users';
$view->human_name = 'Liste délégué(s) d\'un comité';
$view->core = 0;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['title'] = 'Délégué(s)';
$handler->display->display_options['use_more_always'] = TRUE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'responsive_grid';
$handler->display->display_options['style_options']['column_classes'] = 'userscol';
$handler->display->display_options['style_options']['row_classes'] = 'usersrow';
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['row_options']['inline'] = array(
  'picture' => 'picture',
  'name' => 'name',
);
/* Header: Global: Text area */
$handler->display->display_options['header']['area']['id'] = 'area';
$handler->display->display_options['header']['area']['table'] = 'views';
$handler->display->display_options['header']['area']['field'] = 'area';
$handler->display->display_options['header']['area']['content'] = '<h2 class="title">Délégué(s) du %1:</h2>';
$handler->display->display_options['header']['area']['format'] = 'php_code';
$handler->display->display_options['header']['area']['tokenize'] = TRUE;
/* No results behavior: Global: Text area */
$handler->display->display_options['empty']['area']['id'] = 'area';
$handler->display->display_options['empty']['area']['table'] = 'views';
$handler->display->display_options['empty']['area']['field'] = 'area';
$handler->display->display_options['empty']['area']['empty'] = TRUE;
$handler->display->display_options['empty']['area']['content'] = 'Il n\'y a pas de délégué attitré à ce comité. Si ce poste t\'intéresse, tu peux postuler en cliquant sur l\'onglet ci-dessous.';
$handler->display->display_options['empty']['area']['format'] = 'filtered_html';
/* Relationship: OG membership: OG membership from User */
$handler->display->display_options['relationships']['og_membership_rel']['id'] = 'og_membership_rel';
$handler->display->display_options['relationships']['og_membership_rel']['table'] = 'users';
$handler->display->display_options['relationships']['og_membership_rel']['field'] = 'og_membership_rel';
/* Relationship: User: Profile */
$handler->display->display_options['relationships']['profile']['id'] = 'profile';
$handler->display->display_options['relationships']['profile']['table'] = 'users';
$handler->display->display_options['relationships']['profile']['field'] = 'profile';
$handler->display->display_options['relationships']['profile']['required'] = TRUE;
$handler->display->display_options['relationships']['profile']['bundle_types'] = array(
  'main' => 'main',
);
/* Relationship: OG membership: Node from OG membership */
$handler->display->display_options['relationships']['og_membership_related_node']['id'] = 'og_membership_related_node';
$handler->display->display_options['relationships']['og_membership_related_node']['table'] = 'og_membership';
$handler->display->display_options['relationships']['og_membership_related_node']['field'] = 'og_membership_related_node';
$handler->display->display_options['relationships']['og_membership_related_node']['relationship'] = 'og_membership_rel';
/* Field: Profile: Photo de profil */
$handler->display->display_options['fields']['field_prof_pic_profile']['id'] = 'field_prof_pic_profile';
$handler->display->display_options['fields']['field_prof_pic_profile']['table'] = 'field_data_field_prof_pic_profile';
$handler->display->display_options['fields']['field_prof_pic_profile']['field'] = 'field_prof_pic_profile';
$handler->display->display_options['fields']['field_prof_pic_profile']['relationship'] = 'profile';
$handler->display->display_options['fields']['field_prof_pic_profile']['label'] = '';
$handler->display->display_options['fields']['field_prof_pic_profile']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_prof_pic_profile']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_prof_pic_profile']['settings'] = array(
  'image_style' => 'profile_picture',
  'image_link' => 'content',
);
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['name']['element_wrapper_type'] = 'div';
/* Sort criterion: OG membership: Created */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'og_membership';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['relationship'] = 'og_membership_rel';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: OG membership: OG group gid */
$handler->display->display_options['arguments']['group']['id'] = 'group';
$handler->display->display_options['arguments']['group']['table'] = 'og_membership';
$handler->display->display_options['arguments']['group']['field'] = 'group';
$handler->display->display_options['arguments']['group']['relationship'] = 'og_membership_rel';
$handler->display->display_options['arguments']['group']['default_action'] = 'default';
$handler->display->display_options['arguments']['group']['default_argument_type'] = 'og_context';
$handler->display->display_options['arguments']['group']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['group']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['group']['summary_options']['items_per_page'] = '25';
/* Filter criterion: User: Active */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'users';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';
/* Filter criterion: OG membership: State */
$handler->display->display_options['filters']['state']['id'] = 'state';
$handler->display->display_options['filters']['state']['table'] = 'og_membership';
$handler->display->display_options['filters']['state']['field'] = 'state';
$handler->display->display_options['filters']['state']['relationship'] = 'og_membership_rel';
$handler->display->display_options['filters']['state']['value'] = array(
  1 => '1',
);
/* Filter criterion: OG user roles: Role ID */
$handler->display->display_options['filters']['rid']['id'] = 'rid';
$handler->display->display_options['filters']['rid']['table'] = 'og_users_roles';
$handler->display->display_options['filters']['rid']['field'] = 'rid';
$handler->display->display_options['filters']['rid']['relationship'] = 'og_membership_rel';
$handler->display->display_options['filters']['rid']['value'] = array(
  3 => '3',
);
$handler->display->display_options['filters']['rid']['reduce_duplicates'] = TRUE;

/* Display: Entity Reference View Widget */
$handler = $view->new_display('entityreference_view_widget', 'Entity Reference View Widget', 'entityreference_view_widget_1');
$handler->display->display_options['defaults']['title'] = FALSE;
$handler->display->display_options['defaults']['exposed_form'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'entityreference_view_widget';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'grid';
$handler->display->display_options['style_options']['columns'] = '3';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'entity';
$handler->display->display_options['row_options']['view_mode'] = 'entityreference_view_widget';
$handler->display->display_options['defaults']['row_options'] = FALSE;

/* Display: EVA Field */
$handler = $view->new_display('entity_view', 'EVA Field', 'entity_view_1');
$handler->display->display_options['entity_type'] = 'node';
$handler->display->display_options['bundles'] = array(
  0 => 'comit_',
);
$handler->display->display_options['argument_mode'] = 'token';
$handler->display->display_options['default_argument'] = '[node:group:gid]';
$translatables['clone_of_og_extras_group_admin'] = array(
  t('Defaults'),
  t('Délégué(s)'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('<h2 class="title">Délégué(s) du %1:</h2>'),
  t('Il n\'y a pas de délégué attitré à ce comité. Si ce poste t\'intéresse, tu peux postuler en cliquant sur l\'onglet ci-dessous.'),
  t('OG membership from user'),
  t('Profile'),
  t('node from OG membership'),
  t('All'),
  t('Entity Reference View Widget'),
  t('EVA Field'),
);

```

It creates the following SQL query that returns two results (the same being displayed to the admin (uid=1) in my PHPMyAdmin. **So as I said, the query is not the issue; it's when it comes to display the results.**

```
SELECT profile_users.pid AS profile_users_pid, users.name AS users_name, users.uid AS uid, og_membership_users.created AS og_membership_users_created, 'profile2' AS field_data_field_prof_pic_profile_profile2_entity_type
FROM users users
INNER JOIN profile profile_users ON users.uid = profile_users.uid AND profile_users.type = 'main'
INNER JOIN og_membership og_membership_users ON users.uid = og_membership_users.etid AND og_membership_users.entity_type = 'user'
LEFT JOIN node node_og_membership ON og_membership_users.etid = node_og_membership.nid
LEFT JOIN og_users_roles og_users_roles_value_0 ON og_membership_users.gid = og_users_roles_value_0.gid AND og_users_roles_value_0.rid = 3
WHERE (( (og_users_roles_value_0.uid = users.uid) AND (og_membership_users.gid = 407 ) )AND(( (users.status <> 0) AND (og_membership_users.state IN (1)) AND( (og_users_roles_value_0.rid = 3) ))))
ORDER BY og_membership_users_created DESC

```

# Answer
> 1 votes
I found out after hours it was eventually a permission issue; for some reason, only the user with UID = 1 can have access to this view being displayed and it seems to be a known issue (cf. Stella's article where you can find the hack she proposes).

In my case, I bypassed the access by giving temporary access to user 1 permission when outputting the view (through EVA). (cf. this comment on the same article) Even though I don't really like this solution since it doesn't seem very secure, I think the risk is minim since I remove any "power user" access right after having executed the view.

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


title: How to translate a button?

text:
# Question
Title: How to translate a button?
I have a website in English language and i want to translate some button in own language .
i know that i can add my language and simply translate all my stuff, but the point is i have to translate these buttons like subscribe in Simplenews module in en language.

Here is my step : i went to `config/regional/translate/translate` and add my word to translate but i could not do that .

am i missing something ?

# Answer
You can use the module String Overrides which allow you to do what you asked for.

(As my low reputation I need to put here some more useless details :-) )

Copied From the module page:

Provides a quick and easy way to replace any text on the site.

Features: Easily replace anything that's passed through t() Locale support, allowing you to override strings in any language Ability to import/export \*.po files, for easy migration from the Locale module Note that this is not a replacement to Locale as having thousands of overrides can cause more pain then benefit. Use this only if you need a few easy text changes.
> 1 votes

---
Tags: i18n-l10n
---


# Question
Title: Meta tags on taxonomy term pages not showing(using views 3)
I have installed Meta tags module, configured it, working well, but on taxonomy term pages: *meta description*, and *meta keywords* not showing. I am using Views to override taxonomy term pages. I tried to set some random words for test purproses(not even tokens), but it's still not working. Anyone encountered this problem?

# Answer
I can offer next solutions:

1. Support of taxonomy term pages generated by views is already included in the Metatag module since 7.x-1.0-beta2.
2. If you are using the Metatag module with version lower than 7.x-1.0-beta2 you can use module Meta tags term view.
3. Try Meta tags quick.
> 1 votes

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


title: Running cron failed and show white page

text:
# Question
Title: Running cron failed and show white page
I am using Drupal 7.

When I am running cron manually as an admin, I get white page. When I am looking at the dblog report immediately after trying to run cron, I always see the following notice:

TYPE job\_scheduler
DATE Monday, March 17, 2014 - 00:15
USER Guest (not verified)
LOCATION http://www.site.com/admin/reports/status/run-cron
REFERRER
MESSAGE Finished processing scheduled jobs (0 sec s, 0 total, 0 failed).
SEVERITY notice

It is also strange that the user of this activities is "Guest (not verified)" and not Admin.

Yesterday I made alot of changes and installed some performance module as the boost module, file cache module and advagg module. But I always run cron after installing a module.
After few tests and enabling/disabling modules, it looks like that the problem is the filecache module

Can someone help me solve this issue?

# Answer
Hard to debug without further details. If you get white page then check your Webserver logs, especially error log. You can also try to run `drush cron` to catch some more details (error messages).
> 2 votes

---
Tags: cron
---


title: Change the actual file for Logins

text:
# Question
Title: Change the actual file for Logins
I have a site and I'd like to customize the login page. I'm using a customized version of the Stark Theme and I'd like to know if there is any way to change the actual file behind the login form so it looks a bit more uniform with the rest of the site. So without creating a new file and redirecting.

Any help?

# Answer
You can try iTweak Login module to customize the login page. This module have so many settings to customize login form page as well as login block.

You can also try FreshLogin module. It will provide a complete different template.It can customize as you want.
> 1 votes

---
Tags: 7, theming
---


# Question
Title: hook to redirect user before they create node?
I'm running a `db_query` to check if the user has taken a specific action. If they haven't, I'm redirecting them to the page where they can take that action.

```
function my_special_module_node_view(...) {
   db_query(...);

   if( $fails ) {
     drupal_set_message(t('Error'), 'error');
     drupal_goto('new_page');
   }
}

```

`hook_node_view` is mostly working right. It redirects from most pages except any user account pages. The only problem is it doesn't catch when they are trying to create a node. What hook can I use to redirect the user **before they view the node creation form**?

## Update

I've switched it to `hook_page_alter`. This catches all URLs including the node creation form, which is progress. I had to add in some logic to skip certain paths (including the `new_page` path to avoid an infinite loop). It seems to be working much better, except if the user does not have access to a page it still ends up in an infinite loop. My current code:

```
function my_special_module_page_alter() {
  db_query(...);

  if( $fails ) {
    $base_path = arg(0);
    if( !in_array($base_path, array('new_page', 'user')) ) {
      drupal_set_message(t('Error'), 'error');
      drupal_goto('new_page');
    }
  }
}

```

Any ideas why the pages the user does not have access to end up in a redirect loop? Is there a simple function I can call within `hook_page_alter` that checks "if user\_has\_access\_to\_this\_page"?

# Answer
If I am understanding this correctly, this might be a job for hook\_init(), eg something along these lines:

```
function YOURMODULE_init() {
  global $user;

  if ($user->uid) {

    $fails = /* whatever */ ;

    if ($_GET['q']!='node/add/foo') {

      if ($fails) {
        drupal_set_message('How about creating foo first...');
        drupal_goto('node/add/foo');
      }

    }

  }

}

```
> 1 votes

---
Tags: hooks, redirection, nodes
---


# Question
Title: How can I automatically rotate images based on EXIF data prior to image styles being applied?
I have a website where users can upload pictures of themselves. Many of these pictures are taken with mobile phones and as a result a lot of them are shot such that the picture is vertical, but it is uploaded as horizontal because Drupal ignores the EXIF data. This can be fixed using the Image Cache Actions module (autorotate submodule), but if I do so, this breaks the Manual Crop module, which I use to trim the pictures as necessary.

Is it possible to somehow have Drupal automatically rotate all images upon upload based on their EXIF data if available, such that image styles would be applied to the rotated image, not the original image?

# Answer
Another option is to process the images before they are uploaded. I wrote a windows script to do this 5+ years ago. It still works, but I won't be offering any support for it. http://www.autoitscript.com/forum/topic/85891-imagemagick-batch-jpg-processor/
> 1 votes

# Answer
Use the http://drupal.org/project/imagecache\_actions, this module has a sub-module imagecache\_autorotate. The "autorotate" image filter do what you want.
> 0 votes

---
Tags: media
---


title: Query D6 db from D7 module

text:
# Question
Title: Query D6 db from D7 module
I want to import a content type data from D6 db to D7. I have db in settings file like....

```
    /**
     * Database
     */
    $databases['default']['default'] = array(
      'driver' => 'mysql',
      'database' => 'd7',
      'username' => 'root',
      'password' => 'root',
      'host' => 'localhost',
    );
    $databases['d6']['default'] = array(
      'driver' => 'mysql',
      'database' => 'd6',
      'username' => 'root',
      'password' => 'root',
      'host' => 'localhost',
    );

```

I am trying to query nid's from D6 db from D7 module using db\_query, but cant use node\_load for D6 db then.

```
    function import_schools() {
      db_set_active($key = 'd6');

      $result = db_query("SELECT nid FROM {node} WHERE type = :type AND nid         = :nid", array(
        ':type' => 'classified',
        ':nid' => '77307',
      ));

      while ($record = $result->fetchAssoc()) {
        print_r($record);
        print_r(node_load($record['nid']));
      }

    }

```

How can I chang API from d7 to d6 on fly while switching db using db\_set\_active.

# Answer
> 0 votes
If you are looking to Migrate D6 Content (Nodes) to D7 system then you can use Drupal-to-Drupal data migration module.

Project page says

> migrate\_d2d provides a framework based on the Migrate API for migrating content from Drupal 5, Drupal 6, or Drupal 7 sites into the Drupal 7 site where it is installed.

---
Tags: 7, migrations
---


title: How to preallocate form

text:
# Question
Title: How to preallocate form
I'm using the Follow module and I'd like to modify the form, where I can preallocate the beginning of the form, like in the picture shown below:

May I know how can this be done?

# Answer
You need to make a custom drupal module then implement a form alter to add a #field\_prefix to the form element.

In this case specifically, it would be like this:

```
/**
 * Implements hook_form_alter().
 */
function MODULE_NAME_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'FORM_ID') {
    $form['FIELD_NAME']['#field_prefix'] = t('PREFIX_TEXT');
  }
}

```

You will need to change the following in that code sample to suit your form:
MODULE\_NAME: The name of your custom drupal module.
FORM\_ID: The form id of the form you want to alter. In this case the forward form.
FIELD\_NAME: The machine name of the field you want to add a prefix to.
PREFIX\_TEXT: The text you want to put in front of the field.

To work out the form id of the form you want to alter, install the devel module, and just inside your form alter function add the following line:

```
dpm($form_id);

```

Now whenever you load a page you will see the form ids for all the forms on the current page, so go to the page with the forward form and you will see the form id.

To get the field machine name of the field you want to add the prefix to you use the same method.

So after you have added the form id to the code sample, then just inside that if statement add:

```
dpm($form);

```

Then when you go to the page with the form on it you will get a display of the form, which you can click to expand. Expand it and you will see a list of the form elements in the form, the keys are the machine names of the elements.

When you are done you can remove the dpm() calls and uninstall the devel module.
> 3 votes

# Answer
Try Prepopulate Module

The Prepopulate module allows fields in most forms to be pre-populated from the $\_REQUEST variable.

For example, the following URL,

```
http://www.example.com/node/add/blog?edit[title]=this is the title

```

will automatically fill the Title field on a new blog post with the words "this is the title".
> 0 votes

---
Tags: forms
---


# Question
Title: Reading a file uploade in my module without saving it
I'm creating an module and there I want to read a text file.

**I don't want to save the file.**

In my my\_module.module file I have

```
function my_module_upload_form($form, &$form_state) {
    $form['upload'] = array(
        '#type' => 'file',
    );

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

    return $form;
}
function my_module_upload_form_submit($form, &$form_state) {
    $file = file_load($form_state['values']['upload']);
    $url = file_create_url($file->uri);
}

```

I get the error "Trying to get property of non-object" at

```
$url = file_create_url($file->uri);

```

Can someone point me how to read the file correctly (without saving it)?

# Answer
> 3 votes
Ok I figured it out myself!

```
function my_module_upload_form_submit($form, &$form_state) {
    //saved the file into a tmp folder (location to save not set)
    //this will also add a pointer in the database
    $file = file_save_upload('upload', array(
        'file_validate_extensions' => array('txt'),
    ));

    //get the content in the file
    $content = file_get_contents($file->uri);

    //remove the file in temp and the pointer in the database
    file_delete($file);
}

```

---
Tags: 7, files
---


# Question
Title: How to get an array of values of node ids from entity reference field with EntityMetadataWrappers
I'm using a EntityMetadataWrapper on a profile2 entity. One of the fields is a multi-value entity reference field to nodes. I want to simple get the node ids as an array, so I can do a quick in\_array() to see if a value already exists.

I can't seem to find how to easily do this.

# Answer
> 2 votes
Should be as simple as:

```
$ids = $wrapper->field_foo->raw();

```

And if you want an array of entities instead:

```
$entities = $wrapper->field_foo->value();

```

---
Tags: 7, entities
---


# Question
Title: Weird problem in calculating sum of two computed field values as another sum
I have created one content type having fields like A,B,C,D,E,F,G. I have used computed filed module to compute these fields like the following. (Used filed group module to group some A&B in first group, C&D in second group , E,F,G are in third group. Here are the computations

A\*C=E

B\*D=F

E+F=G WHERE E,F AND G are computed fields .

The problem is when I submit the content type first time I am able to get E and F values but not G and if I edit the node and submit the result of G(E+F) is displaying correctly.

Here is the code snippet used to computed fields

```
$entity_field[0]['value'] = $entity->field_a['und'][0]['value'] * $entity->field_c['und'][0]['value'];

$entity_field[0]['value'] = $entity->field_b['und'][0]['value'] * $entity->field_d['und'][0]['value'];

$entity_field[0]['value'] = $entity->field_e['und'][0]['value']+ $entity->field_f['und'][0]['value'];

```

**Display Output**

```
$display_output= $entity_field_item['value'];

```

We tested the same scenario in Articles content type with field groups which shows all the results at a time i.e E,F and G.

I am getting errors on first submit.

Notice: Undefined property: stdClass::$field\_e in eval()

Notice: Undefined property: stdClass::$field\_f in eval()

What would be the problem?

# Answer
> 0 votes
I think this suggestion works

Go to the computed filed settings of **G**. Uncheck "Store value in the database" option might solves your problem. (If not necessary to store)

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


# Question
Title: Leave Page Alert "warning " Unless Submit Button Clicked
I have a website where users submit application forms. The form is based on Entity forms.

How can I popup a message "warning" if user try to close browser without submitting the application.

something similar to this http://jsfiddle.net/DerekL/GSWbB/show/

Many thanks,

# Answer
You can use the dirty forms module.

Currently there is only a drupal 6 version on the project page, however in this issue there is a drupal 7 version that apparently has been well tested and works.

With this module you can configure it to target your form using css seletors like classes and ids.
> 0 votes

---
Tags: entities, javascript
---


# Question
Title: Forms - Clone form with different url + theme
I have a content type which can be created by admins and regular authenticated users. Now i would like to create a separate form url like /city/create for authenticated users instead of the standard admin url /node/add/city.

I try to achieve to have two urls for the same form with two different layouts.

Could you guys point me in the right direction?

# Answer
> 0 votes
You can create path(url) alias for this. Using alias the same url will be called. Regarding theme you can alter form with some condition to assingn different theme. e.g.

`function YOURMODULE_form_alter(&$form, &$form_state, $form_id) {
 if(SOME_CONDITION){
 $form['#theme'] = 'FORM_THEME1'
 }else{
 $form['#theme'] = 'FORM_THEME2'
 }
}`

---
Tags: forms, theming, uri
---


title: D7 Services node view mode

text:
# Question
Title: D7 Services node view mode
I am using the services module. When I call domain.com/json/node/3 is it possible to ask for a specific view mode of the node ?

Something like this ?

domain.com/json/node/teaser/3

Thanks!

# Answer
Nope, Drupal Services just return the node object by default. Looking at the end points in node\_resource.inc, it would seem it would not be hard to build thou.
> 2 votes

---
Tags: 7, services
---


# Question
Title: Difference between a bundle and a content type
Can somebody explain to me the difference between a content type and a bundle? Is the latter just a bundle for the entity node?

# Answer
> 7 votes
*Bundle* is a generic term that applies to every entity Drupal or third-party modules define; *content type* is a specific term that applies to nodes.
Since nodes and content types were introduced a way before Drupal 7, *content type* was the first concept introduced, which then got expanded into the *bundle* concept when entities were introduced in Drupal 7.

So, yes, a content type is a bundle for the *Node* entity.

# Answer
> 0 votes
A content type is just a bundle of the node entity.

---
Tags: entities
---


title: Restructure main menu markup

text:
# Question
Title: Restructure main menu markup
I need this structure to my drupal main-menu:

```
<div class="list-group">
  <a href="#" class="list-group-item active">
    Cras justo odio
  </a>
  <a href="#" class="list-group-item">Dapibus ac facilisis in</a>
  <a href="#" class="list-group-item">Morbi leo risus</a>
  <a href="#" class="list-group-item">Porta ac consectetur ac</a>
  <a href="#" class="list-group-item">Vestibulum at eros</a>
</div>

```

Im use bootstrap theme, and menu\_block module.

this is my template.php file, I need to remove the li tags.

```
<?php

/**
 * @file
 * template.php
 */

function bootstrap_subtheme_menu_tree__menu_block__main_menu($variables){
    //add class for ul
    return '<div class="list-group">' . $variables['tree'] . '</div>';
}
function bootstrap_subtheme_menu_link__menu_block__main_menu($variables){
    //add class for li
    //$variables['element']['#attributes']['class'][] = '';
    //add class for a
    $variables['element']['#localized_options']['attributes']['class'][] = 'list-group-item';
    //dvm($variables['element']);
    return theme_menu_link($variables);
}

```

# Answer
> 2 votes
**1. Using theme overrides.**

You can override theme\_menu\_link() and theme\_menu\_tree() in your theme.

However, you probably only want to target this one menu and not every other menu. To achieve this, you can use targeted overrides for theme\_menu\_link() and theme\_menu\_tree():

```
THEMENAME_menu_tree__MENU_NAME()
THEMENAME_menu_link__MENU_NAME()

```

Or (as you figured out yourself) there are specific overrides for menu\_block:

```
THEMENAME_menu_tree__menu_block__MENU_NAME()
THEMENAME_menu_link__menu_block__MENU_NAME()

```

Detail:

```
function THEMENAME_menu_tree__menu_block__MENU_NAME($variables){
    //add class for ul
    return '<div class="list-group">' . $variables['tree'] . '</div>';
}

function THEMENAME_menu_link__menu_block__MENU_NAME(array $variables) {
  $element = $variables['element'];
  // Omit all the submenu stuff, since this will only be used to display the top level.
  /*
    $sub_menu = '';

    if ($element['#below']) {
      $sub_menu = drupal_render($element['#below']);
    }
  */
  $link_options = $element['#localized_options'];
  $link_options['attributes']['class'][] = 'list-group-item';
  return l($element['#title'], $element['#href'], $link_options);
}

```

# Answer
> 2 votes
**2. With Menupoly (advanced users)**

An alternative solution is to use Menupoly with a MenuTheme implementation that will render links without the ul/li. You can think of this like a formatter for menus.

**When and why?**

Typically, the basic theme overrides as in the other answer are sufficient.
But there are some use cases where Menupoly can be preferable:

* You want to reuse the theme html in another project, or for another menu.
* You want to render the same menu more than one place, with different HTML. E.g. in the header you want only links + separator, but in the sidebar you want the usual ul + li. In this case, the targeted theme override won't cut it.

**Solution 1: Menupoly as a block**

Create a custom module.

Optionally, create a custom MenuTheme implementation, similar to this one. Or just use the existing one.

If you create your own, make sure that the class can be found with an autoloader, or put it in a file that is always included.

Then, implement hook\_menupoly() to define a menu block:

```
function MYMODULE_menupoly() {
  return array(
    'topnav_flat' => array(
      'menu_name' => 'main-menu',
      'depth' => 1,
      'menu_theme' => new menupoly_MenuTheme_FlatLinksWithSeparator(' | '),
    ),
  );
}

```

**Solution 2: Without a block.**

To skip the part with the block, you can directly do this in your theme.

Implement `THEMENAME_preprocess_page()`, and add this:

```
function THEMENAME_preprocess_page(&$vars) {
  $settings = array(
    'expand' => MENUPOLY_EXPAND_ALL,
    'menu_name' => 'user-menu',
    ... // more options possible
  );
  $html = menupoly_view($settings);
  $vars['topnav_flat'] = menupoly_view($settings);
}

```

Then, in your `page.tpl.php`:

```
..
<?php print $topnav_flat; ?>
..

```

---
Tags: theming, routes
---


title: Embed Views Map in Slider/Slideshow

text:
# Question
Title: Embed Views Map in Slider/Slideshow
I need to have a slider on my main page that has a number of images (taken from views), and also a map that slides. Can anyone recommend any tutorials on how to embed a block as one of the images in a slider or any other solutions to this? So far everything that I have seen is just for embedding images.

# Answer
You can use **Views slideshow** module :

> Views Slideshow can be used to create a slideshow **of any content (not just images**) that can appear in a View... Potential uses :
>
> * **News item** slideshow (such as the title, image and teaser of the last 5 news articles submitted)
> * The **last X number of X submitted** (images, videos, blog entries, forum posts, comments, testimonials, etc.).
> * Rotate **hottest new products**, contact links, share links, entire nodes, categories, image galleries, etc.

There are many tutorials links on the project page , i.e how to create a simple slideshow with some node fields.

Define the relationship between your images & maps ( taxonomy ? fields of the same node ? ...), set a view showing them, then display it as a slideshow.

If you **can't find how to join** your content in a view query, have a look at Multiple nodes in one slide using views slideshow or another module ...
> 0 votes

---
Tags: views, javascript
---


# Question
Title: How to add custom price for custom line items added using commerce customizable products?
I have created custom line items using "commerce customizable products" module by following the steps provided in this screencast. I want to add custom price for each added custom line item and it would be great if i could add/specify the price while creating that line item. Is there any way to do it? If not I will be glad to help to do so, All I need is proper guidance. This is a well known issue and solving it would be an awesome addition to this module.

Thank you in advance.

# Answer
I havent found anything for line-items per say, but found this module that might work

https://drupal.org/project/commerce\_pricing\_attributes
> 0 votes

---
Tags: 7, commerce
---


# Question
Title: How do I display a parent view term information when child terms exist?
I have two views set up: one that displays the image field, title, and description for each taxonomy terms in a vocabulary, and one that displays a grid of photos/nodes that are tagged with a taxonomy term. What I want is to always display the parent term image/description in the first View so that users can drill down to the children terms, and then ultimately click into the second view of photos/nodes.

For instance, the first View is made up of taxonomy terms associated with the taxonomy vocabulary "Gallery". Under gallery, I have the terms "Parties" and "Games". Parties has no children terms, but "Games" has "Sports" and "Other Games" as children terms.

I would like the Gallery View page content to be displayed this way:

\[parties\] \[games\]

Clicking "Parties" would bring you to a view page (the second View) that shows all of the photos/nodes tagged with that term. Clicking "Games" would take you to a View similar to the first View that shows the taxonomy fields for the child category, like so:

\[sports\] \[other games\]

Clicking on "Sports" or "Other Games" would take you to a view page that shows all of the photos/nodes tagged with that term, like the "Parties" page operates in the example above.

Make sense? Hoping someone here can point me in the right direction.

Thanks!

# Answer
> 1 votes
What you would probably want to do is create a view of the taxonomy terms that lists Parties, Sports, etc. On the fields to display, re-write the output to a link to categories/%1, which will take the term being listed as an argument, and make sure to un-check link to taxonomy page. For this view you should make the link something like "categories". Then, in the second view (or maybe just another page in the same view), make the link something like "categories/%" The % wildcard will take in the value of the taxonomy term form the page before. So when you click the link from the first page it will link you to the second view, where you can make a contextual filter that takes the taxonomy term given via the URL from the one clicked on the first page and have it list the terms based on that with a relationship.

# Answer
> 1 votes
It seems the main task is that you want to display two views per taxonomy term: Child terms, and associated content. There might be terms where you only have child terms but no associated content, and other terms where you have only associated content but no child terms. And there might be terms where you have both.

I usually do this with Display suite \+ Dynamic fields, or with views\_content\_ds. This gives you full control where the two views appear in your layout, and also allows to display additional fields.

1. Create a "Content pane" views display "Child terms", with a contextual filter "parent term" and argument input set to "Taxonomy term id".
2. Create a "Content pane" views display "Tagged nodes", with a contextual filter "referenced taxonomy term" based on the taxonomy term reference field, and argument input set to "Taxonomy term id".
3. Configure the taxonomy term page display to use Display Suite (by choosing a display suite layout).
4. Two options:

1. Create two "dynamic fields", and position them in the layout. Click the cog-wheel to let one of them display the child terms, and the other display the tagged nodes. (You will need to have ds\_extras enabled, and enable some stuff under the ds\_extras options, I think). OR
    2. Install views\_content\_ds, and the two Views displays will be available as fields automatically in the "Manage display" of the taxonomy term.
5. Optionally, you can display other fields from the taxonomy term entity along with the two views displays.
6. Not sure you need that, but Taxonomy display allows to configure how associated content is being displayed. I usually only use this to disable the core behavior, but then use the views\_content\_ds fields to actually display the associated content.
7. Optionally, you could use Entity aspect to have different view modes for different types of taxonomy terms. E.g. on one site I am using this to distinguish between "leaf terms" and "root terms".

A lot of this stuff could be done with Panels / Page manager, instead of Display suite + Entity aspect. I am obviously biased here, and like the latter more :)

Some of these steps could use more detailed instructions, but I think this would be too much for this answer.

# Answer
> 0 votes
Your idea wasn't completely intelligible, so I may be off the mark with this advice, in which case excuse me. But it sounds as if you want a taxonomy term view and separate content view displayed together, contextually filtered by the term id. If that's correct, it's very easy.

1. Create the **content view**, and set up your **fields**, **filters** and **sort** order.
2. Add a **contextual filter**, choosing **content has taxonomy term id**, choose your preferred **behaviour when the filter value is not in the url** (eg hide content) and specify **validation criteria**.
3. Note that if for any reason you want to use the term name rather than tid, you'll need to add a relationship, picking content: terms on node - and choose "taxonomy term name" as your contextual filter (as opposed to tid). If your term name includes spaces, ensure you check **"Transform spaces to dashes in URL"** them from the **More** section. This is a much trickier approach than simply using tid, but I include it here just in case!
4. Set a path for your view, including a **%** wherever the tid will appear (in your case probably **taxonomy/term/%**).
5. For the taxonomy term view, begin by adding a **contextual filter** for **taxonomy term tid** before configuring its **no results behaviour** and **validation**.
6. Add a **relationship** for **taxonomy term parent term**.
7. Add your desired fields, configuring each **to use the parent term relationship** and save.
8. No need to worry about creating a page display for this. Leaving it as Master or using an attachment display is fine.
9. Return to the **content view**. In **Header**, add **Global View Area** and choose the taxonomy term view you've just created, making sure you check "**inherit contextual filters**". In doing this you'll embed your parent term and its info in it's child terms' content displays.

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


title: List style article in drupal 7

text:
# Question
Title: List style article in drupal 7
I'm trying to create a content type that allows me to post multiple images from an external database in this sort of style: http://www.newageman.co.uk/14-time-travelling-celebrities

In an ideal world this is what I would like my group of fields to look like in the article creation screen.

Any idea how I would achieve this using best practices? To post articles like this I'm currently using a piece of php code but it's confusing for my contributors, so would like to use fields. I've never made a module or custom field before.

Essentially I am trying to recreate what this PHP does: The input

```
<?php $folder = ''; ?>
<?php $location = ''; ?>
<?php
$title01 = '';
$content01 = ''; ?>

```

The output

```
<div class="image_article">
<span id="title"><span id="num">1. </span><?php echo "$title01"; ?></span>
<p><img src="/sites/default/files/foldered_images/<?php echo "$folder"; ?>/<?php echo "$location"; ?>_01.jpg" /></p>
<p><?php echo "$content01"; ?></p>
</div>

```

# Answer
> 0 votes
You can create a multiple-value field collection field.

In the "field collection item" entity type, you can create the fields for the image and body text.

Afaik, the built-in image field type does not really work with external images. This problem is discussed here: Linking image field to an external URL

And now for the output.

Under "manage display" of the field collection item, use Display suite, with ds\_extras enabled. Choose "Reset" as the layout (which will disable all divs that wrap the field collection item). Then create a ds custom field using token, and use it to put the other fields into your custom html.

Or alternatively, override field-collection-item.tpl.php in your theme, or better, override field-collection-item--field-xyz.tpl.php. I am not sure which exact template suffix to use to target the specific field collection item type. You should play around a bit and then we can update the answer based on your findings.

# Answer
> 0 votes
As an alternative to field collection, you could simply use a text field (or just the body field) with image embedding.

I typically use a combination of IMCE and CKEditor or BUEditor. For external images you might not need IMCE, but you want to configure the text editor of your choice to provide a button for embedding of (external) images.

---
Tags: 7, entities
---


# Question
Title: Show a menu item as expanded if on a certain node type
I have a News menu item, which then has children. I need it to be expanded if it is on a news article page, but not expanded on other certain pages.

I'm not sure which hook to use. i've played around with menu\_link\_alter but i can't figure out how to choose the item i'm on in order to process it. Maybe this isn't the correct way.

Any ideas please?

# Answer
You can try one of these:
> 0 votes

# Answer
I would go with the context module.

You can set a context to be active whenever a certain content type is shown, in this case, an 'Article'.

You can then set the reaction to 'menu' and choose an item which will get an active trail. You can then target using CSS or more likely, it's probably already expanded.

https://drupal.org/project/context
> 1 votes

---
Tags: routes
---


# Question
Title: Drupal Calendar, why some events appear as "all day" events even if they are not "all day" events?
Why some events appear as "all day" events even if they are not "all day" events in Calendar Views?

As you can see, these events have just a start date defined at 00:00. But they are not "all day" events:

# Answer
> 1 votes
This is probably an old "bug" in calendar: https://drupal.org/node/881224 Have you tried to give your dates an end date?

---
Tags: views, datetime
---


# Question
Title: Content Type with People (list of people) in Select List to Choose From
diving deep into Drupal 7 as a noob and wondering how can I create a field (select list) in a new content type that pulls in all the users in the system? I'd like to be able to associate certain content with a person, not necessarily as the author, but as the "person in charge of this area" for example. I'd like to show the persons name and some other info from the "people" area of the Drupal 7 core.

I am thinking I should use the people area rather than create a new content type for people. I added new fields to the "new user" form.

Any thoughts or ideas?

EDIT:::

Did find https://drupal.org/project/references module that seems to work great. However, I still would like to know if using People area is best for storing all users / people associated with my Drupal site. Thanks :)

# Answer
Personally I often use Entity Reference, but I think this answer is the same regardless of the choice between Entity Reference and References modules. Both modules allow you to define a relation between two entities. If you need a reference from a node to another entity, this is a good solution.

> I still would like to know if using People area is best for storing all users / people associated with my Drupal site.

When you say "People area", I think you mean Drupal's built-in user management. Users are fieldable entities, just like nodes. If you need to store data about a person, you can use both the user entity or define a "Person" node type. If the persons you're adding should be able to log in, now or in the future, you definitely want to create users. If they will never need to log in (for instance, you're building a site about people in ancient Rome), I would choose nodes.
> 2 votes

---
Tags: 7, nodes, users
---


# Question
Title: Hiding fields when creating node and showing them only when editing
I'd need to enable editing of certain fields only when the node they're assigned to already exists. Therefore I need to disable them on node create form and enable them on node edit form.

I though I'd do it the same way as with users where you have two separate forms (user profile a user register) and therefore can use settings array on field instance (at least I believe it works this way).

```
...
'settings' => array(
   'user_register_form' => 0,
),
...

```

The problem is you can't do it with nodes as nodes don't have separate forms for edit and create.

I know I can do it directly via altering CONTENTTYPENAME\_node\_form (changing the access status of the fields to false or unseting them completely when the node does not yet exist) but it doesn't seem to be the very best solution (It doesn't feel systematical to unset it on form alter hook).

BTW: I know that someone asked similar question but he hasn't received any answers.

# Answer
This is certainly without a doubt a job for hook\_form\_alter() and quite easy to accomplish, eg, something along the lines of:

```
function YOURMODULE_form_alter(&$form, &$form_state, $form_id) {

  switch ($form_id) {

    case 'foo_node_form':

      if ($_GET['q']=='node/add/foo') {

        // we are creating a node of type foo so do stuff to the form one way here

      } else {

        // we are editing a node of type foo so do stuff to the form another way here

      }

      break;

   // other forms here

  }

}

```
> 3 votes

---
Tags: nodes, forms
---


title: inserting content into node using field

text:
# Question
Title: inserting content into node using field
I am really stuck and need some advice, I'd like to know how I can go about doing this, simply put:

A website contributor enters a value into a field which is placed into the html.

eg. I have say two fields that will determine an image name and the file type. In field 1 the user enters \[ABC\], in field 2 the user enters \[123\].

The output of this would be `<img http://www.example.com/[ABC].[123] />`

I have never worked with my own custom modules/fields etc before, a point in the right direction would be a big help.

# Answer
> 0 votes
To do this in a template, 1. create a file inside your /sites/all/themes/YOURTHEME folder, called node--CONTENT\_TYPE.tpl.php. 2. copy the contents of node.tpl.php into that file. 3. add something like the following to the template file, where you want to print the image:

```
<img src="http://example.com/<?php
    print $node->YOUR_FIELD_1[$node->language][0]['value'] .
    '.' .
    $node->YOUR_FIELD_2[$node->language][0]['value'];
    ?>
 alt="..." ... >

```

Another possibility (probably better), would be to use the filefield sources module, and let the users upload the image to your drupal site by pasting the url.

---
Tags: entities
---


title: Drupal Caching and hook_init

text:
# Question
Title: Drupal Caching and hook_init
So I was considering using hook\_init() to do stuff but I'm not understanding what it means when it says that "This hook is not run on cached pages." Oh really?

So as an experiment I made sure caching was turned on for anonymous users, and went to the site in a browser window where I was not logged in. So I was definitely getting some cached pages, right? Then I added this to my module

```
function mymodule_init() {
  $num = rand(0,1000);
  drupal_set_message($num);
}

```

I figured if the hook wasn't being run, then I shouldn't get a random number each time I viewed the page. I wasn't sure if I should even get a message or not! But I am getting a different random number each time. So what exactly does it mean when it says that the hook isn't being run on cached pages? And when is it NOT ok to use this hook? Sorry if it's something obvious I don't know.

**-- edit --**

Thanks for the answer. I should have realized the drupal\_set\_message thing was causing the page not to be cached. So I went back and I also tried adding java script like this:

```
function mymodule_init() {
  $num = rand(0,1000);
  drupal_add_js(array('mymodule' => array('rand' => $num)), 'setting');

  $path = drupal_get_path('module', 'mymodule');
  drupal_add_js($path . '/js/mymodule.js');

  echo $num;
}

```

And in my javascript file:

```
(function ($) {
    Drupal.behaviors.mymodule = {
        attach: function(context,settings) {
            var num = Drupal.settings.mymodule.rand;

            alert(num);
        }
    }
})(jQuery)

```

It still seems to alert a random number every time. So is drupal\_add\_js also disabling the cache? I even tried using a simple echo statement in hook\_init() and it still seemed to echo a random number. So are all these things causing the page not to be cached or does hook\_init() still get run somehow?

# Answer
A couple things here:

1. hook\_init() will be run on the first hit on the page, eg, if it's not in cache already, it will be run and then the page will be cached. But...
2. A page will not be cached if there are any drupal messages, so, when you call `drupal_set_message()` it sets `drupal_page_is_cacheable(FALSE);` and the page isn't cached.

ADDITION:

Regarding your additional code with respect to Javascript: adding this code in verbatim here does **not** exhibit the random behavior you see on your site; eg; here the same number appears until the cache is refreshed.

Which made me think about this. Check your cache times:

If the times are set to `<none>` I see the behavior you seem to experience, but when they are set to anything else, eg:

then I don't.
> 6 votes

---
Tags: 7, caching, hooks
---


# Question
Title: Send out welcome e-mail in users selected language
Whenever I create a new user, I want to send a welcome e-mail to the user. This email is translated in both English and Chinese using the Internationalization module.

But when I check Chinese for a user, it still sends out the email in English.

The only option is to switch to the Chinese interface and then create the user, is there a way that when I select Chinese it will send out the email in that language? Regardless or not the interface is in that language?

# Answer
This is not a answer but can't fit this to a comment. From what I see in the source of user.module, the function that fires drupal\_mail favors user's preferred language.

```
3495 function _user_mail_notify($op, $account, $language = NULL) {
3496 // By default, we always notify except for canceled and blocked.
3497 $default_notify = ($op != 'status_canceled' && $op != 'status_blocked');
3498 $notify = variable_get('user_mail_' . $op . '_notify', $default_notify);
3499 if ($notify) {
3500 $params['account'] = $account;
3501 $language = $language ? $language : user_preferred_language($account);
3502 $mail = drupal_mail('user', $op, $account->mail, $language, $params);
3503 if ($op == 'register_pending_approval') {
3504 // If a user registered requiring admin approval, notify the admin, too.
3505 // We use the site default language for this.
3506 drupal_mail('user', 'register_pending_approval_admin', variable_get('site_mail', ini_get('sendmail_from')), language_default(), $params);
3507 }
3508 }
3509 return empty($mail) ? NULL : $mail['result'];
3510 }

```

Note the $language param defaults to NULL and, in line 3501, if the param is NULL, it will get the user's preferred language. Moreover, none of the function calls has the third argument, so in all cases, user\_preferred\_language() should be used to determine the language.

So,if you have correctly translated the message, with correct t() function's syntax, message should be translated.

However, rather than translating the entire message, I'd suggest a dirty hook\_mail\_alter() hack to translate line by line with t() or completely different messages on 2 languages.
> 2 votes

# Answer
**@Triskelion** pointed the correct way for me and i just give more details that i solved this problem by doing following :
**First**, enable the mail edit module from http://drupal.org/project/mail\_edit. After that add some email templates for languages by going **admin/config/system/mail-edit**
**Next**, go to **/admin/config/regional/language/configure** and check the 'Follow the user's language preference.' option
**Finally** I tested to create new account by admin and I received an welcome email by the language that i set for that user before.
> 2 votes

# Answer
Did you tried Rules module? It may help you send emails, depending on language selected...
> 0 votes

# Answer
@Triskelion Once you configured your website like Stone Vo explains, you migth notice that the tokens in your emails refer to your website in the wrong language. You might need to install a core patch called "Implement language aware tokens for one time login link and cancel link" https://drupal.org/node/1754162
> 0 votes

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


# Question
Title: Auto Increment - Order/user numbers not changing
I've executed the following via phpmyAdmin but nether the order nor user numbers change.

```
ALTER TABLE 'users' AUTO_INCREMENT = 1025;
ALTER TABLE 'commerce_order' AUTO_INCREMENT = 1025;

```

I checked inside 'commerce\_order' and the AUTO INCREMENT is set to: 1025(order numbers should change). When i check inside the 'users' table, AUTO INCREMENT is NOT available(why?).

I've cleared the cache. Shouldn't this be working? Drupal7

Thank you for your help!

# Answer
The users table does not work with AUTO INCREMENT in Drupal 7. Instead, the ids are generated in PHP.

See What could cause uids to not be numbered consecutively?
> 2 votes

---
Tags: 7, database
---


title: Defining a PHP variable using a field

text:
# Question
Title: Defining a PHP variable using a field
Is is possible to define a PHP variable using a field?

eg. In the field a contributor would enter \[ABC\]

which would translate to: `<?php $VARIABLE = '[ABC]'; ?>`

which would be repeatedly used in the node as:

```
<img src="http://www.example.com/<?php echo "$VARIABLE"; ?>/image_01.jpg/>
<img src="http://www.example.com/<?php echo "$VARIABLE"; ?>/image_02.jpg/>

```

etc

# Answer
You could create a simple text field to store the string, and then a custom formatter to render it as an image. Then under "Manage display" for the content type, you choose the formatter you just created.

If you don't want to create the custom formatter programmatically, you could use the Custom formatters module.

If you want to use the value of the text field for more than one output element, you could create Display suite custom fields using this value e.g. as a token.
> 1 votes

# Answer
What you're asking for (linking remote images) can be done the File Field Sources module. This way for instance drupal will "copy down" the remote image locally and you may use Image Styles and other things to theme it (locally). If the remote image is deleted or the URL changes you're website in turn will not break.

> FileField Sources is an extension to the FileField module. The FileField module lets you upload files from your computer through a CCK field. The FileField Sources module expands on this ability by allowing you to select new or existing files through additional means, including:
>
> * Re-use files by an auto-complete textfield
> * Attach server-side files uploaded via FTP
> * Transfer files from a remote server (cURL required)
> * Paste a file directly from the clipboard (Drupal 7 only)
> * Select existing files through the IMCE file browser
>
> Although FileField Sources provides several built-in sources, it can be extended by any module through an API for creating new sources. Users can toggle between any of the available methods for selecting a file.

See these Additional File Field Sources add-on Modules.

Retrieving the remote image to a local version is the "typical" Drupal pattern here. If you want the specific drop-downs for certain remote paths or folders -- try to extend the feature-set by using their API to write your own little dialog similiar to the default ones (see the project page) and have its form values be your desired criteria.

**EDIT:**

it looks like the AmazonS3 module can work with the FileFieldSources module from this issue https://drupal.org/node/1585188. It stores/retrieves files to your S3 account. I still think you can use the FileFieldSources API to build whatever interface you need to poke, prod and otherwise fetch data from Amazon for your images and feeds. In short I would try to use the AmazonS3 module + FileFieldSources as the groundwork to create you're own custom UI for your contributors.
> 0 votes

---
Tags: entities
---


# Question
Title: Strange problem with enabling/disabling modules
I just moved my Drupal 7 site over from one host to another. At first, everything seemed to be working just fine, but I keep getting this strange problem when dealing with modules.

The installation appears to go without a hitch, and it shows up in the modules list. It also shows up under the correct path in /sites/all/modules/$modulename. However, the problem I get is two-fold:

* Attempting to go to the configuration page for the module does virtually nothing. It just takes me to the related menu for whatever admin category that particular module falls into. (For example, Disqus would take you to Web Services rather than a Disqus configuration panel).
* Disabling the module doesn't remove it from the configuration menus, either. I've tried running cron, flushing my caches, and even using the registry\_rebuild scripts.

This also affects my themes now. I can't seem to get any of my new themes to appear in the directory when I upload them into my /sites/all/themes/ directory. I can remove themes manually, and they disappear at least. But, as you can imagine this is all a very frustrating problem. I think it may possibly be a permissions error, but frankly I really have no idea.

# Answer
> 1 votes
My first thought was permissions, but I don't think that incorrect file permissions would result in the kind of problems you're seeing.

Have you checked that the server has all the same extensions installed for PHP? If you've still got access to the old server, put a `phpinfo()` page on both server and compare the extensions that are available to see if any are missing.

# Answer
> 0 votes
This is a really old thread but thought it was worth adding the following.

I had this problem recently on a local dev install (using Acquia Dev Desktop, by the way). Turning off the Memcache module resolved my issue.

---
Tags: 7, installation
---


# Question
Title: How to resize an uploaded image based on the longest side?
I can't seem to figure out how get ImageCache to resize an image based on the longest side.

Desired behaviour:

```
upload image 800x532 --> resize image to 400x266 (landscape)
upload image 532x800 --> resize image to 266x400 (portrait)

```

Is this possible with ImageCache? If not, how can I achieve this? Aspect ratio must be preserved.

# Answer
> 1 votes
To follow up on this question; ImageCache Actions now offers a feature called Aspect Switcher which allows for different image styles based on the original images aspect ratio, if it's portrait or landscape.

---
Tags: 6, media
---


# Question
Title: Minimizing the time taken for entity_load while using for apachesolr indexing
I am working on a site with a specific node type that has close to 50 fields, most of which are taxonomy term references, a couple of node references and a few conventional text and integer values. Almost all of them accept multiple values. While indexing the nodes with apachesolr I observe that most of the time in the indexing process is consumed by calls made to `entity_load` function, almost 3.5 - 4 minutes for loading 200 nodes when checked with timer based logging while the total indexing takes about 50 seconds more (4.5 minutes overall).

Adding a custom 'status back' with `hook_apachesolr_entity_info_alter` to query and return the node status directly instead of loading it, I was able to negate the `entity_load` in one instance, however another function `apachesolr_index_entity_to_documents()` where the drupal node to solr document conversion takes place had `entity_load` calls consumed more time since they could no longer use the cached result of the status callback.

My aim is to reduce the time taken for indexing to at least half of what it currently which now is completely dependant on the time taken by `entity_load`. Since `entity_load` is one of the critical aspects of Drupal 7 around which functions like `node_load`/`node_load_multiple` are derived from I'm unable to find a different option to proceed or determine ways to improvise entity\_load usage.

Note: The site functions such that these nodes get created almost all the time and none of the fields can be pruned out, negating the option of pre-loading the entities. Also the site uses entity cache module with memcache

I'm hoping to get suggestions on improving the node load time programatically with entity\_load or using alternative approach to load the respective entities to bring down my indexing time.

# Answer
> 2 votes
You could very well form an array of the nodes to be indexed after the query execute and do a single entity\_load instead of doing a entity\_load for each and every node separately and I hope that will reduce the time and below is the patch that could help you

```

# Index: apachesolr/apachesolr.index.inc

--- apachesolr/apachesolr.index.inc     (revision 9348)
+++ apachesolr/apachesolr.index.inc     (working copy)
@@ -636,9 +636,21 @@
     $query->condition('aie.entity_type', $entity_type);
   }
   $query->range(0, $limit);
-  $records = $query->execute();
-  $status_callbacks = apachesolr_entity_get_callback($entity_type, 'status callback');
+  $records = $query->execute()->fetchAll();
+  foreach ($records as $node_record) {

+    $entities[] = $node_record->entity_id;

+  }
+  $arr_entity = entity_load($entity_type, $entities);
+  foreach ($records as $record) {

+    $record->status = $record->status && $arr_entity[$record->entity_id]->status;
+    $rows[] = $record;
+  }
+  // Commenting as we have already used the entity_load
+  /*$status_callbacks = apachesolr_entity_get_callback($entity_type, 'status callback');

   foreach ($records as $record) {
     // Check status and status callbacks before sending to the index
     if (is_array($status_callbacks)) {
@@ -651,7 +663,7 @@
       }
     }
     $rows[] = $record;
-  }
+  }*/
   return $rows;
 }

```

As you have said most of your fields are taxonomy term it is idle that you check the term\_load method and also whether the term\_data table is properly indexed.

# Answer
> 1 votes
You should first figure out is why is entity\_load so slow. What additional hooks are running inside of it that slows it down? An example of a module causing a slow entity\_load is the metatag module. I have a patch for it in this issue: https://drupal.org/node/2183203 If you can find what is slowing down your entity\_load that would be the most helpful.

If there are no slow performers inside entity\_load, make sure that it is loading the entities in bulk and not one at a time.

If all else fails, one of the better looking alternatives is direct database queries at this point if the database layer has already been optimized. I've been working on some code that extends EFQ which I call EntityFieldQueryExtra. I got the idea for it from the apache solr module as apache solr also extends EFQ. For this use case you would only add in the fields that need to be indexed and I would use executeEntityBuild() as that will give you output similar to entity\_load; just dpm() what is returned from executeEntityBuild() to find it.

If it is a volume issue (lots of entities to be processed), HTTPRL could be helpful if you want to roll your own solution or if you want to try a module that uses it like Apache Solr Parallel Indexing.

---
Tags: performance, search, entities
---


title: Modify template.php for custom HTML

text:
# Question
Title: Modify template.php for custom HTML
It was suggested the below script in template.php might work to assist in creating a modified HTML page.

```
<?php
function YOUTHEME_preprocess_html (&$vars) {
if (module_exists('path')) {
$alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
if ($alias != $_GET['q']) {
$template_filename = 'html';
foreach (explode('/', $alias) as $path_part) {
$template_filename = $template_filename . '__' . $path_part;
$vars['theme_hook_suggestions'][] = $template_filename;
      }
    }
  }
}
?>

```

I tried it but broke my site. Do I need to copy just the code minus the php brackets? Use my exact subtheme name to replace YOURTHEME and then create my html--foo.tpl.php to correspond?

# Answer
you can try `function themeName_preprocess_page(&$vars, $hook)` to override theme theme\_hook\_suggestions. More detail you will find here.
> 0 votes

---
Tags: theming
---


title: My site crashed

text:
# Question
Title: My site crashed
My site crashed trying to enable Commerce modules (like 10 at a time). Now I get white screen of death. How do I restore my site? I know it had only 64MB PHP memory, does increasing it will restore the website or is the database already broken and game over?

# Answer
> 2 votes
Increasing PHP memory limit to 192MB solved the problem.

---
Tags: 7, commerce, wsod
---


# Question
Title: Drupal Form API submission to create node
I have created a custom form in my module using **Form API**, the problem is it's kind of **huge** form (it consists lots of **fields** and **fieldsets**), I wanted to save the form as node after submission. I can create content type and map those fields, but the form is huge. I am looking for alternative way to do this and by the way I have "Taxonomy terms" in my select list in my forms, I want them to be preserved as well while saving in node.

Thank you.

# Answer
If you want to save the form as a node you have to add all the fields to the node type, because otherwise the database won't have tables to put all the data in.

Then, if the form you have made maps directly to the node type, then there really isn't any need for you to have a custom form, just use the normal node add page.

If you then want things to look or function a bit differently you could form alter the form to tweak things and get them the way you want them.

That is the approach I would recommend (without actually knowing what you are trying to achieve, so I am making assumptions).

The alternative is to stick with your custom form, but also make a custom database table to store all the data and enter the data into that, but then you miss out on all the modules that are already out there that provide extra functionality for nodes, you have to write your own integration with views if you want to use that, etc.

You could also do a custom entity type or use the data module, but the trouble you would go to doing this is pretty similar (or even more so) to what you would have to do if you just set it up as a node type.
> 2 votes

---
Tags: webforms, forms
---