# Question
Title: External authentication module prevent further authentication
I am trying to make an external authentication module for Drupal, and I have one almost done, except that after I successfully authenticate the user (or throw an error), Drupal's standard authentication kicks in and adds error messages to the form error stack.

Here is a simplified version of my code:

```
/**
* Implements hook_form_alter().
* We replace the local login validation handler with our own.
*/
function XXXX_form_alter(&$form, &$form_state, $form_id) {
  // Add our validation function to the form
  if ($form_id == 'user_login' || $form_id == 'user_login_block') {
    $form['#validate'][] = 'XXXX_authenticate';
  }
}

/**
* Custom user authentication function
*/
function XXXX_authenticate($form, &$form_state) {

  $name = $form_state['values']['name'];

  if(XXXX_is_valid_user()) {
    user_external_login_register($name, 'XXXX');
    return true;
  } else {
    // in the full module, this would be set in another function.
    form_set_error('user', t('The XXXXXX error'));
  }
}

function XXXX_is_valid_user() {
  // return false;
  return true;
}

```

This is for demonstration purposes, only. It is trying to log the user in no matter what the user types (because the actual module is too complicated to put in its' entirety).

The problem is that user\_external\_login\_register works correctly, except that If XXXX\_is\_valid\_user() returns false, the standard invalid login error appears before the actual error, and if the login succeeds, the standard invalid login error appears on a page where the user is logged in.

I have tried form\_clear\_error, but either it's not clearing the error properly, or an additional authentication is being added after this form submits. I think this module would work correctly if there was a way to either prevent further authentication, or replace the authentication code currently in place with this code.

# Answer
> 1 votes
You can override the default login function, in a hook\_form\_alter. You're trying to append to $validators, below I'm overriding it with:

```
$validator = 'dew_auth_id_authenticate_validate';

```

So my example code is:

```
/**
 * This function alters the default login form we are presenting to the student.
 *
 * It overrides the typical drupal login authentication scheme and injects our
 * own localized version.
 */
function _dew_auth_user_login_form_alter(&$form, &$form_state) {
  global $conf;
  $saveForm = $form;
  $form = array();

  $status_type = is_esci_open_for_submissions() ? 'availability_message_open' : 'availability_message_closed';
  $form['availability_message'] = array(
    '#markup' => _dew_auth_availability_message_html($status_type, TRUE),
    '#weight' => -10,
  );

  # overrides the default validator.
  foreach ($saveForm as $key => $value) {
    if ($key == '#validate') {
      $form[$key] = array();
      foreach ($value as $validator) {
        if ($validator == 'user_login_authenticate_validate') {
          // If we progressed down to this level of nested Alters, we have
          // #auth-destination. #auth-destination is a key I add to the $form
          // to know which login mechanism I want to call and use. The site
          // has 3 login mechanisms.
          $type_of_login = $saveForm['#auth-destination'];
          switch($type_of_login) {
            case 'id':
              $validator = 'dew_auth_id_authenticate_validate';
              $form['#action'] = '/?q=id/login&destination=%3Cfront%3E';
              break;
            case ESCI_ENDUSER_TYPE:
              $validator = 'dew_identity_service_authenticate_validate';
              break;
            default:
              break;
          }
        }
        $form[$key][] = $validator;
      }
    }
    else {
      $form[$key] = $value;
    }
  }
  $form['name']['#title'] = ($type_of_login == 'id') ? 'Department Username' : 'CAMPUS ID';

  if ($type_of_login == ESCI_ENDUSER_TYPE) {
    $form['links']['#markup'] = '<div><a target="_blank" href="https://secure.network-diagnostics.edu/netid_diags/">Unable to Login? Verify your Campus Access Credentials</a></div>';
    $form['links']['#weight'] = 199;
  // For Departmental logins just hide the default drupal links to reset passwords.
  } else {
    unset($form['links']);
  }
}

```

Then functions like `dew_identity_service_authenticate_validate` and `dew_auth_id_authenticate_validate` are just copy/paste "clones" of user\_login\_authenticate\_validate from drupal core with some 3-5 extra lines of custom logic -- they also in turn use custom copy/pasted drupal core `*_user_external_login_register` functions to properly create users depending on the method the user was created on the website.

Note this level of customization is good for say Drupal 7. But will have to be re-created if you move to Drupal 8.

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


# Question
Title: dsm vs drupal_set_message vs debug vs dpm vs watchdog for developing
`dsm` requires the devel module but I guess you have that installed anyway if your developing modules. `debug` and `watchdog` having the advantage that is writes to the log file.

I can see the advantage of `watchdog` on a live site so users don't get bugged by messages while debugging the site. but is harder to use ( you have to write more code )

`dsm` and `dpm` are short and simple to use but don't always show output.

So are I think `debug` is the best way to go while developing modules (on your test server). But apparently it doesn't handle array's that well.

Which one do you use and why do you think that is the best / better or should I use the different functions for different purposes?

# Answer
> 2 votes
If devel is available, i use mostly `dpm`. If not, I use `drupal_set_message(print_r($array, true))`. This helps me in the most cases. If both are not available or visible, I use the Watchdog.

# Answer
> 1 votes
`watchdog` has always been a preference for me. Most of the situations my troubles involve checking values before submit or redirects and using `dpm` and `dsm` to check debugging info in the message tab seem a bit out of place. Checking the logs in the admin end and having the ability to filter seems a better thought for debugging.... but that's just me.

# Answer
> 0 votes
I realize this is extremely late, but another option is the devel\_debug\_log module. It still requires the devel module, but it allows you to log your devel related messages.

---
Tags: 7
---


# Question
Title: Replace existing content type with feature
Once upon a time a made a terrible mistake on one of the test sites by not enabling feature module but cloning database along with content types data from my local dev machine (`drush sql-sync @local @test`). This `test` site went live with feature disabled, but content type exists and has content.

Is it somehow possible to enable this feature at this stage to override existing content type and keep it's content?

# Answer
Yes, it is possible to enable the feature. Enabling the custom feature module does not change anything on the site. The feature will have a different state depending on if the code in the feature module differs from what is stored in the database. A quick way to check the state of your features is the drush command:

```
drush fl

```

If your custom feature's components are simply the content type, and assuming field\_base and field\_instance components, then enabling the feature will tell you if they are either:

1. Overridden: the components (content type settings, field settings) are different in the database and the custom feature code.
2. Default: the components in the custom feature code are the same as the settings in the database.

If your custom feature is "Overridden" you have two options:

1. Update: *drush fu featurename* \- Updating your feature will update the custom feature code with the settings that are stored in the database.
2. Revert: *drush fr featurename* \- Reverting your feature will restore the feature's component's settings in the database to what is stored in the custom feature module's code.

So, either way, this shouldn't affect your node content. Unless you revert your feature components thus affecting the content type or field settings.

See the drupal.org documentation for more on using features & drush: https://www.drupal.org/node/960926
> 2 votes

---
Tags: 7, features
---


# Question
Title: Is there a way to make a unique view template for a specific type of view?
I needed to edit the views-view-unformatted.tpl.php for a specific view, however I'd rather it not apply to every view. Is there a possible way to make a unique view template to select from? Rather than rewriting every view that uses views-view-unformatted?

# Answer
Yes it is. Open the Views Admin UI and in Theme Information there is a list of available template files

For example in my website it is:

You can use any of them.
> 1 votes

# Answer
You can copy 1 of the default templates provided by views (the source code is in the /views folder) into a template file named specifically for that 1 view.

This is explained in this other answer: https://drupal.stackexchange.com/a/11472/3279
> 1 votes

---
Tags: views, theming
---


# Question
Title: Sorting a new column on task list on open atrium
Hey I have added two new column's to a task list. One is a Due Date (Date chosen by calendar) and the second is number of days out (integers). The other column's that are added by default are able to be sorted, however the two new columns only have a black title.

Is there a way to add the ability to sort these new columns?

# Answer
> 0 votes
I figured it out.

1. Go to adminstration/structure/views/
2. Click Edit for Open Atrium Worktracker
3. In Filter Criteria click add, then select column of choice
4. Click the "Expose this filter to visitors, to allow them to change it"

---
Tags: distributions
---


title: Add html code to a content block

text:
# Question
Title: Add html code to a content block
I need to insert an html code into a content block. As the html code has some javascript links and css, I've done a module to include all the references in the .info file. The problem is that I don't know how to insert the html code in the .module file.

This is the html code:

```
    <html>
  <head>
    <link rel="icon" type="image/png" href="favicon.ico">
    <title>Aldizkari Elektronikoa</title>
  </head>
  <meta charset="UTF-8" />

  <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no">
  <meta http-equiv="cleartype" content="on">
  <meta name="description" content="Aldizkari Elektronikoa"/>
  <meta name="keywords" content="" />
  <meta name="author" content="" />
<!-- Development mode -->
  <link rel="stylesheet" href="assets/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="assets/stylesheets/style.css">
  <link rel="stylesheet" href="assets/stylesheets/secciones.css">
  <link rel="stylesheet" href="assets/stylesheets/mediaQuery.css">

  <body class="no-js">

    <section id="sec">
      <div id="secciones"></div>
      <div id="secciones-control"></div>
    </section>

    <script src="assets/libraries/jquery-1.9.1.js"></script>
    <script src="assets/libraries/mustache.js"></script>
    <script src="assets/libraries/jquery.imagesloaded.min.js"></script>
    <script src="assets/libraries/jquery.mobile-1.3.1.min.js"></script>
    <script src="assets/libraries/verge.min.js"></script>
<!-- Development mode -->
    <script src="assets/data/langs.js"></script>
    <script src="assets/data/services.js"></script>
        <script src="assets/data/events.js"></script>
    <script src="assets/data/templates.js"></script>

  </body>
</html>

```

As you can see most of the code are references to javascripts and css. But what I need is to include the to the module, because this is the part that shows what I need form my page.

Do you know if the is any hook for this? Or can I do in an other way to add this html structure to the content block?

I hope you can help me,

Thanks

# Answer
> 3 votes
You can always create a block in your module. You'll need hook\_block\_info, hook\_block\_view.

Example:

```
function hook_block_info() {
// This example comes from node.module.
$blocks['syndicate'] = array(
'info' => t('Syndicate'),
'cache' => DRUPAL_NO_CACHE,
);

return $blocks;
}

```

Then in hook\_block\_view:

```
function hook_block_view($delta = '') {
// This example is adapted from node.module.
$block = array();

switch ($delta) {
  case 'syndicate':
    $block['subject'] = t('Syndicate');
    $block['content'] = myfunction();
    );
    break;
 }
  return $block;
 }

```

Then you just need to return what ever out put you want in myfunction, and you should be set. Check out the links for more info, full block api is also here.

# Answer
> 2 votes
and attach the js and css

```
function my_module_block_view($delta = '')
{
  if($delta == 'my_module_delta')
  {
    $block = array
    (
      'subject' => t('My block title'),
      'content' => array
      (
        '#markup' => '<p>' . t('This is some text that will go in the block.') . '</p>',
        '#attached' => array
        (
          'js' => array('path/to/file.js'),
          'css' => array('path/to/file.css'),
        ),
      ),
    );
    return $block;
  }
}

```

---
Tags: 7, blocks
---


# Question
Title: append settings.php during profile installation
I would like to add lines to my settings.php during my custom installation. I'm using some `$conf['...']` to match external content to my drupal and i would like not to do this by modifying directly the file. During my custom install i want to use the external content to have a fully operational website after running my script.

Do you have an idea how i can do this ?

Thanks.

# Answer
Checkout this post about Collecting and writing configuration settings to setting.php from an install profile.

It describes how a custom task (via `hook_install_tasks_alter()`) was injected into the installation profile to display a custom form and, upon submission, how `drupal_rewrite_settings()` can be used to inject the custom settings into **settings.php**.
> 2 votes

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


# Question
Title: How can I list all the pages of a Drupal site in csv format?
My goal is to get a .csv file list of the titles/urls for all "pages" in a Drupal site, including all Views, panel pages, and nodes, etc.

## Potential incomplete solutions:

1. Using the xmlsitemap module to generates xml then convert it to .csv format. This gets content types and menu links, but not views pages or panel pages or other cases. The downside here is that it only outputs the urls. It'd be nice to also have the titles.
2. Querying menu\_links or menu\_router tables. These list all the drupal paths, but not node paths or anything that requires the variable substitutions, ie "node/%".

I'm curious if there is a more straight forward way to do this. Any thoughts?

# Answer
> 2 votes
I wrote a dirty script to query the node, menu\_router, and menu\_links tables: https://gist.github.com/dooug/b102a683d4e4854defba

This could be improved upon. The upside is that it includes "path,title" of all nodes, panel pages, view pages, etc. The downside is it includes all admin pages. Also, it includes lots of duplicates between the menu\_links and menu\_router tables. Please fork with your suggestions.

---
Tags: 7
---


# Question
Title: How do I change submit URL for exposed search filter?
I've created view using Search API Views with two different displays.

First *Page* display (`by_terms`) and with the following options:

> *Page settings*: Path:/taxonomy/term/%
>
> *Contextual filters*: Category: Term ID (indexed)
>
> *Filter criteria*: Search: Fulltext search (exposed)

And second *Content pane* display (`panel_pane`):

> *Use Panel path*: Yes
>
> *Filter criteria*: Search: Fulltext search (exposed)
>
> *Link display*: Custom URL set to `search/results`

---

When I open page with 1st display `/category/list/name` (which is alias to `/taxonomy/term/123`) and submit Search input, it goes to `/category/list/name?keywords=test`.

When I open page with 2nd display (`/search/results`) and submit Search input, it goes to `/taxonomy/term/%2A?keywords=test` which is weird.

Ideally I would like the submit to end up in both cases at `/search/results?keywords=test`.

---

Is there any way of controlling the submit URL of the landing page for exposed filter? How?

# Answer
> 1 votes
Seems that specific problem is with Panels.

The exposed form is basically a block which have no sense of context, therefore setting the URL from the view pane doesn't affect exposed filters in a block.

Therefore one way to go is to use `hook_form_alter`:

```
/**
 * Implements hook_form_alter().
 */
function foo_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'views_exposed_form') {
    $form['#action'] = current_path();
  }
}

```

Or:

```
/**
 * Implements hook_form_views_exposed_form_alter().
 */
function foo_form_views_exposed_form_alter(&$form, &$form_state) {
  if ($form['#id'] == 'views-exposed-form-foo-default') { // Or: if ($form['#action'] === '/foo')
    $form['#action'] = '/bar';
  }
}

```

Or by extending Views handler, for example:

```
class foo_handler extends views_handler_field {

  /**
   * Add to and alter the form.
   */
  function views_form(&$form, &$form_state) {

    // Submit to the current page if not a page display.
    if ($this->view->display_handler->plugin_name != 'page') {
      $form['#action'] = current_path();
    }
  }

}

```

Alternatively content pane can be used which can override the path, instead of using exposed form. See this issue for more details.

---
Tags: 7, views, forms, search
---


title: Wrong caching of embedded views block

text:
# Question
Title: Wrong caching of embedded views block
I am having trouble with the Cache API in Drupal 8. I embedded a views block with pagination through a field preprocess function into a node. When caching is off, I can normally use the pager and will always get the right results, but once caching is one, every block page (e.g. /node/1?page=2) shows the same block content rendering the pager useless.

I assume my hacky method is preventing the node cache to let the view in the field handle it's own caching, hence I always get the content from the page I visited first after clearing cache.

This is how the view is embedded:

```
function foo_preprocess_field(&$variables) {
  $field_name = $variables['field_name'];

  if($field_name === 'bar'){
      foreach ($variables['items'] as &$item) {
        $item['content'] = views_embed_view($item['content']['#markup']);
      }
   }
}

```

# Answer
I think you need to add the pager context to item #cache
> 0 votes

---
Tags: views, blocks, caching, entities, 8
---


# Question
Title: Checkbox to make billing information same as shipping information does not work for Anonymous users
For Anonymous users, the **My Shipping information is the same as my Billing information** checkbox doesn't reload the Shipping Information checkout pane.

I have the checkbox working for authenticated users, but when an anonymous user is going through checkout, the ajax callback never fires. The `#element_validate` function `'commerce_customer_profile_copy_validate'` is never called. The `#ajax['callback'] => 'commerce_customer_profile_copy_refresh'` is never called.

Watching the network tab in Chrome, the ajax request is never fired.

The checkbox is checked by default and nothing happens when I un-check it. The Shipping Information pane doesn't expand and show the shipping information form fields via ajax.

Is there some permission I'm missing that would allow anonymous users to use this checkbox?

# Answer
> 0 votes
Turns out I was kicking myself on this one. I forgot I had some custom `hook_js_alter` code in my `template.php` that removes unnecessary js from the page for anonymous users. This was done to improve site speed and because my custom theme didn't require these default Drupal js libraries.

```
function theme_js_alter(&$javascript) {
  $logged_in_user = user_uid_optional_load();
  if(!in_array("authenticated user", $logged_in_user->roles)) {
    foreach($javascript as $key => $value) {
      unset($javascript[$key]);
    }
  }
}

```

However I do need these javascripts on commerce checkout pages apparently, so I added a `request_path()` check for `checkout` and `cart` pages so the js would not be `unset`.

I confirmed the **My Shipping information is the same as my Billing information** checkbox now works for anonymous users.

---
Tags: ajax, commerce
---


# Question
Title: Custom Node Template not inheriting page.tpl.php
In my theme, I have page.tpl.php and page--node--1.tpl.php.

When page--node--1.tpl.php is rendered, everything in page.tpl.php is lost. I only want page--code--1.tpl.php to replace the $content line in page.tpl.php and inherit everything else in page.tpl.php.

How can I do this? Do I need to first create a template for the content type?

Below is what I have in my template.php

```
if (strtolower($vars['template_files'][0]) == "page-search") {
    $vars["template_files"] = array();
    $vars["template_files"][] = 'page-search';
} else {
    if ($vars["template_files"][2] != 'page-node-edit') {
        if (isset($vars['node']) && ($vars['node']->type == "mytheme_page" || $vars['node']->type == "person" || $vars['node']->type == "blank_page")) {
            if ($vars["template_files"][2] == "page-front") {
                $vars["template_files"] = array();
                $vars["template_files"][] = 'page-home-mytheme';
            } else {
                $vars["template_files"] = array();
                if ($vars['node']->type == "blank_page") {
                    $vars["template_files"][] = 'page-blank';
                } else {
                    //print "made it here";exit;
                    $vars["template_files"][] = 'page-mytheme';
                }
            }
        } elseif ($alias == "sitemap") {
            $vars["template_files"] = array();
            $vars["template_files"][] = 'page-blank';
        }
    }
}

```

# Answer
> 1 votes
You cannot do this with those templates.

Only one "page" template will be used. You could try using one "page" template, and one "node" template: https://api.drupal.org/api/drupal/modules!node!node.tpl.php/7

but the node template won't allow you to modify the page template.

---
Tags: 7, theming
---


# Question
Title: Use of a global variable ('submission counter')
I'm trying to construct a registration form (of a node) wich stores serial (ascending) values in a hidden field. The form is open to unregistered users. I made it with rules and variable (every time a node of type xxx is saved, the global variable is +=1 and stored in the correct field), but... If two nodes are submitted at the same time, this variable can be dupplicated. Any ideas on how avoid this behaviour? Thank you.

# Answer
I would recommend implementing the Serial Module:

> This module provides an auto-increment (serial) field.
>
> Unlike Drupal's built-in auto-increment node ID, which is global and shared by nodes belonging to all content types, serial fields are managed per content type (D6) / entity (D7). For example, the serial field of an Invoice instance will generate a unique sequential number (starting at 1, then 2, etc.) exclusively for Invoice instances.
>
> The allocation of serial numbers by this module is atomic. In other words, the serial values are unique even when multiple instances of the same content type / entity are created simultaneously.
> 1 votes

---
Tags: rules
---


# Question
Title: How to change "Secure Login Module - Secure base url" without login?
I have installed Secure Login with Secure base URL setting on a live site, and clone that into a different domain for testing. The "/user" page has no login form because the Secure base URL should be different. How can I change this URL without login? Where is this data in phpMyadmin?

# Answer
It's in the variables table. Variable name is securelogin\_base\_ssl, value like `s:4:"theurl";`
> 1 votes

---
Tags: 7, users
---


# Question
Title: How to dynamically consume external RSS feed and display content Drupal 7 with feeds module?
Is it possible to consume an external RSS feed with the feeds module - without turning the content into nodes - and display it in a view? I attempted to do this using the aggregator module as described here: External RSS Feed in View and it looked great at first, but then I discovered this bug where the aggregator does not update. https://www.drupal.org/node/2344795. I am now trying to do the same thing with the feeds module, but I don't see a way to have it not create nodes out of the data. I just want it to be dynamic and not create content nodes on my site. Thanks for the help.

# Answer
> 2 votes
I have sucessfully used Views XML Backend in situations like this.

---
Tags: feeds
---


title: Hiding a field in a node conditionally

text:
# Question
Title: Hiding a field in a node conditionally
I have a field that's a term reference field. If it has a value 'x' I want it to show on the node page. However if it has the value 'y' I don't want it to show. Is this possible?

# Answer
> 2 votes
The Field Formatter Conditions module should do the trick. It's currently in beta and doesn't work on excluding fields based on their own value.

However, if you change function `ffc_get_condition_fields` on line 145 in **ffc\_conditions\_info.inc** such that `$exclude_current_field` is `FALSE`.

```
function ffc_get_condition_fields($context, $exclude_current_field = FALSE) {
...
}

```

it will let you hide field display when it has a certain value.

---
Tags: theming, nodes
---


# Question
Title: Drupal schema API not supporting MySQL date data type?
I am getting this error with my existing database:

> no Schema type for mysql type date.

I did some research and it seems like schema does not support date type in MySQL. What would you guys suggest I replace it with? I'm presenting income statements and balance sheets on my site and I need to have some sort of date reference of each row(otherwise I wouldn't be able to figure out 2009 earnings versus 1999).

What other options are available?

# Answer
You *could* define it yourself, have a look at http://drupal.org/node/159605#comment-1674678.

You should however only do this if you are sure that you will only ever use/support MySQL.

Portability with date data types among different databases is almost impossible. Drupal 7 initially had date types defined but they were removed again because there is simply no way to make them work consistently across multiple database types.

You might want to look at http://drupal.org/project/date, I'm pretty sure that allows to use dates that can not be mapped to a UNIX timestamp.
> 2 votes

# Answer
I found a better solution than ignoring the message. I was able to stop getting it by making Schema happy.

When I imported a table from Access to MySQL and then adopted it for the Data module ("Structure \> Data tables \> Adopt tables") I got the same message for two table fields, one that was a "Yes/No" in Access and the other that was a "Date/Time". The importation from Access had converted those fields to types "bit(1)" and "datetime", respectively, in MySQL. Drupal's data schema does not have bit types or temporal (date/time) types, so the Schema module issued those messages.

My solution was to convert those table fields to types that are consistent both with Drupal's schema and with the data in my table. I converted the "bit(1)" field to type "tinyint(1)" and the "datetime" field to type "double". (The "datetime" data type is the same as the "double" type except that it's designated to represent a date and time.)

I checked that the conversion had not changed the values of the data in the table. For the datetime field, this was done using the SQL function "convert(\<field name\>, datetime)". The check was successful; the before and after values were the same.

Then I went back to "Data tables" and adopted the table with the converted data types. No more complaints from Schema!
> 0 votes

---
Tags: 7, database
---


# Question
Title: Multiple results being returned using search for same node
I have a view-based search in my site. I notice that when I type a phrase like so "search terms" or even just search terms (no quotes) into the search box it returns all results that match that exact phrase as you'd expect BUT it also returns multiple versions of the same node!

I checked to make sure they are the exact same node and I think they are. One of these nodes is returned 6 times. I clicked on each linked result and the pathauto-altered URL is exactly the same for each. So for some reason it's returning it 6 times and I don't know why. Other nodes get returned fewer times. Some don't get returned more than once. I've checked some of the items that get returned multiple times in the mysql database and they appear to only be in there once...

I've cleared caches and run cron/re-indexed site...nothing.

I've got into 'find content' and looked to see if there are multiple copies of the nodes. Nope just the one.

And if, when I search, I just search for one word in the profile it only returns it once.

However, when I search for multiple terms I get multiple copies. I've reviewed the SQL of the returned view and it doesn't look like anything funky is going on.

Any idea why this might be happening?

# Answer
> 2 votes
There is a join in the query that is causing multiple instances of the same node to be returned.

Edit the view and under the "Other" section click on Query settings and choose Distinct.

The description says:

*"This will make the view display only distinct items. If there are multiple identical items, each will be displayed only once. You can use this to try and remove duplicates from a view, though it does not always work. Note that this can slow queries down, so use it with caution."*

Here is the "Other section" in the view settings:

**EDIT:**

If this doesn't work then try the Views Distinct Module that Sage mentions in his comment below.

---
Tags: views
---


# Question
Title: Display term description below a field widget based on the selected option on node edit form
I am trying to show a block (or the term description) on the node edit form when a user selects the term.

An example:

User is creating a node with a "location" vocabulary. They select their state (parent term), then a region in the state. A block or the term description will display directly below the dropdown for the parent term (their chosen state). If they select another state, another block or term description will come up for that state.

Basically each term in the vocabulary will have subtle but different submissions guidelines and I would like to inform the user during the node creation process as to the guidelines for each state.

I am not sure if I should create a "state submission guidelines" content type then Entity Reference it, build a view and embed it or try to get the term description or another field attached to the term to show. How does one make dynamic node edit forms?

I am running Drupal 7, Display Suite, Views, CSHS, Rules as the main stack.

EDIT: I am also using Conditional Fields if that can be utilized.

Thanks.

# Answer
> 2 votes
You can add an `#ajax` property to the state field in a `hook_form_alter()` and then include the taxonomy term description as a form item below the state field if state is set. See the ajax examples in the examples module or post here is you have any problems.

I don't think there is any need to use a block.

---
Tags: 7, views, theming, forms, ajax
---


title: Getting Xdebug to work with Dev Desktop

text:
# Question
Title: Getting Xdebug to work with Dev Desktop
I'm trying to get xdebug to work with Dev Desktop.

I am following the instructions in this guide:

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

and I still get the message, "waiting to connect" well after it should have already connected and the site is showing in my browser.

My zend\_extension also starts out as:

```
zend_extension="C:\Program Files (x86)\DevDesktop\php5_5\ext\php_xdebug.dll"

```

And I'm not sure which version to get off of here:

http://xdebug.org/download.php

I'm somewhat lost - I have no problems getting xdebug to work on OSX or Linux, but I seem to be having real trouble getting it to work on Windows

# Answer
> 0 votes
Well to address your concern about which version to download, if the instructions state **Program Files (x86)** then you want the **32-bit** version of the dll. I'm not sure VC++ 9 or VC++11 should matter. As far as thread safe, you should check `phpinfo()` in your DevDesktop environment to make sure it's thread safe or not.

The XDebug site has a nifty wizard form where you can copy/paste your `phpinfo()` into it and it will point you to the version you need.

---
Tags: debugging, acquia-dev-desktop
---


# Question
Title: Displaying HTML entities in title through a view
I have a site (D7) where I need to have HTML entities in the title like the copyright, trade mark signs with the subscript tags. Like:

**Product name<sup>®</sup>**

The solution at the node level is simple using the page.tpl.php:

```
<?php print html_entity_decode($title); ?>

```

But in a view no matter how I try to format the title it will always return it like

```
Product name<sup>®</sup>

```

I try a formatter, but they don't reach the title. Any other ideas?

# Answer
> 1 votes
Yes! You need to add the attribute `'html' => true`. This is a link property in Drupal 7. If you render any link in Drupal 7 and want to add some extra HTML inside it you need to set `array('html'=>true)`.

# Answer
> 0 votes
This can be achieved using templates: In case of a view page, the template used will be page--.tpl.php. Ex: If the path to the page is awards then the page template file is page--awards.tpl.php. The title can be edited as required in the template file.

In case of a block, the title can be edited using the block.tpl.php. Refer to this link for creating the template file for a specific block. Here are the other references for this topic.

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

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

Hope this helps.

# Answer
> -1 votes
I had the same problem, and I solved it, but I think my method is not perfect. I created another filed, called "title2", text field with "Full HTML". Make Title2 = title, and view it in views, it will be html\_entity\_decoded. Sorry for my n00b english.

---
Tags: 7, views
---


# Question
Title: Views Escaping Special Characters in URL
I am creating a view with a list of titles that link to the relevant full article that is also displayed via a view.

The view that contains the article has a contextual filter which contains the Title and the of the views is "mysite.com/%"

So the article that is named "hello world" will be found at "mysite.com/hello-world"

However if the article has the ' special character in it for example "Children's Book" the link that I create to point at the article will be "mysite.com/Children%26#039;s-Books" which brings back an empty result.

# Answer
> 1 votes
With the Pathauto module you can strip the special Chars. Here is a quote about it (from the module's project page):

> ... automatically generates URL/path aliases for various kinds of content (nodes, taxonomy terms, users) without requiring the user to manually specify the path alias. This allows you to have URL aliases like /category/my-node-title instead of /node/123. The aliases are based upon a "pattern" system that uses tokens which the administrator can change.

# Answer
> 1 votes
You can configure under Contextual Filter \> More setting. There are some transform settings.

# Answer
> 0 votes
You can try to override the template for your view, and there escape the string that is sent with urlencode(); assuming that you have the necessary Drupal experience to do that.

---
Tags: views
---


# Question
Title: Pictures are not responsive on Firefox & Internet Explorer, Using grid on views
I am building a site with a lot of pictures. On Google Chrome Everything is working fine.

On FF & IE, If I am just viewing the content & picture not through a view - everything is fine. But, the pictures are not responsive when I am presenting the picture using views. I read & saw many tutorials regarding breakpoints Module, Picture Module, and more. On the picture field on views, I chose the right Formatter, picture group and Fallback image style.

I am using zen sub-theme, but the problem also occur on other themes I tried.

If there are other modules that can fix this issue, or you can help me solve the situation currently, it will be great. Any Ideas?

Thanks!

# Answer
> 1 votes
I use the Adaptive Image module. It gives you an adaptive behavior you can select when on Admin\>Configuration\>Image Styles. In other words, you'll need to create an image style with the new adaptive behavior (it should appear in the pick list after you install the module), or alternately, add the adaptive behavior to existing image styles. Once you've done that, you just need to use the adaptive image style in the view, either by adjusting the image field settings, or by changing the settings on the display type fields if you're using content or rendered entities. For the most part, I found that doing the above steps gives me responsive images, but I sometimes have to tweak my CSS also.

# Answer
> 1 votes
I think I solve the Problem, but I am not sure if this is a good solution. All the pictures were responsive on Google Chrome, But not on Firefox & Internet Explorer.

I found out that I was using the Grid format on the view, and I think that what caused the problem. After I have installed the View-Fluid-Gird-Module, and chose that on the view, all the designs and the pictures in all browser became fluid.

Still, only the pictures on the Google chrome are responsive and can shrink, but I think the fluid module is enough for most of the devices.

Note: when I am NOT using the grid/fluid grid on a view, but let's say "unformatted list" -\> all the pictures on all browsers are responsive (shrinks when needed)

I will be happy to get insights, and maybe someone can find a better solution..

# Answer
> 0 votes
After trying all sorts of codes and fidles, this simple edition on my CSS did the trick:

```
img {width: 100%;}

```

Where you wish your images to resize, define them without adding the `width` parameter (sizing to original from source); and then, if you want to fix their size, add the `width` parameter on SRC you wish (on the style="", the regular width="" will not work). Also, if it's an inline image on your paragraph, simply wrap it inside a div and align that div to whatever side you'd like. Reeeeally simple!

It works both for Google, Firefox and IE. Cheers!

PS: Thanks for the editors for fixing my comment!! ;)

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


# Question
Title: How can we go to particular #div on a page using drupal_goto()?
There is one scenario where I want to go to particular div on page using `drupal_goto()`.

Below is my code:

```
$path = '#textarea_comment'.$alert_id;

$options = array('bid' => $bookingid.$path );

drupal_goto("/fsaclientservice/viewreservation", $options);

```

In the above code the `#` is get replaced with `%23` in URL and due to this I am not able to redirect to particular div on a page.

I have tried :

```
encodeurl()
rawencodeurl()

```

But still the URL is coming as `%23` etc. Please help.

# Answer
You just use the second argument the function takes.

```
drupal_goto("fsaclientservice/viewreservation", array('fragment' => 'add-reservation-note-form'));

```

Notice that in the code I wrote here, `'fragment'` is a literal string you need to use as it is, and `'add-reservation-note-form'` doesn't have any leading `#`. The documentation for that parameter is in `url()` because `drupal_goto()` calls that function to build the URL.

> `$options`: (optional) An associative array of additional options, with the following elements:
>
> * 'query': An array of query key/value-pairs (without any URL-encoding) to append to the URL.
> * 'fragment': A fragment identifier (named anchor) to append to the URL. Do not include the leading '#' character.
> * 'absolute': Defaults to `FALSE`. Whether to force the output to be an absolute link (beginning with http:). Useful for links that will be displayed outside the site, such as in an RSS feed.
> * 'alias': Defaults to `FALSE`. Whether the given path is a URL alias already.
> * 'external': Whether the given path is an external URL.
> * 'language': An optional language object. If the path being linked to is internal to the site, `$options['language']` is used to look up the alias for the URL. If `$options['language']` is omitted, the global `$language_url` will be used.
> * 'https': Whether this URL should point to a secure location. If not defined, the current scheme is used, so the user stays on HTTP or HTTPS respectively. TRUE enforces HTTPS and `FALSE` enforces HTTP, but HTTPS can only be enforced when the variable 'https' is set to `TRUE`.
> * 'base\_url': Only used internally, to modify the base URL when a language dependent URL requires so.
> * 'prefix': Only used internally, to modify the path when a language dependent URL requires so.
> * 'script': The script filename in Drupal's root directory to use when clean URLs are disabled, such as 'index.php'. Defaults to an empty string, as most modern web servers automatically find 'index.php'. If clean URLs are disabled, the value of $path is appended as query parameter 'q' to `$options['script']` in the returned URL. When deploying Drupal on a web server that cannot be configured to automatically find index.php, then `hook_url_outbound_alter()` can be implemented to force this value to 'index.php'.
> * 'entity\_type': The entity type of the object that called `url()`. Only set if `url()` is invoked by `entity_uri()`.
> * 'entity': The entity object (such as a node) for which the URL is being generated. Only set if `url()` is invoked by `entity_uri()`.
> 6 votes

---
Tags: redirection, uri
---


# Question
Title: How to change access callback of user entity when entity module is installed? (how to make sure my alteration is the last)
I want to change the 'access callback' of user entity to my own access function or at least alter the original function 'entity\_metadata\_user\_access'.

The problem is that 'entity module' which I need because of others' module dependencies already alters the 'user entity information' and changes the 'access callback' to its own function 'entity\_metadata\_user\_access' and so when I alter it with my module, the entity module re-alters it to 'entity\_metadata\_user\_access'.

To make it more clear, the entity module is alters the entity info after me which causes that the final value of the callback is not mine (does not come from my alteration) but its and therefore the callback is wrong.

I know that I could modify the module itself but I honestly don't want to do that because it makes later updates painful.

# Answer
Take a look at `hook_module_implements_alter`, you can change the order of the hooks called by Drupal and make sure your `alter hook` is called as last one.

```
function YOURMODULE_module_implements_alter(&$implementations, $hook) {
    if($hook === 'entity_info_alter') {
    $group = $implementations['YOURMODULE'];
        unset($implementations['YOURMODULE']);
        $implementations['YOURMODULE'] = $group;
    }
}

```
> 3 votes

# Answer
Here is a complete working example of overriding `entity_metadata_user_access`:

```
/**
 * Implements hook_module_implements_alter().
 */
function YOURMODULE_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'entity_info_alter') {
    $group = $implementations['YOURMODULE'];
    unset($implementations['YOURMODULE']);
    $implementations['YOURMODULE'] = $group;
  }
}

/**
 * Implements hook_entity_info_alter().
 */
function YOURMODULE_entity_info_alter(&$entity_info) {
  $entity_info['user']['access callback'] = 'YOURMODULE_entity_metadata_user_access';
}

/**
 * Overrides entity_metadata_user_access function.
 */
function YOURMODULE_entity_metadata_user_access($op, $entity = NULL, $account = NULL, $entity_type = NULL) {
  // Include Entity API module's logic
  $return = entity_metadata_user_access($op, $entity, $account, $entity_type);

  // Do your own logic here:
  // $return = $return || ...

  return $return;
}

```
> 4 votes

---
Tags: 7, entities
---


# Question
Title: How to extract data from DB into fields?
How would I go about extracting the data from a DB into fields? I would like to display information on a page using Views, but the information isn't on the website, instead it is in a separate database. Is this possible?

I get that in order to use Views I need to have fields, but how do I extract this?

# Answer
> 1 votes
If you just want the content, you can use Feeds as Patrick said but this will replicate the content of the other database as entities in your Drupal site.

If you really want views connecting to a remote database, this question looks like a duplicate of:

https://drupal.stackexchange.com/questions/3275/how-do-i-display-an-external-database-data

This will help you make Drupal "aware" of the external db:

http://drupal.org/node/18429

# Answer
> 0 votes
If you can get the data from the database in CSV or OPML format, you can use the Feeds module. It's quite complex to set up, but it does have decent documentation.

# Answer
> 0 votes
Consider the Forena module (disclosure: I'm a co-maintainer of it), here is a summary of it:

> Forena is built of the idea of using SQL to get data out of a database and use XHTML and CSS to format it into web reports.
>
> Various DBMSs are supported, such as Oracle, MS Sql, Postgress, SQLite, MySQL, any PDO compliant DBMS ... And there are quite some reasons for considering Forena.

Refer to the example in my answer to How to retrieve data directly from a Drupal database to get an idea about using Forena, i.e.:

* establish a DB connection.
* a **custom** SQL query.
* a **custom** report.

Forena can also be used for importing data (from an external database ...) into a Drupal site, using its integration with the feeds module. Or you can use its integration with the views module to create views about data retrieved from such external database.

Refer to the available community documentation for (way) more details, and/or the sample reports and graphs in the demo site (which processes data stored in an SQLite database, one of the supported DBMSes).

# Answer
> -1 votes
The data module would help you to achieve what you are looking for.

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

> ... helps you model, manage and query related sets of tables. It offers an administration interface and a low level API for manipulating tables and accessing their contents. Data module provides Views integration for displaying table data and Drupal search integration for searching table content.

---
Tags: views
---


# Question
Title: What does it mean to "Use rendered output to group rows?"
Is the alternative to use raw output?
To what grouping is it referring?
Does this affect the sort order of rows?

# Answer
> 5 votes
Say you have a node with a taxonomy term, then a normal list would look like this

* Title: A, Term 1
* Title: B, Term 2
* Title: C, Term 1
* Title: D, Term 3
* Title: E, Term 2
* Title: F, Term 1
* Title: G, Term 3

If you group them on the term, you would instead get something like this

* Term 1

+ Title A
    + Title C
    + Title F
* Term 2

+ Title B
    + Title E
* Term 3

+ Title D
    + Title G

Rendered is not related to raw/safe values. It's just a way of explaining that it's the rendered (displayed) values that are used as grouping field.

# Answer
> 4 votes
This question is pretty old, but I was looking for the same thing just recently. Since the question wasn't really answered in previous posts, here's what this setting does - let's say you have a list of nodes grouped by date. Normally you'd get something like this:

* 12 January 2015

+ Title one
    + Title two
* 10 January 2015

+ Title three
* 24 December 2014

+ Title four
* 14 December 2014

+ Title five

But if you override date field in your view settings or using template to display just month and a year and then check “Use rendered output to group rows”, you will get this:

* January 2015

+ Title one
    + Title two
    + Title three
* December 2014

+ Title four
    + Title five

Note that nodes are grouped by months and years and not full dates, thanks to your overridden settings.

If you didn't check “Use rendered output to group rows”, you'd get this instead - nodes would be still grouped by original full date values, only labels would change:

* January 2015

+ Title one
    + Title two
* January 2015

+ Title three
* December 2014

+ Title four
* December 2014

+ Title five

Hope it clears some things.

---
Tags: views
---


# Question
Title: filter by taxonomy term = taxonomy term of referencing nodes
I have a node type 'hotels'. These nodes have a reference to a vocabulary 'regions' and a field 'hotel\_images'.

And I have a node type 'region\_page' with also the reference to the vocabulary 'regions'. In these nodes I integrate a view with images of the field 'hotel\_images'.

This view should be filtered by the 'regions'.

In case the node (type: region\_page) is set to term 'xy' of the vocabulary 'regions' - only images of hotels for which the term 'xy' is also set should be displayed.

How can I do this?

# Answer
If there is no specific requirement to use taxonomy terms to create the relationship between 'hotels' nodes and 'region\_page' nodes, I recommend to use the Entity reference module instead.

In your use case, you likely want to attach an Entity reference field to the 'hotels' content type, that allows the content editor to point to a node of the content type 'region\_page'.

If I understand it correctly, you already have a View attached to your 'region\_page' content types' display. Assuming you're using the EVA: Entity Views Attachment module, you should add `Content: Nid` as your contextual filter in the particular View, create a relationship using `Entity Reference: Referencing entity` and then use this relationship for outputting the field 'hotel\_images'.

In this way, when viewing a 'region\_page' node, the View will show all images that are stored on 'hotels' nodes that have a reference to the particular 'region\_page' node.
> 0 votes

# Answer
I assume you're using the EVA: Entity Views Attachment to attach a View to your 'region\_page' content types' display, that you're required to use taxonomy terms to create a relationship between your 'hotels' and 'region\_page' content, and that your vocabulary is named 'Regions'.

In the View, use `Content: Nid` as your contextual filter and add the `Content: Taxonomy terms on node` as a relationship. Then, add `Taxonomy term: Content using Regions` as an additional relationship and mark it required. In the remainder of this answer, I assume that the identifier of this second relationship is 'field\_regions'.

The 'field\_regions' relationship can be selected for outputting the field 'hotel\_images'. You probably want to add a filter criteria using `(field_regions) Content: Type (= Hotels)`, to prevent the output of row(s) from the content type 'region\_page' that have the same taxonomy term selected (i.e., the 'region\_page' node that is currently being displayed).
> 0 votes

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


# Question
Title: For Drupal 7, is there a hook debug mode equivalent to the theme debug mode?
As a beginning developer, it seems like I spend a significant percentage of my time googling to find out what hook to call in order to modify something before it renders.

In the drupal 7.33 release, the `theme debug mode` was introduced, which provides contextual information in the page's HTML to theme developers and can be accessed by setting the `theme_debug` variable to `TRUE`.

Obviously there is no `hook debug mode` supported in core, but is anyone aware of a module that would provides contextual information about attempted hook calls, similar to how `theme debug mode` displays theme suggestion attempts?

Specifically, I am wondering if there is a module that would generate a list of every call to `drupal_alter()`, `module_invoke_all()`, or `module_invoke()`, along with the `$type`, `$module`, and/or `$hook` arguments supplied to these functions.

# Answer
You could create a custom module and use hook\_module\_implements\_alter which takes two arguements - $implementations and $hook.

Try this:

```
function MODULE_module_implements_alter(&$implements, $hook) {
  if ($hook == 'form_alter') {
    print_r($implementations);
  }
}

```

This will print out a list of all the implementations, in order, for hook\_form\_alter.
> 1 votes

---
Tags: 7, debugging
---


title: Articles listed in custom order

text:
# Question
Title: Articles listed in custom order
I have a Drupal **7.31** installation.

I have 3 rows in homepage, in which are listed 3 articles for each of them. Here a partial screenshot of `Edit View` for the first row, in which **Sort criteria** actually is set to "*Publishing Date*".

My customer asks me to be able to directly re-arrange the order and I found something about the "DraggableViews" module. I tried to follow two guides (DraggableViews and Custom Sort Drupal Content with the Draggable Views Module) without success.

Reasons are both:

1. Options and settings that I found in my installation are different from which are listed in tutorials
2. In both cases, I have to change "`Format`" in "`Table`" but doing so results in a wrong display template also in the website, corrupting layout. So I have to remain with "**Unformatted List**" for output.

It's not important that custom order is made with Drag&Drop, an order specified with dropdowns could be ok, but how to not affect view display, but only order?

# Answer
You can maintain a weight field with list option enabled for your content type and sort your view from your weight(an integer). In views sort criteria section put the weight criteria top if there are any others. Same answer I gave here
> 1 votes

# Answer
You could try the Node Queue Module, which will allow you to completely control what shows up in your view and in what order.

Basically, you add a nodequeue, add your three pieces of content to the queue and set the order. The nodequeue can automatically create a view for you (configurable), which you can then customize any way you want.

I've used the Weight module and definitely prefer node queues.
> 1 votes

# Answer
I (also) highly recommend using the Draggable views module – and since it can actually be a bit difficult to get the first steps going here's some basics that should help:

* Configure your (fields) view as you like. Be sure to add the field `Content: Nid` to the list and check `Exclude from display` on the next screen.
* When you're done *clone* that view and set the Format of the clone to `table`. I usually name it the same as my fiest view and append a *"\_sort"* to the name to that I know how is who. This will be your client's interface to sort the entries.
* Add the `Draggableviews: Content [Provide a draggable functionality.]` to the list of fields to your *\_sort-table* and then rearrange the fields' order so that the draggable field is first in the list.
* Add `Draggableviews: weight` to the sorting criteria of both views. Choose your \_sort-table under `Display sort as` to connect them.

This is basically the workflow i use everytime I install a sortable list view. I actually use quite a lot of them. Even for '*events*' etc. draggable views *can* make sence since sometimes the client e.g. wants the "current" event before the "upcoming" event, even though that woudn't be in coreect chronological order. Anyways – I hope I didn't miss any important details.
> 1 votes

# Answer
You use a separate view to organise the order of your nodes. So create table view to organise the view and link this view to the management menu and give the view a URL like admin/structure/yournameofview (this will appear under the structure menu for your client)

Once you have organised your nodes, go back to your “live” view and apply the draggable weight to the sort order.

You may need to create a relationship for this to work.
> 0 votes

---
Tags: views
---


# Question
Title: How to set proper permissions for drush rsync
I have a weird problem here. When I use drush sync for my remote server, Drush changes permissions for the uploaded files to the name of the remote user for both the user and the group on the system.

The remote server is an Apache-FPM install where the name & group of webroot files have to be owned by vu2003:vu2003. Is there a way to achieve this with the **aliases.drushrc.php**?

Here Is my aliases file:

```
$aliases['live'] = array(
    'uri' => 'pts1.tk',
    'root' => '/var/www/virtual/pts1.tk/htdocs',
    'remote-host' => 'pts1.tk',
    'remote-user' => 'publisher',
    'os' => 'Ubuntu',
    'path-aliases' => array(
    '%drush' => '/usr/share/php/drush',
      '%drush-script' => '/usr/bin/drush',
      '%dump-dir' => '/tmp',
      '%files' => 'sites/default/files',
      '%private' => '/var/www/virtual/pts1.tk/000_private',
     ),
    'databases' =>
      array (
        'default' =>
        array (
          'default' =>
          array (
            'driver' => 'mysql',
            'username' => '[placeholder]',
            'password' => '[placeholder]',
            'port' => '',
            'host' => 'pts1.tk',
            'database' => '[placeholder]',
          ),
       ),
     ),
     'variables' => array(
        'site_name' => 'Drupal',
      ),
     'command-specific' => array (
       'sql-sync' => array (
         'no-cache' => TRUE,
       ),
     ),
  );

 $aliases['default'] = array(
      'root' => '/var/www/d7',
      'uri' => 'drupal.dev',
    'os' => 'Ubuntu',
    'path-aliases' => array(
    '%drush' => '/usr/share/php/drush',
      '%drush-script' => '/usr/bin/drush',
      '%dump-dir' => '/tmp',
      '%files' => 'sites/default/files',
      '%private' => '/var/www/html/private',
     ),
    'databases' =>
      array (
        'default' =>
        array (
          'default' =>
          array (
            'driver' => 'mysql',
            'username' => '[placeholder]',
            'password' => '[placeholder]',
            'port' => '',
            'host' => 'localhost',
            'database' => '[placeholder]',
          ),
       ),
     ),
     'variables' => array(
        'site_name' => 'Drupal',
      ),
     'command-specific' => array (
 'sql-sync' => array (
         'no-cache' => TRUE,
       ),
     ),
  );

```

# Answer
The easiest solution would be to set 'remote-user' =\> 'vu2003', and set up the ~/.ssh/authorized\_keys for that user to allow the rsync to run.
> 1 votes

---
Tags: drush
---


title: Disable admin menu for specific page

text:
# Question
Title: Disable admin menu for specific page
Is there a way to disable the top admin menu (not default toolbar), for a particular page? I am not looking for a JS or CSS workaround, but a proper solution such that the rendering of the admin menu does not happen.

Thanks and help appreciated...

# Answer
> 0 votes
OK, thanks for your replies everyone. But for this specific problem, `admin_menu_suppress` actually works perfectly. Idiot that I am, previously, I was calling this function from my page tpl. Hence, the js and css were already getting included even before the content was rendered. However, when I followed the prescribed way of calling the function for each of the page callbacks where I want the admin menu to be excluded, it worked perfectly.

Check the documentation of this function for more details.

Hope this helps somebody...

# Answer
> 0 votes
You can assign your admin menu to a block, and have that block disabled on certain pages.

# Answer
> 0 votes
The module\_load\_all function loads all of the enabled modules. this is its code:

```
function module_load_all($bootstrap = FALSE) {
  static $has_run = FALSE;

  if (isset($bootstrap)) {
    foreach (module_list(TRUE, $bootstrap) as $module) {
      drupal_load('module', $module);
   }
   // $has_run will be TRUE if $bootstrap is FALSE.
  $has_run = !$bootstrap;
 }
  return $has_run;
}

```

Just before the `drupal_load('module', $module);` statement check for the specific url you are looking for and the `admin-menu` module, if the condition holds skip the `drupal_laod` statement. I mean

```
function module_load_all($bootstrap = FALSE) {
  static $has_run = FALSE;

  if (isset($bootstrap)) {
    foreach (module_list(TRUE, $bootstrap) as $module) {
      if(current_path != "SPECIFIC URL" || $module!="SPECIFIC MODULE")
         drupal_load('module', $module);
   }
   // $has_run will be TRUE if $bootstrap is FALSE.
  $has_run = !$bootstrap;
 }
  return $has_run;
}

```

The How do I prevent a module from being loaded? may also be helpful

**Please note that this will require you to hack the core (modify a core source code) and is not recommended unless you have no other option.**

---
Tags: 7
---


# Question
Title: radios options separated into different wrappers
I'm trying to customize a radios field to wrap some of the options into a div.

What the best way to do it?

I had a look to theme\_radio but no success on it :( example:

```
<div id="part1">
  <div class="form-item form-type-radio form-item-SOME_ID">
    <input id="edit-SOME_ID" class="form-radio" type="radio" value="SOME_VALUE" name="SOME_NAME" />
    <label class="option" for="edit-bla-bla">MY LABEL</label>
  </div>
  <div class="form-item form-type-radio form-item-SOME_ID">
    <input id="edit-SOME_ID" class="form-radio" type="radio" value="SOME_VALUE" name="SOME_NAME" />
    <label class="option" for="edit-bla-bla">MY LABEL</label>
  </div>
</div>

<div id="part2">
  <div class="form-item form-type-radio form-item-SOME_ID">
    <input id="edit-SOME_ID" class="form-radio" type="radio" value="SOME_VALUE" name="SOME_NAME" />
    <label class="option" for="edit-bla-bla">MY LABEL</label>
  </div>
</div>

<div id="part3">
  <div class="form-item form-type-radio form-item-SOME_ID">
    <input id="edit-SOME_ID" class="form-radio" type="radio" value="SOME_VALUE" name="SOME_NAME" />
    <label class="option" for="edit-bla-bla">MY LABEL</label>
  </div>
  <div class="form-item form-type-radio form-item-SOME_ID">
    <input id="edit-SOME_ID" class="form-radio" type="radio" value="SOME_VALUE" name="SOME_NAME" />
    <label class="option" for="edit-bla-bla">MY LABEL</label>
  </div>
  <div class="form-item form-type-radio form-item-SOME_ID">
    <input id="edit-SOME_ID" class="form-radio" type="radio" value="SOME_VALUE" name="SOME_NAME" />
    <label class="option" for="edit-bla-bla">MY LABEL</label>
  </div>
</div>

```

ANSWER:

See Djouuuuh answers +

```
$output .= drupal_render($element['element'][$i]);

```

if you do this one below it won't work with ajax...

```
$output .= theme('radio', $element['element'][$i]);

```

# Answer
> 1 votes
In my opinion you can achieve that with a theme function, specified like this:

```
$element['example'] = array(
  '#type' => 'checkboxes',
  '#title' => t('Example checkboxes'),
  '#options' => $options,
  '#theme' => array('custom_options'),
);

```

And then, you can write down the output just as you want here:

```
function theme_custom_options($element) {
  $output = '<div id="blah">';
  $output .= $element['#options'][0];
  $output .= $element['#options'][1];
  $output .= '</div><div id="blablah">';
  $output .= $element['#options'][2];
  $output .= $element['#options'][3];
  $output .= '</div>';
  // ETC...
  return $output;
}

```

Does it seem correct?

---
Tags: 7, forms
---


# Question
Title: Form input returns "1" instead of real value
On this page I have an select list with values from a file directory. This works. Only after submitting it doesn't get the value of it. It makes it "1". Normally with a "normal" select list this should work I guess.

Problem: $form\_state\['input'\]\['edit'\]\['ios\_cert'\] doesn't return selected value.

Code (in hook\_form):

```
$files = array();
foreach(glob("C:/wamp/www/drupal2/sites/default/files/*.pem") as $filename) {
   array_push($files, substr(strrchr($filename, '/'), 1));
 }

$form['replace_textfield']['edit']['ios_cert'] = array(
    '#title' => t('Select right certificate file'),
    '#type' => 'select',
    '#options' => $files,
    '#default_value' => $ios_key,
    '#weight' => 45,
  );

```

Code (hook\_submit):

```
$ios = $form_state['input']['edit']['ios_cert'];

$query = db_update('push_notifications_api')
->fields(array(
'app_id' => $app_id,
'GCM' => $gcm,
'ios' => $ios,
'ios_mode' => $ios_mode,
))
->condition('app_id', $oldid)
->execute();
drupal_set_message(t('@title has been updated succesfully.', array('@title' => $title)));
dsm($form_state);

```

Result:

And it should be something like "Filename-djfklasjklf.pem"

thanks in advance!

# Answer
Currently you're setting the '#options' property of the form element as an indexed array such as:

```
$form['replace_textfield']['edit']['ios_cert']['#options'] = array(
  0 => 'filename1.pem',
  1 => 'filename2.pem',
  [...]
);

```

This means that the first option in the select tag will have a textual label of "filename1.pem" and a value of 0, so 0 will be sent via GET/POST to the receiving script.

In order to send the filename you need to also have the filename as the key of each option in the '#options' array (i.e it should be a self-keyed associative array).

A simple way to achieve that would be to change the line:

```
'#options' => $files,

```

to:

```
'#options' => array_combine($files, $files);

```

or, change:

```
array_push($files, substr(strrchr($filename, '/'), 1));

```

to:

```
$filename = substr(strrchr($filename, '/'), 1);
$files[filename] = filename;

```
> 1 votes

# Answer
I already got it.

I added this:

```
foreach ($files as $record){
    $options1[$record] = $record;
 }

```

And then use $options1 as '#options'
> 2 votes

---
Tags: forms
---


title: hook_node_view can't change content

text:
# Question
Title: hook_node_view can't change content
I've read through many questions asking this same thing, but I feel like I'm doing what they are suggesting and it's still not working.

I've created a custom module and enabled it. This is my code:

```
function mymodule_node_view($node, $view_mode, $langcode) {
  if ($view_mode == 'teaser' && $node->type == 'article' && count($node->field_video) > 0) {
    kpr($node);

    $markup = sprintf("<video style='width: 502px; height: 282px;' poster='%s'>\n",
        image_style_url('video_thumbnail', $node->field_video[$node->language][0]['thumbnailfile']->uri)
      );

    foreach($node->field_video[$node->language][0]['playablefiles'] as $video_object) {
      $markup .= sprintf("<source src='%s' type='%s' />\n",
          file_create_url($video_object->uri),
          $video_object->filemime
        );
    }

    $markup .= "</video>";

    $node->content['field_video_embed_code'] = array(
      '#markup' => $markup,
      '#weight' => 10,
      '#type'   => 'markup',
    );

    kpr($node);
  }

}

```

When I look at the krumo output, I see my changes to the $node object, however, when it renders the new field I'm adding is not included.

What am I doing wrong?

EDIT: I just realized I'm using Display Suite (it's been awhile since I set this site up) which is overriding which fields are shown and in what order. My guess is that DS is getting my modified content, but not showing the additional field because it isn't listed in my teaser fields? I'm not sure.

# Answer
You must declare the field for the DS be able to handle it. In your case:

```
/**
 * Implements hook_field_extra_fields().
 */
function mymodule_field_extra_fields() {

  $extra['node']['article']['display']['field_video_embed_code'] = array(
    'label' => t('Custom field embed video.'),
    'description' => t('Adds a custom field.'),
    'weight' => 0,
  );
  return $extra;
}

```
> 1 votes

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


# Question
Title: Views contextual filter not working for Pathauto path
Im using Pathauto so set aliases for taxonomy terms.

So this: /taxonomy/term/1

Is the same as this: /custom-term-url

Im using Drupals default Taxonomy term View to control the layout of the term page. This works fine for both of the paths.

Ive created an additional page in this view with a path of /taxonomy/term/%/something and an additional filter so show different results.

When I go to this page everything works perfectly: /taxonomy/term/1/something

However this returns a page not found: /custom-term-url/something

How can I get my View working with the Pathauto URL?

# Answer
> 0 votes
Try the Sub-path URL Aliases module, which should do exactly what you're after.

# Answer
> 0 votes
Install Global Redirect module, this module create a unique form of all of the aliases. I am not able to test this solution of your problem But I guess it may solve the problem.

---
Tags: views
---


# Question
Title: How to force users to choose a forum when creating new thread?
Here is the problem: On a D7 community site, upgraded from D6, users are allowed to create new forum threads using node/add/forum link. In the node creation page ,they have to choose which forum their thread belongs to.

The default forum in the drop-down menu is set to '-None-' . So users who do not choose any forum, end up creating their thread in the 'None' forum, which then appears as the first forum and is obviously not desirable.

I am wondering who to get rid of this annoying problem?

# Answer
> 0 votes
Bit late, but someone else might find this useful.

My method was to use my theme template.php in D7 to modify the form:

1. Add an entry to the list of forums (I only had a simple, non-hierachical list) e.g. `$form['taxonomy_forums']['und']['#options']['0'] = '-choose a forum-';`
2. Add a validation function to the form. `$form['#validate'][] = 'cirqasupport_validate_forum_area';`
3. In the validation function test the 'tid' being returned and if it was zero return an error on the forum field.

For example, add the following to template.php for your theme (or it could be done in a new module instead):

```
function mytheme_form_forum_node_form_alter(&$form, &$form_state){
   // force user to select a forum by putting a blank one at the top
   // and then checking that it is not what gets returned
   $form['taxonomy_forums']['und']['#options']['0'] = '-choose a forum-';
   $form['#validate'][] = 'mytheme_validate_forum_area';
}

```

and the validation function:

```
function mytheme_validate_forum_area($form, &$form_state){
   // A taxonomy_forum tid of 0 means they haven't selected one
   if ($form_state['values']['taxonomy_forums']['und'][0]['tid'] == '0')
   form_set_error('taxonomy_forums', t('You must select a forum.'));
}

```

The only problem I found is that the blank forum went in at the bottom of the sorted list no matter what number I gave it or how it was named.

---
Tags: 7, nodes
---


# Question
Title: How to print a flag in a block programmatically?
I am creating a module which displays a block. I have created a flag within the module, and I am trying to display it through the block\_view() hook. Currently struggling to get there...

I am doing this instead of going through the template pages because there are certain conditions and functions involved to decide if I show the flag or not, making it easier for me at the minute to do this in a block.

Unfortunately, the block isn't working. Am I not displaying it correctly?

```
function get_involved_block_info() {
$blocks = array();
$blocks['get_involved_block'] = array(
'info' => t('Get involved block'),
'weight' => 10,
);
return $blocks;
}

function get_involved_flag_default_flags() {
$flags = array();
$flags[] = array(
'content_type' => 'node',
'name' => 'get_involved_interested',
'title' => 'Interested',
'global' => FALSE,
'types' => array('ad'),
'flag_short' => 'Join',
'flag_long' => 'I want to join',
'flag_message' => 'Your interest was registered',
'unflag_short' => 'Cancel',
'unflag_long' => 'Cancel my interest',
'unflag_message' => 'Your interest was deleted',
'show_on_page' => TRUE,
'show_on_teaser' => FALSE,
'show_on_form' => TRUE,
'status' => TRUE,
'locked' => array('name', 'types', 'global'),
);
return $flags;
}

function get_involved_block_view($delta) {
global $user;
$block = array();
if (arg(0) == 'node' && is_numeric(arg(1))) $nodeid = arg(1);
$node = node_load($nodeid);

//First of all, if the user is the author, do not show this node
if ($node->uid == $user->uid)
{
} else {

$block['title'] ='Get involved';

$block['content'] = flag_create_link('get_involved_interested', $nodeid);

  return $block;
}
}

```

# Answer
You are adding raw PHP code as block content; you should execute it directly instead.

Try this:

```
$block['content'] .= flag_create_link('mymodule_interested', $node->nid);

```

---

**UPDATE**

You were using Flag API v1, instead of v2. Below is the full code:

```
function get_involved_block_info() {
  $blocks = array();
  $blocks['get_involved_block'] = array(
    'info' => t('Get involved block'),
    'weight' => 10,
  );

  return $blocks;
}

function get_involved_block_view($delta) {
  $block = array();
  switch ($delta) {
    case 'get_involved_block':
      global $user;
      $node = menu_get_object();
      // First of all, if the user is the author, do not show this node.
      if ($node && $node->uid != $user->uid) {
        $block = array();
        $block['subject'] = t('Get involved');
        $block['content'] = flag_create_link('get_involved_interested', $node->nid);

        return $block;
      }
    break;
  }
}

function get_involved_flag_default_flags() {
  $flags = array();
  // Exported flag: "Interested".
  $flags['get_involved_interested'] = array(
    'entity_type' => 'node',
    'title' => 'Interested',
    'global' => false,
    'types' => array(
      0 => 'ad',
    ),
    'flag_short' => 'Join',
    'flag_long' => 'I want to join',
    'flag_message' => 'Your interest was registered',
    'unflag_short' => 'Cancel',
    'unflag_long' => 'Cancel my interest',
    'unflag_message' => 'Your interest was deleted',
    'unflag_denied_text' => '',
    'link_type' => 'toggle',
    'weight' => 0,
    'show_on_teaser' => false,
    'show_on_form' => true,
    'status' => false,
    'locked' => array(
      'name' => 'name',
      'types' => 'types',
      'global' => 'global',
    ),
    'module' => 'get_involved',
    'api_version' => 3,
    'import_roles' => array(
      'flag' => array(),
      'unflag' => array(),
    ),
    'show_in_links' => array(
      'full' => true,
    ),
  );

  return $flags;
}

```
> 1 votes

---
Tags: blocks, flags
---


# Question
Title: Publish node link to social media on content creation
I'm looking for a way to publish the node link to social media (Facebook, Twitter and Linkedin) on the creation of the node.

So what I would like is a little checkbox saying: publish to facebook on the node edit page. Does anyone know a module that could help me achieve this? Thanks !

# Answer
Take a look at the twitter module: https://drupal.org/project/twitter

You should be able to then use twitter to send that story to Facebook by hooking up your twitter account to your Facebook account. I'm not sure if the same is possible with linked in though.
> 0 votes

# Answer
I can also suggest using the Tweet module. Here is a quote about it (from the module's project page):

> ... provides links to post pages to Twitter in a new window or tab. The tweet will be in focus and will contain customizable text that can hold the relevant URL, title and anything else you need it to (like hashtags). The URL can be automatically abbreviated at the administrator's choice of service by integration with the Shorten URLs module by the same author.
>
> When Twitter is opened, if the user is not already logged in, Twitter will prompt them to log in, and after logging in will redirect users to the tweet form as described above.
> 0 votes

# Answer
Facebook Autopost for Facebook postings. Twitter module for Twitter.

Both modules provides integration with rules so you check condition for checkbox.

Have not tried linkedin but this looks promising. No stable release yet for Drupal 7
> 0 votes

# Answer
Try social media module as well.

> The social media module helps integrate your website with social media sites such as Twitter, Facebook and Google+. It provides an centralized way of managing social media profile information and plug-in widgets such as follow and share buttons.
> -1 votes

---
Tags: 7, nodes, social-network
---


# Question
Title: How to install an existing Drupal profile with drush?
Seems like searching for the answer on Google just leads me to how to create make files and profiles.

I know how to do that. I also know how to install Drupal with drush.

But I want to install one of the many existing Drupal profiles, like Drupal Commons, Commerce Kick Start, etc. with drush.

I would have thought it would have been just an easy process to find the profile's makefile and run that. Drush will take care of the rest. But I can't find the repositories where these makefiles sits.

Some direction would be appreciated.

# Answer
To build on what Patrick said, if the profile is **not** already in your profile directory, you can download it with Drush dl: `drush dl drupal --drupal-project-rename=drupal
cd drupal
drush dl commons
drush site-install commons --db-url=mysql://user:pwd@localhost/db_name --site-name=Example --account-name=admin --account-pass=pwd` You do not need to run `drush make`, because drupal.org runs it prior to making the profile available for download. Thus, when you run `drush dl commons`, you get all of the components that the Drupal Commons distribution needs to install.
> 7 votes

# Answer
If the profile is already in your drupal/profiles directory you can just pass it into site-install.

```
drush site-install your_profile --db-url=mysql://user:pwd@localhost/db_name --site-name=Example --account-name=admin --account-pass=pwd

```
> 1 votes

# Answer
Maybe Drush Make is what you're looking for?

There are various questions (and answers) tagged with .

And the answer to Changing Drush make default subdir for install profiles may also help.

Does this answer your question?
> 0 votes

---
Tags: drush, installation-profiles
---


# Question
Title: Unable to set Singularity grid total to 16
I’m having a problem using the Singularity grid framework. I set the total number of columns to 16 but it seems not to be reading this setting. instead the total seems to be 12.

the details are as follows. I’m using the Omega theme and have correctly implemented a sub-theme i’m using SASS and in the grid partial, \_grid.scss have this code

```
@import "singularitygs";
$tab: 44em; /*704 pixels */
$desk: 70em; /* 1120 pixels */
$grids:16;
$gutters:1/4;

```

for test purposes i set a div to be 16 columns with this code.

```
.someDiv {@include grid-span(16, 1); }

```

this div then breaks out of the main page div, in this case .l-page and in the inspector it reads as

```
width:133%;

```

to trouble shoot i’ve searched via grep ‘grids:12’ and cleared the .sass-cache file. but so far nothing is working. has anyone had this same problem?

# Answer
> 1 votes
Make sure that you are using the correct syntax for your version of SingularityGS. Your syntax is for pre 1.2. If you created the sub-theme recently, I bet you are on a more modern version. The syntax should be like:

```
// Singularity 1.2+ Syntax
@include add-grid(16);
@include add-gutter(1/4);

```

It is also very unlikely that .sass-cache files are causing your issues.

# Answer
> 1 votes
Make sure that you aren't overwriting your grids variable. I believe that by default, it's overwritten when the browser reaches the $tab size via: `$grids: add-grid(12 at $tab);` so searching for that line would be a start.

To help visualize your grid, singularitygs has the `@include background-grid($color: blue);` option that might be helpful while testing.

Lastly, you can always set your grids on the fly with a 3rd argument in your `grid-span` calls. For example:

```
// Override the default $grids variable to use 16 grids
@include grid-span(16, 1, 16);

```

---
Tags: theming
---


# Question
Title: How to implement this event tracking to google analytics module
I need to implement this event

```
setTimeout('pageTracker._trackEvent(\'NoBounce\',\'NoBounce\',\'Over 30 seconds\')',30000);

```

with the Google Analytics event tracking module, I do not understand how to proceed and create this event, The event is useful for count a bounced visitor only if the visitor leaves before 30 secons, I need to add that event, any help would be appreciated. Thanks

# Answer
> 2 votes
I finally found the way of add this event code in google analytics module.

Go to your admin-\>configs-\>google analytics

Go to advanced settings then open Custom Javascript code fieldset

Then in the field **Code snippet (after)** add this snipppet:

```
setTimeout(“ga(‘send’,’event’,’Profitable Engagement’,’time on page more than 3 minutes’)”, 180000);

```

I modified the code snippet in order to fit universal analytics code that is the one used in the Drupal google analytics module.

After that you will see how your bounce rates are more accurate

# Answer
> 2 votes
The GA Event Tracking module is designed to react to a number of different binded JS events. You're limited by what DOM events that jQuery can bind to. As such, there is no `settimeout` event.

One solution that comes to mind is adding some custom JS to the standard GA module. Go to configuration page under the `Custom Javascript Code` in the `Advanced Settings` fieldset. There you can add what custom JS needed to trigger your setTimeout GA event.

---
Tags: 7, google-analytics
---


title: 'Media File Selector' blank screen

text:
# Question
Title: 'Media File Selector' blank screen
To use already existing image, I choose 'Media File Selector' Widget. But, it gives me blank page like this when I click on 'Library' to choose already existing image in Drupal-7.

***Version of the Media:*** 1) Media: YouTube (media\_youtube) 7.x-2.0-rc4

2) Media (media) 7.x-1.4

In Media browser settings, Allowed file extensions are (jpg jpeg gif png txt doc docx xls xlsx pdf ppt pptx pps ppsx odt ods odp mp3 mov m4v mp4 mpeg avi ogg oga ogv wmv ico)

Thanks!

# Answer
I am not sure whether to making 'jQuery' version down to some level is good or not. But, I tried to downgrade the jquery version to 1.5 and it works well with my website.

I refereed this post: Media 7.x-1 Library tab empty

Now, I can see all my images by selecting 'jQuery' version - 1.5.

To do so: Go to Home » Administration » Configuration » Development

Thanks!

Vidushi
> 1 votes

---
Tags: files, media
---


# Question
Title: I need to add rel="nofollow" to the button provided by "views load more" module
I need to add rel="nofollow" to the button "Load More" provided by Views Load More, but the problem is that the anchor is created in views\_load\_more.module (line 91) this way:

```
$li_next = theme('pager_next',
    array(
      'text' => (isset($tags[3]) ? $tags[3] : t($vars['more_button_text'])),
      'element' => $element,
      'interval' => 1,
      'parameters' => $parameters,
    )
  );

```

But I dont know how to add an attribute to that, when I print\_r($li\_next), it prints the link.

I have tried this:

```
function THEMENAME_preprocess_pager_next(&$vars) {
  $vars['#path']['options'] = array('attributes'=>array('rel'=>'nofollow'));
}

```

But didn't work

# Answer
> 4 votes
I found the answer myself, and I want to share it in case someone have the same problem in the future.

Just override the theme\_pager\_next() function in the template.php file of your theme like this:

```
function YOURTHEME_pager_next($variables) {
  $text = $variables['text'];
  $element = $variables['element'];
  $interval = $variables['interval'];
  $parameters = $variables['parameters'];
  global $pager_page_array, $pager_total;
  $output = '';

  // If we are anywhere but the last page
  if ($pager_page_array[$element] < ($pager_total[$element] - 1)) {
    $page_new = pager_load_array($pager_page_array[$element] + $interval, $element, $pager_page_array);
    // If the next page is the last page, mark the link as such.
    if ($page_new[$element] == ($pager_total[$element] - 1)) {
      $output = theme('pager_last', array('text' => $text, 'element' => $element, 'parameters' => $parameters,'attributes'=>array('rel'=>'nofollow')));
    }
    // The next page is not the last page.
    else {
      $output = theme('pager_link', array('text' => $text, 'page_new' => $page_new, 'element' => $element, 'parameters' => $parameters,'attributes'=>array('rel'=>'nofollow')));
    }
  }

  return $output;
}

```

I've just add 'attributes'=\>array('rel'=\>'nofollow') to theme() function :)

---
Tags: views, navigation, theming
---


# Question
Title: Fatal error after enabling backup and migrate module
I just enabled back up and migrate module. Then I backed up my site and tried to restore the site using the back up file and it did not allow me to do it.

Then when I go to admin \> config \> I get this error:

"One or more problems were detected with your Drupal installation. Check the status report for more information."

Then I go to admin \> reports \> status reports \> click run cron manually \> I get this error:

" Fatal error: Class CToolsCssCache contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (DrupalCacheInterface::\__construct) in /home/content/65/11722765/html/sites/all/modules/ctools/includes/css-cache.inc on line 52 "

Chaos tools 7.x-1.7

Drupal 7.22, 2013-04-03

Please advise, D

# Answer
Go to this link and install the ctools-cache-handler.patch patch
> 0 votes

---
Tags: debugging
---


# Question
Title: Panels in-place editor won't show in panels even after setting renderer
My relevant specs are: Drupal 7, Jquery update 2.5.7 (set to 1.7), Ctools 1.7.7, and Panels 3.5.7.

**The problem:**

I've enabled "Panels in-place editor" to ease panels editing. I've set the renderer at Paenls\>Settings\` from "Standart" to "Panels in-place editor" and cleared cache - and yet, when standing at the Panel node I don't see it. reasons?

**notes:**

* The site has only 1 user, me, the Admin so it's not a permissions issue (also checked permissions).
* My layout was taken from "Panels extra layouts" module, if it makes
any difference...

# Answer
> 0 votes
Solved!

It seems to me that there are two types of renderes for panels:

The first is the **global** renderer that indeed I've changed to "Panels in-place editor". The second is each Panel's **own** or **Specific** renderer.

My problem occurred because for some reason, My Panel's **own** renderer wasn't affected from the global one, and stayed "Standart". I have no idea why that happen (might be a bug)...

Anyways, to change your Panel's own renderer just go to it's Panel.page\Panel.node and click on the tab "Edit" located on it's top. Thus when you edit the Panel itself you could choose it's own renderer and Problem should be solved by then.

All luck, Ben.

---
Tags: panels
---


# Question
Title: Site wont let me into administator areas
Whenever I want to go to an admin only area (e.g. Modules), I get this error:

> Fatal error: require\_once(): Failed opening required '/Applications/XAMPP/xamppfiles/htdocs/Ecommerce\_website/sites/all/modules/openatrium-7.x-2.33/modules/system/system.admin.inc' (include\_path='.:/Applications/XAMPP/xamppfiles/lib/php') in
>
> /Applications/XAMPP/xamppfiles/htdocs/Ecommerce\_website/includes/menu.inc on line 517

Any ideas?

(Tip: I have also tried putting openatrium back into the folder and it still gave me an error)

# Answer
**Why has it happened?**

**OpenAtrium is not a module, is an installation profile**

You are mistaken an installation profile with a module. An installation profile contains the whole drupal core plus some extra modules and themes.

It means, you cannot put it in the modules directory of another Drupal installation. If you want to use an installation profile you do not need to use Drupal core.

**How to fix it?**

**A: Re-install Drupal using OpenAtrium**

If you want all the features in Open Atrium and you do not care about your current website, you'd better delete the whole thing and re-install Drupal using OpenAtrium.

Extract the content of OpenAtrium package to your document root (which is `/Applications/XAMPP/xamppfiles/htdocs/` in your case). Then install it again.

**B: Remove OpenAtrium and keep the current installation**

If you already have a working Drupal installation and want to keep it, first you will need to remove OpenAtrium package out of it. There is no way you could use an installation profile along side a current installation.

First remove all the OpenAtrium files.

Then clear all caches. You can go to database and clear the content of all tables starting with `cache_`.

To access database you can use phpMyAdmin in browser (learn how) or an app like SequelPRO.

If the problem persists, you will need to rebuild the menu.
> 4 votes

---
Tags: 7
---


# Question
Title: Beginner Drush question. Can't get Drush to do anything!
I can't get Drush to do much. I can connect to my site by typing `cd` and then dragging my files to the terminal window in OSX using Acquia DevDesktop. My overall goal is to create a sub theme of Omega.

When I type `drush omega-wizard` I get:

> The drush command 'omega-wizard' could not be found. Run `drush cache-clear drush` to clear the commandfile cache if you have installed new extensions. \[error\]
>
> Drush was not able to start (bootstrap) the Drupal database. \[error\]
>
> Hint: This may occur when Drush is trying to:
>
> * bootstrap a site that has not been installed or does not have a configured database. In this case you can select another site with a working database setup by specifying the URI to use with the --uri parameter on the command line. See `drush topic docs-aliases` for details.
> * connect the database through a socket. The socket file may be wrong or the php-cli may have no access to it in a jailed shell. See http://drupal.org/node/1428638 for details.

I think this means that I haven't shown Drush where the settings file is. For the life of me, I'm not able to do that. Normally, I would do something like:

```
cd sites/nameofsite.localhost

```

or

```
cd site/nameoffolder.localhost

```

I've tried every iteration of this command: with the localhost, without the localhost, different folder names, etc. I always get "No such file or directory". Can anyone tell me what I'm doing wrong? What does Drush need me to tell it?

Thanks so much in advance,

Jason

# Answer
> 1 votes
There is a known problem of using **Drush** with **DevDesktop** on **MacOSX**.

**Quick fix**

Instead of running drush like this:

```
$ drush status

```

Run it like this:

```
$ DEVDESKTOP_DRUPAL_SETTINGS_DIR="$HOME/.acquia/DevDesktop/DrupalSettings" drush status

```

**Permanent fix**

Everything is explained in this article: http://btmash.com/article/2015-03-24/using-dev-desktop-composer-drush

**Why is it happenenig?**

Acquia DevDesktop keeps all credentials in a specific folder and let PHP have access to that location via a $\_SERVER variable called `$_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR']`. This variable is provided by Apache and PHP only sees it is run by Apache. But when you use Drush, PHP is called directly and that variable does not exists anymore and Drush cannot find the database credentials.

---
Tags: drush
---


# Question
Title: Send message notification when license expired
I have a commerce site where I sell subscription using the Commerce License module. I want to send email notification to users whose licenses will expire soon.

I'm trying to do that by creating a custom module. I have 2 code snippets, one to notify users when the license expires, the second to send email using the Message Notify module. I don't know what variables I should use to have the licence owner's.

This is my custom module and the code works well for me.

```
    /**
     * Implements hook_cron().
     */
    function license_notif_cron() {
      $expires = strtotime('-1 day');
      $query = new EntityFieldQuery();
      $query
        ->entityCondition('entity_type', 'commerce_license')
        ->propertyCondition('status', COMMERCE_LICENSE_ACTIVE)
        ->propertyCondition('expires', 0, '<>')
        ->propertyCondition('expires', $expires, '>');
      $results = $query->execute();
      if (!empty($results['commerce_license'])) {
        $license_ids = array_keys($results['commerce_license']);
        drupal_set_message('licensce expires soon');
        //send message
      }
    }

```

This is an example of sending a message. I am not interested in `hook_node_insert()`; I already created a new message type (*licence\_expire\_soon*).

```
/*
 * Implements hook_node_insert().
 */
function foo_node_insert($node) {
  $message = message_create('foo_message_type', array('uid' => $node->uid));
  $wrapper = entity_metadata_wrapper('message', $message);
  $wrapper->field_node_ref->set($node);

  $options = array(
    'rendered fields' => array(
      'message_notify_email_subject' => 'field_rendered_subject',
      'message_notify_email_body' => 'field_rendered_body',
    ),
  );

  message_notify_send_message($message, $options);
}

```

# Answer
> 0 votes
To glue the bits you have together you need to relate your to-be-expiring-soon license with a uid which can feed into `message_create`. So something like this in your `hook_cron` call...

```
//...after assigning $license_ids

foreach($license_ids as $license_id) {

   //...@TODO: checks on previous alert messages

   $uid = db_select('commerce_license','cl')
     ->fields('cl', array('uid'))
     ->condition('license_id', $license_id)
     ->execute()->fetchField();

   //...@TODO: code for executing message_notify_send_message and sending message to $uid
}

```

---
Tags: commerce
---


# Question
Title: How to disable specific message displayed by contrib/core?
I am using the Disable Messages module to disable one of the message which is being displayed to the end user. The message is:

> Anonymous (not verified) has requested to be your Friend. View your pending friend requests to approve or decline.

To achieve this I have configured the module and written a regular expression to match a word from the message, But it seems to not be working.

Here is the code:

```
str.matches("(?i)(^|\\s+)(Anonymous (not verified))(\\s+|[.?!]$)");

```

# Answer
Once a user has been deleted, The User relationships module have to delete all relationships associated to deleted user but it doesn't work correctly. I implemented `hook_user_delete()` in a custom module and delete non-approved relationships associated to the deleted user. like this:

```
/**
 * Implements hook_user_delete().
 */

function YOUR_MODULE_NAME_user_delete($account) {
  //user_relationships_delete_relationship($relationship, $user);
  db_delete('user_relationships')->condition('approved', 0 , '=')->condition(db_or()->condition('requester_id', $account->uid)->condition('requestee_id', $account->uid))->execute();
}

```
> 0 votes

---
Tags: 7
---


# Question
Title: image field point to another image field
I have users whom are part of a group, this group has an image field that can be changed by the administrator.

When a user writes a new article, i wan the article to display the image of the group. To do so, i'm modifying the hook\_node\_presave(). I'm loading the group of the user and i modify the image of the article to match the one from the group with a simple affection ( `$node->field_image = $userGroup->field_image_group;` ).

It's working pretty well, however if the group changes its image, the article will still keep the old one.

Is there a way to make the image change automatically ? Same question if I change the author of the article or if the author changes group.

Thank you.

# Answer
What you need is a change in the way the content is displayed, so it is much better to do it in theme layer rather than content level.

I would recommend using template preprocessing for node.

Add this function to the `template.php` file in your theme folder:

```
<?php

/**
 * Implements hook_preprocess_node().
 *
 * Replaces the node's image field with anbother node's image field
 */
function YOURTHEME_preprocess_node(&$variables) {
    $node = $variables;
    // Make sure we only alter nodes that we intend to!
    if ($node->type == 'article') { // assiuming your article content-type is 'article'
        // Get the view mode for this node, e.g. full or teaser
        $view_mode = $variables['view_mode'];
        // Get the group node
        $another_node = get_another_node($node); // Somehow!
        // Retrieve the image field of that node using the same view mode of the current node
        $another_image_field = field_view_field('node', $another_node, 'field_image', $view_mode); // assiuming it is called 'field_image'
        // Replacing the other field with the current node's field
        $variables['content']['field_image'] = $another_image_field; // assuming it is called 'field_image'
    }
}

```

You will need to update the code to retrieve the node object for the group and also make sure that the field names are correct for your case.
> 0 votes

---
Tags: entities, media
---