title: Superfish Menu in 2 Columns

text:
# Question
Title: Superfish Menu in 2 Columns
I am using superfish menu in my website as a main horizontal navigation. on mouse over some links the drop down menu opens and it but due to lots of links its getting very long verticaly. Is there a way through CSS we can divide the first drop down menu into 2 columns. my website link is http://go2georgia.travel

# Answer
Just about the time you posted your question, the new Superfish features showed up in beta. These features include a multi-column capability. You would want to use CSS to style it, but the multi-column capability comes through the configuration panel.

There is a nice tutorial here: http://www.digett.com/blog/02/19/2013/superfish-mega-menus

Pay special attention to the limitation: the multi-column nature of the menu is enabled for the entire menu, and you have to explicitly indicate any menu items that are to be excluded.

Presently, the dev version is the most highly recommended by the developer, but leave yourself a way to back out, in case you hit a problem.

Also, pay close attention to the instructions for upgrading to v1.9

d
> 1 votes

---
Tags: theming, navigation
---


# Question
Title: Always the same error when drush sup (to upgrade from 6.x to 7.x) is running for a certain time
i'm hardly trying to upgrade my Drupal 6.x installation to 7.x with the help of drush.

I'm using the command drush sup @dev2 -v -d

Every thing's working fine until Major Upgrade Step 15. I try to use the choice: Automatically enable and upgrade all modules remaining in list.

But when drush updates about 3-6 modules in the list, i'm getting this error and no more modules can't be processed without showing the same error message.

```
... some other modules processed (votingapi,xmlsitemap,util, dblog_common, etc...)....

```

Then the part with the error message:

```
Upgrading Contrib Modules from Drupal 6 to Drupal 7 Step 1

```

Upgrading module: userpoints

1. Check your notes, and the UPGRADE.txt files inside each module, to see if any special upgrade instructions apply

There is no UPGRADE.txt file in userpoints Drush will now do the step 'Begin upgrade of module userpoints'.

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Upgrading Contrib Modules from Drupal 6 to Drupal 7 Step 2 Upgrading module: userpoints
2. Fully remove the old module directory inside sites/all/modules/

Note that Drush builds the target site in a new directory; the modules directory therefore starts off empty, and there is therefore no need to delete anything. If there is for some reason an old module directory in place, Drush will automatically delete it when downloading the new module.

Skipping optional step.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Upgrading Contrib Modules from Drupal 6 to Drupal 7 Step 3 Upgrading module: userpoints
3. Download, unpack and move the new module directory to sites/all/modules/

```
  Drush has a cached version of userpoints at /Users/dennis/.drush/cache/@self-d6-to-dev2-d7/project_cache/disabled/userpoints. The destination directory is /Users/dennis/Sites/dev2/sites/all/modules/userpoints

  Drush will automatically do this step now.
  Calling _drush_recursive_copy(/Users/dennis/.drush/cache/@self-d6-to-dev2-d7/project_cache/disabled/userpoints, /Users/dennis/Sites/dev2/sites/all/modules/userpoints) [1044.77 sec, 102.01 MB]      [debug]

```

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Upgrading Contrib Modules from Drupal 6 to Drupal 7 Step 4 Upgrading module: userpoints
4. Enable the module

Then I've this output:

```
Drush will automatically do this step now.
Backend invoke: /usr/bin/php /usr/local/drush/drush.php --php=/usr/bin/php  --backend=2 --verbose --debug --root=/Users/dennis/Sites/dev2 --uri=default  pm-enable userpoints 2>&1 [1045.13 sec,   [command]
102.03 MB]
/usr/bin/php /usr/local/drush/drush.php --php=/usr/bin/php  --backend=2 --verbose --debug --root=/Users/dennis/Sites/dev2 --uri=default  pm-enable userpoints 2>&1 [1045.13 sec, 102.04 MB]         [notice]
Bootstrap to phase 0. [0.01 sec, 4.96 MB]                            [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.01 sec, 5.25 MB] [bootstrap]
Cache HIT cid: 5.9-commandfiles-0-beab8c3c129fe63a55d60d824a695615 [0.02 sec, 5.27 MB]                                                                                [debug]
Bootstrap to phase 0. [1045.34 sec, 12.42 MB]                                                                                [bootstrap]
Bootstrap to phase 6. [1045.37 sec, 12.42 MB]                                                                                [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [1045.37 sec, 12.43 MB]                                                                                [bootstrap]
Initialized Drupal 7.22 root directory at /Users/dennis/Sites/dev2 [1045.41 sec, 14.49 MB]                                                                                [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [1045.41 sec, 14.49 MB]                                                                                [bootstrap]
Initialized Drupal site default at sites/default [1045.41 sec, 14.5 MB]                                                                                [notice]
Cache HIT cid: 5.9-commandfiles-2-c32acd775c18a90c5b41d0fc9accf5ab [1045.42 sec, 14.5 MB]                                                                                [debug]
Drush bootstrap phase : _drush_bootstrap_drupal_configuration() [1045.42 sec, 14.5 MB]                                                                                [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_database() [1045.43 sec, 14.51 MB]                                                                                [bootstrap]
Successfully connected to the Drupal database. [1045.43 sec, 14.52 MB]                                                                                [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_full() [1045.44 sec, 15.52 MB]                                                                                [bootstrap]
Cache HIT cid: 5.9-commandfiles-5-efa59ca0aabb00a052dd01ef436dba54 [1045.64 sec, 41.46 MB]                                                                                [debug]
Drush bootstrap phase : _drush_bootstrap_drupal_login() [1045.64 sec, 41.57 MB]                                                                                [bootstrap]
Successfully logged into Drupal as Gast (uid=0) [1045.65 sec, 41.76 MB]                                                                                [bootstrap]
Found command: pm-enable (commandfile=pm) [1045.65 sec, 41.76 MB]                                                                                [bootstrap]
Cache MISS cid: 5.9-commandfiles--a96edeebec832dfcac7c4c036542fd68 [1046.3 sec, 44.46 MB]                                                                                [debug]
Cache SET cid: 5.9-commandfiles--a96edeebec832dfcac7c4c036542fd68 [1046.3 sec, 44.47 MB]                                                                                [debug]
The following extensions will be enabled: userpoints
Do you really want to continue? (y/n): y
WD system: userpoints module enabled. [1046.76 sec, 51.18 MB]                                                                                [info]
WD actions: 3 orphaned actions (heartbeat_activity_delete_action, userpoints_action_grant_points, user_block_ip_action) exist in the actions table. Verwaiste Aktionen entfernen [1048.31 sec,        [info]
60.01 MB]
userpoints was enabled successfully. [1048.51 sec, 59.85 MB]                                                                                [ok]
Command dispatch complete [1048.51 sec, 59.79 MB]                                                                                [notice]
 Timer  Cum (sec)  Count  Avg (msec)
 page   3.085      1      3084.86

Peak memory usage was 61.74 MB [1048.51 sec, 59.78 MB]                                                                                [memory]

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Upgrading Contrib Modules from Drupal 6 to Drupal 7 Step 5
Upgrading module: userpoints

5. Run update.php again (you should have run it once already when upgrading core) and check for any message output.

Drush will automatically do this step now.
Backend invoke: /usr/bin/php /usr/local/drush/drush.php --php=/usr/bin/php  --backend=2 --yes --verbose --debug --root=/Users/dennis/Sites/dev2 --uri=default  updatedb 2>&1 [1048.99 sec, 102.08  [command]
MB]
/usr/bin/php /usr/local/drush/drush.php --php=/usr/bin/php  --backend=2 --yes --verbose --debug --root=/Users/dennis/Sites/dev2 --uri=default  updatedb 2>&1 [1048.99 sec, 102.09 MB]               [notice]
Bootstrap to phase 0. [0.01 sec, 4.96 MB]                            [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.01 sec, 5.25 MB] [bootstrap]
Cache HIT cid: 5.9-commandfiles-0-beab8c3c129fe63a55d60d824a695615 [0.02 sec, 5.27 MB]                                                                                [debug]
Bootstrap to phase 0. [1049.17 sec, 12.42 MB]                                                                                [bootstrap]
Bootstrap to phase 2. [1049.19 sec, 12.42 MB]                                                                                [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [1049.2 sec, 12.43 MB]                                                                                [bootstrap]
Initialized Drupal 7.22 root directory at /Users/dennis/Sites/dev2 [1049.22 sec, 14.49 MB]                                                                                [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [1049.22 sec, 14.49 MB]                                                                                [bootstrap]
Initialized Drupal site default at sites/default [1049.22 sec, 14.5 MB]                                                                                [notice]
Cache HIT cid: 5.9-commandfiles-2-d0694fde84f442a7d33c2119cff575f2 [1049.23 sec, 14.5 MB]                                                                                [debug]
Found command: updatedb (commandfile=core) [1049.23 sec, 14.5 MB]                                                                                [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_configuration() [1049.8 sec, 28.17 MB]                                                                                [bootstrap]
Cache HIT cid: 5.9-commandfiles-3-ff795e0864da9d3c245f6727a8655b23 [1049.81 sec, 28.18 MB]                                                                                [debug]
Drush bootstrap phase : _drush_bootstrap_drupal_database() [1049.81 sec, 28.18 MB]                                                                                [bootstrap]
Successfully connected to the Drupal database. [1049.81 sec, 28.18 MB]                                                                                [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_full() [1049.81 sec, 28.19 MB]                                                                                [bootstrap]
Cache MISS cid: 5.9-commandfiles-5-6989c0ea5e3787ed00051dc86fc1390b [1049.99 sec, 45.45 MB]                                                                                [debug]
Cache SET cid: 5.9-commandfiles-5-6989c0ea5e3787ed00051dc86fc1390b [1050.01 sec, 45.45 MB]                                                                                [debug]
The following updates are pending:

userpoints module :
  7000 -   Update profile category setting, allow multiple categories to be displayed.
  7001 -   Add a few indexes to speed up contrib modules that query the `points` columns.   Add index on points columns in userpoints and userpoints_txn, as well as on the two  uid columns in userpoints_txn. No need to add a uid index in userpoints, as the  compound uid_tid index is used instead when needed.   Since these indexes are added in a 6.x update as well, they need to be conditional  in this update. Otherwise users get errors, which is bad.
  7002 -   Increase length of operation and entity_type columns.
  7003 -   Create the {userpoints_total} table.
  7004 -   Filling the {userpoints_total} table.

Do you wish to run all pending updates? (y/n): y
Backend invoke: /usr/bin/php /usr/local/drush/drush.php --php=/usr/bin/php  --backend=2 --verbose --debug --yes --root=/Users/dennis/Sites/dev2 --uri=default  updatedb-batch-process 31 31 2>&1   [command]
[1051.01 sec, 48.89 MB]
/usr/bin/php /usr/local/drush/drush.php --php=/usr/bin/php  --backend=2 --verbose --debug --yes --root=/Users/dennis/Sites/dev2 --uri=default  updatedb-batch-process 31 31 2>&1 [1051.01 sec,      [notice]
48.9 MB]
Bootstrap to phase 0. [0.01 sec, 4.96 MB]                            [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.01 sec, 5.25 MB] [bootstrap]
Cache HIT cid: 5.9-commandfiles-0-beab8c3c129fe63a55d60d824a695615 [0.02 sec, 5.27 MB]                                                                                [debug]
Bootstrap to phase 0. [1051.19 sec, 12.42 MB]                                                                                [bootstrap]
Bootstrap to phase 2. [1051.21 sec, 12.42 MB]                                                                                [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [1051.21 sec, 12.43 MB]                                                                                [bootstrap]
Initialized Drupal 7.22 root directory at /Users/dennis/Sites/dev2 [1051.23 sec, 14.49 MB]                                                                                [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [1051.24 sec, 14.49 MB]                                                                                [bootstrap]
Initialized Drupal site default at sites/default [1051.24 sec, 14.5 MB]                                                                                [notice]
Cache HIT cid: 5.9-commandfiles-2-d0694fde84f442a7d33c2119cff575f2 [1051.25 sec, 14.5 MB]                                                                                [debug]
Found command: updatedb-batch-process (commandfile=core) [1051.25 sec, 14.5 MB]                                                                                [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_configuration() [1051.76 sec, 28.17 MB]                                                                                [bootstrap]
Cache HIT cid: 5.9-commandfiles-3-ff795e0864da9d3c245f6727a8655b23 [1051.76 sec, 28.18 MB]                                                                                [debug]
PDO::__construct(): MySQL server has gone away environment.inc:517 [1051.76 sec, 28.19 MB]                                                                                [warning]
SQLSTATE[HY000] [2006] MySQL server has gone away [1051.76 sec, 28.23 MB]                                                                                [bootstrap]
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.

Drush was attempting to connect to:
  Drupal version    : 7.22
  Site URI          : default
  Database driver   : mysql
  Database hostname : 127.0.0.1
  Database username : root
  Database name     : dev2db
  Default theme     : garland
  Administration theme: garland
  PHP configuration : /private/etc/php.ini
  Drush version     : 5.9
  Drush configuration:
  Drush alias files : /Users/dennis/.drush/aliases.drushrc.php
  Drupal root       : /Users/dennis/Sites/dev2
  Site path         : sites/default
  Modules path      : sites/all/modules
  Themes path       : sites/all/themes
  File directory path: sites/default/files
  Temporary file directory path: /tmp
  %paths            : Array

 [1051.77 sec, 102.18 MB]
PHP Fatal error:  Call to undefined function batch_get() in /usr/local/drush/commands/core/drupal/batch.inc on line 80
PHP Stack trace:
PHP   1. {main}() /usr/local/drush/drush.php:0
PHP   2. drush_main() /usr/local/drush/drush.php:19
PHP   3. _drush_bootstrap_and_dispatch() /usr/local/drush/drush.php:64
PHP   4. drush_dispatch() /usr/local/drush/drush.php:95
PHP   5. call_user_func_array() /usr/local/drush/includes/command.inc:175
PHP   6. drush_command() /usr/local/drush/includes/command.inc:175
PHP   7. _drush_invoke_hooks() /usr/local/drush/includes/command.inc:208
PHP   8. call_user_func_array() /usr/local/drush/includes/command.inc:334
PHP   9. drush_core_updatedb_batch_process() /usr/local/drush/includes/command.inc:334
PHP  10. _update_batch_command() /usr/local/drush/commands/core/core.drush.inc:1107
PHP  11. drush_batch_command() /usr/local/drush/commands/core/drupal/update_7.inc:246
PHP  12. _drush_batch_command() /usr/local/drush/includes/batch.inc:93

Fatal error: Call to undefined function batch_get() in /usr/local/drush/commands/core/drupal/batch.inc on line 80

Call Stack:
    0.0007     710016   1. {main}() /usr/local/drush/drush.php:0
    0.0298    5201720   2. drush_main() /usr/local/drush/drush.php:19
    0.1111   13019960   3. _drush_bootstrap_and_dispatch() /usr/local/drush/drush.php:64
    0.1753   15203400   4. drush_dispatch() /usr/local/drush/drush.php:95
    0.2077   15213792   5. call_user_func_array() /usr/local/drush/includes/command.inc:175
    0.2077   15214408   6. drush_command() /usr/local/drush/includes/command.inc:175
    0.2079   15215232   7. _drush_invoke_hooks() /usr/local/drush/includes/command.inc:208
    0.2087   15260392   8. call_user_func_array() /usr/local/drush/includes/command.inc:334
    0.2087   15261008   9. drush_core_updatedb_batch_process() /usr/local/drush/includes/command.inc:334
    0.2128   15873488  10. _update_batch_command() /usr/local/drush/commands/core/core.drush.inc:1107
    1.1880   32966920  11. drush_batch_command() /usr/local/drush/commands/core/drupal/update_7.inc:246
    1.1904   33063392  12. _drush_batch_command() /usr/local/drush/includes/batch.inc:93

Drush command terminated abnormally due to an unrecoverable error.                                                                                [error]
Error: Call to undefined function batch_get() in /usr/local/drush/commands/core/drupal/batch.inc, line 80 [1052.29 sec, 102.18 MB]
The external command could not be executed due to an application error. [1052.43 sec, 102.18 MB]                                                                                [error]
Finished performing updates. [1052.43 sec, 49.08 MB]                                                                                [ok]
Command dispatch complete [1052.43 sec, 49.03 MB]                                                                                [notice]
 Timer  Cum (sec)  Count  Avg (msec)
 page   3.138      1      3138.28

Peak memory usage was 50.98 MB [1052.43 sec, 49.02 MB]                                                                                [memory]
updatedb failed for userpoints [1052.63 sec, 102.22 MB]                                                                                [error]

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Upgrading Contrib Modules from Drupal 6 to Drupal 7 Handle Update Errors
Upgrading module: userpoints

If you have errors when you run the update.php script:

Note any error messages you see. Restore your site to its previous state, using the file and database backups you created before you started the upgrade or update process. Do not attempt to do
further updates or upgrades on a site that had update problems. Consult one of the support options listed on http://drupal.org/support.
Drush cannot do this step; you must perform it manually.

What would you like to do?
 [0]  :  Cancel
 [1]  :  I will do this step manually.

```

You can see, it is processing the userpoints module in this case. But for example, when i directly choose to update this module, there is no error message.

Please help me with this. Every suggestion is appreciated.

# Answer
Follow the advice in the error message: restore the site to its previous state. To do this, just run drush sup again, select the appropriate restore option, and then cancel drush sup. (Don't run with --auto).

From here, you just need to get userpoints working. You said: "When I directly choose to update this module, there is no error message." After userpoints has updated, run drush sup again; it should continue, and allow you to upgrade your other modules.

If you can't get userpoints to upgrade, ask for help in the userpoints issue queue. First search it and see if there are any existing issues related to the upgrade path.
> 1 votes

---
Tags: drush, upgrading
---


# Question
Title: Creating a node with PHP cURL client returns 401 error - X-CSRF token always empty
A recent update to Services and Drupal requires a csrf token, and it broke the PHP cURL client samples.

I am trying the sample code for Services to:

It fails with 401 error. `$csrf_token` is always empty for me, so that should be the problem, but I am not sure how to return it with cURL. Any tips?

# Answer
> 2 votes
I fixed the DrupalREST class by Randall Kent here https://github.com/RandallKent/DrupalREST.PHP/issues/2

---
Tags: 7, services, csrf
---


# Question
Title: How can I sell time slots using drupal Commerce?
I want to allow customers to purchase products for a specific time slot and within a date range. Can this be done?

I want to achieve the following.

1. Allow products to be sold within a certain date range.
2. Also allow products to be sold for a certain time within that date range, for example between 1200 and 1300 or 1200 and 1220.
3. Show availability of those dates / time slots on a calendar for people to choose from.

# Answer
> 1 votes
Looks like you are looking for Commerce Booking:

> This module provides tools to use Drupal Commerce as a powerful event booking system. Any entity can be an 'event' and a single booking can contain any number of tickets.

---
Tags: views, datetime, commerce, javascript
---


title: omega theme issue

text:
# Question
Title: omega theme issue
i am using omega theme in drupal7. i implemented theme sucessfully, but i am facing some serious issue. when i try to login with admin. everthing is working fine. but when i use other account.after login it redirects to me http://example.com/user/2/. now then i try to go to home page. it will redirects back to me at http://example.com/user/2/.

when i change my theme it is working fine.

Can anybody tell me what is the problem, or where i need to check actual problem

# Answer
> 0 votes
Have a look on the template.php in your theme directory. Probably is there something which redirects you. Or probably a Rule which is active under certain circumstances ...

---
Tags: theming
---


title: How to create a view area handler

text:
# Question
Title: How to create a view area handler
I'm building a Drupal Commerce store. On cart view I need to display some additional information.

I want to create area handler like Commerce Order: Total. It should do some php logic and display the results.

Can anybody give me some advice how to build such a handler? The documentation didn't gave me much information.

# Answer
> 2 votes
You need to create a custom module and override default area handler using hook\_views\_data\_alter().

The default implementation of order total handler placed here.

# Answer
> 1 votes
You need to:

1. implement hook\_views\_data\_alter() to declare the area handler, and specify the name of the class that implements the handler.
2. Implement the handler class, extending views\_area\_handler, and override the methods you need.

I wrote such an area handler for views\_autorefresh some months back, find the code here: http://drupalcode.org/project/views\_autorefresh.git/commitdiff/2bafcd7?hp=9108ef808df5165e946eb09cebe5bc6c9112acd2

---
Tags: views, commerce
---


# Question
Title: Is it possible to get <any> form submission diff with Diff module
Diff module, from what i've seen works with node revision differences, not node edit submission diff.

Is diffing any entity-related form submission possible programmatically through Diff module API? Suppose i alter `node_form_submit()` in my module and i want to record in watchdog the watchdog message the diff if this is a node edit event.

I try with `diff_entity_diff($old_entity, $new_entity, $context)` but i get no title changes and i'm not sure how to render this output.

Or in other words, which is the best way to get the diff of the submitted values of any form? (compare form\_states)

Thanks

# Answer
Problem is - diff compares entities and their revisions. But node\_form\_submit() happens before revision is created. If you will inspect node\_save, you will see no hooks are called after actual save.

To get your code executed and be sure revision is there, it would be tempting to use Rules, but existing bug "After updating existing content" runs before content is saved. shows it has just the same issues as hooks. Maintainers say:

> We just rely on the hooks drupal provides us here.

So now you have 2 options:

1. Give up on using diff module and just borrow some of it's code (it's open source after all)
2. On save, set a hidden field "test with diff" to true, and on cron make actual testing. With `*/5` minutes CRON it will be almost as good, as instantaneous test.
> 0 votes

---
Tags: 7, forms, nodes
---


# Question
Title: How can I get Drupal to hide menu items that user does not have permission for?
I thought Drupal was supposed to do this (and sometimes it does), but I'm not seeing this behaviour, so thought I'd ask.

My Main Menu contains three manually-added links to useful stuff.

1. Administration - **this one auto-hides**; cannot be seen by anonymous users.
2. Application - provided by a Module. Does not auto-hide, yet the module defines the path as requiring a certain permission that anonymous users don't have.
3. Documentation - link to a Documentation node type. I'm using Content Access Control and have not provided permission to view this content type for anon users. Should be hidden but is not.

Can anyone explain when drupal hides stuff and when it won't be able to? Obviously there's the "install yet another module" approach that will provide a brute-force fix, but I'm interested in why the behaviour is erratic/unreliable.

# Answer
Drupal does this using `access callback` from the menu items.

In the example given:

1. This was working.
2. The Application had `TRUE` for the access callback. As this was not my application, I used hook\_menu\_alter in my own module to set the access callback for this argument to my own function. This then checked the permission and returned true/false.
3. The Contact Access module requires rebuilding permissions (`/admin/reports/status/rebuild`) after any changes.
> 1 votes

---
Tags: routes, users
---


# Question
Title: How to get update to check Feature Server
I have a custom module hosted on a feature server. When I update Drupal how can I get it to check the Feature Server to see if there is an update there?

In the back of my head I thought it was something you could add to *.info*. However I can't find an example.

# Answer
> 3 votes
You're looking for `project status url`, which is a property that can be used in your module's .info file:

> Allows module maintainers to define a URL to check for updates to their module using the Update status module. No module released on drupal.org should define this parameter. URL should point to an XML feed that accepts requests in the form of http://my.domain.com/projects/{project}/{core}. In that example, project status url should be set to http://my.domain.com/projects.

---
Tags: 7, updating, .info
---


title: How to check if a view is grouped?

text:
# Question
Title: How to check if a view is grouped?
In a views template, I need to check if the views rows are grouped. Which property of the $view object contains this information?

---

In the example below, `$grouped = !empty($options['grouping'][0]);` seems to work. However I don't know/understand all details about the $view object and I'm not sure if this really is a solid solution. Will this work in all situations?

Currently, my `views-view-unformatted.tpl.php` looks like this:

```
<?php
$grouped = !empty($options['grouping'][0]);
$heading_classes = $grouped ? ' class="group-heading"' : '';
?>

<?php if ($grouped): ?>
  <div class="views-group clearfix">
<?php endif; ?>

<?php if (!empty($title)): ?>
  <h3<?php print $heading_classes; ?>><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
  <div<?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?>>
    <?php print $row; ?>
  </div>
<?php endforeach; ?>

<?php if ($grouped): ?>
  </div>
<?php endif; ?>

```

# Answer
> 3 votes
Some tips about your solution:

1- It looks right to me. I would try keep the logic separate from the template. I'd also declare my own template to avoid problems. Another style plugin, for example a custom style plugin, could use the original template.

```
HOOK_preprocess_views_view_unformatted(&$vars){
  if(!empty($options['grouping'])){
    $vars['heading_classes'] = $grouped ? ' class="group-heading"' : '';
    // My own template
    $vars['theme_hook_suggestions'] = 'views_view_unformatted_group';
  }
}

/*
* Implement hook_theme
*/
HOOK_theme($existing, $type, $theme, $path){
  return array(
    'views_view_unformatted_group' => array(
     'variables' => array(),
     'path' => 'PATH/TO/YOUR/MODULE',
     'template' => 'views_view_unformatted_group',
  ),
}

```

Template views\_view\_unformatted\_group.tpl.php

```
<div class="views-group clearfix">
 <?php if (!empty($title)): ?>
 <h3<?php print $heading_classes; ?>><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
  <div<?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?>>
  <?php print $row; ?>
  </div>
<?php endforeach; ?>
</div>

```

2 - The default function that manage the grouping is `render_grouping_sets()` in an style plugin object. The documentation warn about that:

> Plugins may override this method if they wish some other way of handling * grouping

The unformatted list, html list, grid and table style inherit the default methods and they don't override it.

3 - If you have nested groups, Views wrap the parent group with the next function in theme.inc:

```
function theme_views_view_grouping($vars) {
  $view = $vars['view'];
  $title = $vars['title'];
  $content = $vars['content'];

  $output = '<div class="view-grouping">';
  $output .= '<div class="view-grouping-header">' . $title . '</div>';
  $output .= '<div class="view-grouping-content">' . $content . '</div>' ;
  $output .= '</div>';

  return $output;
}

```

---
Tags: views, theming
---


# Question
Title: Is the creator of a flag stored in the database?
Is the uid of the user who created a specific flag stored in the database? Where is it stored?

# Answer
> 2 votes
Yes, it's stored in the `flag_content` table, in the `uid` column which is defined as

> The user ID by whom this content was flagged.

---
Tags: 7, flags
---


# Question
Title: How to add a universal form submit handler to ALL forms?
Suppose i need to record all form submissions in a site, i mean all of them. I would add a new submit handler to be executed after each forms submit handler, like `$form['#submit'][] = 'log_submit'` , right?

The problem is that some forms may not have the submit handler inside `$form['#submit']` array but in $form\['buttons'\] or $form\['#actions'\] etc...

How would i add my own submit handler to ALL of these forms, in one hook\_form\_alter() and in a clean way?

Thanks

# Answer
You can use `hook_form_alter(&$form, &$form_state, $form_id)` without traditional `if` inside. Then it'll work on all forms.

Problems start when submit handlers are attached not to form, but to buttons. If you have to take care about that, you will need to scan recursively form tree, find all elements with `['#submit']` set and attach your handler to them. to do this, write recursive\* function. Drupal mixes properties with children elements, so to avoid scanning properties, use element\_children(&$elements, $sort = FALSE).

\*Of course you can make it iterative, too, should be faster, but recursion is more intuitive approach.
> 1 votes

---
Tags: 7, forms
---


# Question
Title: Purging session data on devel user switch
If you have used the `devel` module, you'd probably know about the nifty *Switch user* tool that is available as a block for use in a site. It allows users with the required permission to switch from the block as any other user.

This is the API doc for the `devel_switch_user` method.

I notice that while switching between users, the session ID of the user as whom you initially logged in to the Drupal site for the first time is re-used for all switched users i.e. In `{sessions}`, the `uid` column is simply changed while `{sessions}.sid` or `{sessions}.ssid` persists.

A problem with this approach is that the session data (`{sessions}.data`) (saved using the `$_SESSION` superglobal) remains the same even for switched users which isn't good to test the application logic sometimes (at least not in my case).

Is there an elegant way to clear the session data of the old user on switch? If not, how can this be solved?

# Answer
> 1 votes
Problem is - `$_SESSION` was never really meant as temporary data storage. Proper and safe way is to use cache\_set() to store data.

First argument, `$cid` is customary used as a string with sections separated with `:`, so in your case it should look about like that:

```
global $user;
// ...
cache_set('mymodule:' . $user->uid . ':' . $user->sid . ':kind_of_data',
          $data, 'cache', CACHE_TEMPORARY);
// ...
$data = cache_get('mymodule:' . $user->uid . ':' . $user->sid . ':kind_of_data',
                  'cache');

```

That way you will allow Drupal to benefit from database permanency, memcached speed, whatever you please. And by including uid of current user, you are sure data is well separated and no collisions will occur. Including session ID allows proper anonymous user handling. For logged in part `$user->sid` might be safe to ignore, depends if you want data to be shared between logged in seats or not.

If you use session id as a part of cache key, like above, entries will be only valid for one session. If your site has few users, obsolete cache entries are not a problem. And if you have many, you should store both sessions and cache in memcached, apc or similar technology anyway. Database is simply to slow for this. Memory based cache engines are very good at automatically destroying unused entries when needed, destroying them from code is a waste of time and effort.

---
Tags: 7, debugging
---


# Question
Title: How do you override page.tpl.php in Omega 4?
I am using the Omega 4 base theme, and am trying to override `page.tpl.php`.

This file is in the base theme in sites/all/themes/omega/templates/system. When I copy it into my theme, edit it, clear caches, I don't see my changes?

Why can't I override this template?

# Answer
> 8 votes
Omega 4 includes a few changes. From the project page (emphasis mine):

> The Omega theme provides layouts as a method of managing page templates along with layout specific stylesheets and regions. This allows you to write highly customized layouts that can be contextually switched. **You can disable this feature to use the plain page.tpl.php** or even use Omega 4.x together with Panels and Panels Everywhere to gain even more control over your pages if required.

If you want to use the new layout system, clone sites/all/themes/omega/layouts/simple into your theme, rename the files, edit the layout include, and clear caches.

The goto admin/appearance/settings/mytheme, and click on the **Layouts** tab. If you did everything correctly, you can select the layout you just created, and then save your configuration.

If you don't want to use the layout system, and just want to use page.tpl.php, then untick **Enable Layouts extension**, and save your configuration.

---
Tags: theming
---


# Question
Title: How to remove View/edit option of a node in admin menu?
Drupal 7 node edit and view are showing in admin menu. How do I show it under node title?

Actually when the node is loading, the view edit options of the node is showing under the node title but when fully loaded, the view/edit options of that node is showing in the admin menu. When I checked it with the firebug, it's under admin menu css.

How do I show the view/edit options under the node title?

# Answer
1. Go to Configuration -\> Administration -\> Administration Menu.
2. Under System Tweaks, **uncheck** *Move local tasks into menu*.
3. Flush the cache and clear browser cache.
> 3 votes

---
Tags: 7, nodes
---


# Question
Title: In Drupal 7 Views how do you set permissions via roles for an attachment display?
I am trying to set roles permissions for my attachment view, but every time i set the roles permissions it affects the master display aswell. I want my attachment display only viewable to admin's of the site. Am i missing something or should is there another alternative to this issue?

# Answer
From you screenshot you gave permission to anonymous user, authenticated users and instructor. So the attachment will be visible to all users. Choose only admin for the attachment and for the page it is attached you do not need to set permissions. You settings should look something like the image below

Make sure you always apply permissions to the current display and not to all display.
> 1 votes

---
Tags: 7, views, users
---


title: Administration menu affects theming

text:
# Question
Title: Administration menu affects theming
I'm using the Admin menu in Drupal 7. I recently started developing a Zen sub-theme for my website and discovered something annoying.

My theme's heading background is a simple 200px high image (a brown rectangle) that repeates horizontally:

`body {
 background: transparent url(../images/background.gif) repeat-x center top;
}`

I created the theme while I was logged in and achieved this (first image on website). Happy as I was, I logged out and noticed with anger that my lay-out had changed (second image on website)!

I suspect that the admin menu 'pushes' all the content on my website to the bottom, while the background stays put. Is there a way to 'push the background to the bottom' aswell, so that I don't have to log out every time to see what happened when I changed my CSS theme code?

# Answer
> 1 votes
I also faced same problem with `Zen` theme and I think there is no professional fix for that.

Although, I have used the attributes `not-logged-in` and `logged-in` class'es (which will be available in body tag) to differentiate whether or not the user is logged and placed/adjusted my css accordingly.

# Answer
> 0 votes
Most themes provide div wrapper for their main content. In Skeleton Theme it's `<div id="wrap">` Simply use it (or create it if you don't have one yet) to attach backgrounds and position elements, and tools that needs space outside it would not interfere.

---
Tags: routes, theming, users
---


title: how to include multiple jquery files

text:
# Question
Title: how to include multiple jquery files
is it possible to include multiple jquery files like this one ?

```
(function ($) {
  Drupal.behaviors.mymodule = {
        attach: function(context) {
    //my code
        }
    }
}(jQuery));

```

I use this to include the files

```
drupal_add_js(drupal_get_path('module', 'mymodule') . '/js/mymodule.test1.js');
drupal_add_js(drupal_get_path('module', 'mymodule') . '/js/mymodule.test2.js');

```

both files are loaded but it seems that only the first is executed while test2 is ignored

can you help me with that ?

thanks

# Answer
In Behaviors, behavior name don't need to be the same as module name. And it cannot be repeated, unless you want to disable earlier implementation.

If you separated your code, it means it's there to do different things. So just name them accordingly, like `Drupal.behaviors.mymoduleDoSomething` and `Drupal.behaviors.mymoduleDoOtherThing`.
> 1 votes

---
Tags: javascript
---


# Question
Title: Vertical tabs of form fieldsets taking a long time to load
**UPADTE:** *I've been awarded a Tumbleweed badge for this question (Asked a question with no votes, no answers, no comments, and low views for a week). My gut feeling is this is about optimizing Drupal to speed up page loads, but maybe it's something else?*

I have a form divided into five fieldsets. The sets are displayed on my page using vertical tabs, like this:

```
// Form element: vertical tabs.
$form['vertical_tabs'] = array(
    '#type' => 'vertical_tabs',
);

// Form elements: fieldset tree.
$form['Fruits'] = array(
    '#title' => t('Type'),
    '#type' => 'fieldset',
    '#tree' => TRUE,
    '#collapsible' => TRUE,
    '#group' => 'vertical_tabs',
);

```

...etc.

When the page loads, initially just the plain form appears. It takes about 2-3 seconds for the vertical tabs 'styles' to be applied to the form. In other words, it takes a significant time to load the finished page. Has anyone else had this problem and figured out how to stop/arrest this behaviour?

I am using Zen theme, if that makes any difference. Thanks.

# Answer
> 2 votes
I'm almost 100% certain this problem is related to slow-loading javascript; As Mołot mentioned in his comment on the question, you should investigate whether something is holding up the JS from loading and/or processing when the page loads, using browser tools.

There might be some other JS that's being added on the page that's blocking the vertical tabs JS from loading/running. Do you have any 3rd-party (Facebook, Google, Twitter, analytics, etc.) libraries loaded on the page? There are some good tips for getting these things to not block the rest of the page load here: Non-Blocking Loading Of 3rd Party Scripts In Drupal.

Otherwise, do you have a module enabled or some custom code that's hindering/slowing the progress of the page load on that form? This is less likely, but sometimes if a module does something that requires a lot of CPU time (like looping through an entire taxonomy tree to build a form element or do something fancy to it) either with PHP or JS, that can cause the page load to take a really long time.

Vertical tab rendering (as well as fieldset collapsibility rendering) is usually one of the last things to load when a page loads. Something is blocking the page load/render progress, and if you can figure out what that is, you'll find the source of the problem. Good luck!

---
Tags: theming, forms
---


# Question
Title: Count total number votes a user has gained
I am using `rate` module where users can plus or minus the articles created by an author. Now, in the profile page of the author, I want to display the `total number of votes` he/she has got from all his articles. Is there any way to do this without using db\_query ? Thank you.

# Answer
> 0 votes
I think it would be pretty expensive to do this without writing your own query, but here is one way you could do it:

Use `EntityFieldQuery` to build a list of nids created by the current author. Something like this:

```
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'article');
  ->propertyCondition('uid', '1')
$nodes = $query->execute();

```

Then parse the nids returned into a seperate array and use that array as a criteria parameter in `votingapi_select_votes()`. Something like:

```
$votes = votingapi_select_votes('entity_id' => $nid_array);

```

I'm not 100% sure that `votingapi_select_votes()` accepts an array for the `$criteria['entity_id']` param. You might need to loop through each nid if it doesn't.

---
Tags: 7, views, rating
---


title: How to manually uninstall a module?

text:
# Question
Title: How to manually uninstall a module?
I'm trying to uninstall the "Browsing History Recommender" but I get the HTTP 500 Server error. I want to remove this module completely from the database and FTP.

I have been searching for a solution but no luck, I have also read this question. How to manually uninstall/purge modules?

Please Help. Thanks

Drupal 7 Ubercart 3

# Answer
If you have access to ssh, use drush to disable and uninstall the module. If you do not have access, disable your module, set the status to 0 for the module name that you want to disable.

```
UPDATE system SET status='0' WHERE name='module_name';

```

And then you can manually delete the table "history\_rec\_user\_map".

It however has two variables ('`history_rec_uid_watermark`' and '`history_rec_last_aid`') in the variables table. Use `variable_del` to delete them

To remove modules, you have to remove them from your server's modules directory (usually sites/all/modules/).

**UPDATE:**

To delete the modules blocks use `delete from block where module = 'MODULE'`
> 4 votes

---
Tags: 7
---


# Question
Title: Redirect anonymous users to login when they try to access home page for omega sub theme
I would like to redirect my anonymous users to login when they request my Drupal website. I have found many solutions for many themes but not for omega's sub theme. I like my site to limit for authenticated users.

When I used this rule:

```
{ "rules_test" : {
    "LABEL" : "Test",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "init" ],
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "1" : "1" } }
        }
      }
    ],
    "DO" : [ { "redirect" : { "url" : "user\/login" } } ]
  }
}

```

browser shows:

> The page isn't redirecting properly.

What 's I missing?

# Answer
> 1 votes
Implement a hook\_init().

```
function YOURMODULE_init(){
  global $user;
  if($user->uid == 0){
    drupal_goto('user/login');
  }
}

```

This will work but if you have cache / reverse proxy cache enabled then you might need to consider about a JS solution too.

---
Tags: 7, users, redirection, theming
---


# Question
Title: How to display a views slideshow placeholder?
I have a site where the user can add images to the content types page and (custom) project. These images are displayed in a views slideshow based on contextual filter on each page/project in a block. The slideshows are header slideshows, so there must be a placeholder slideshow, if no images are added. How can i accomplish this ? I need a solution where no further maintenance by the user is needed.

Do i have to put some if/else in the page.tpl.php or is there some more elegant way ?

# Answer
> 1 votes
Your slideshow is a View. So:

1. Go to edit page of your view
2. Expand "Advanced" field set
3. Add new item into "NO RESULTS BEHAVIOR"
4. Choose "Global: Text area"
5. Add your placeholder html there. E.g. `<div class="no-images-placeholder">NO-IMAGES</div>`
6. Save View

# Answer
> 1 votes
The Answer of milkovsky pointed me in the right direction:

1. Go to edit page of your view
2. Expand "Advanced" field set
3. Add new item into "NO RESULTS BEHAVIOR"
4. "Choose "Global: View area"
5. View to insert -\> choose the placeholder view to display instead
6. Add another contextual filter "GLobal Null"
7. WHEN THE FILTER VALUE IS NOT AVAILABLE -\> Display contents of "No Result found"
8. Save view

---
Tags: views, blocks, javascript
---


title: Issue with adding fields in Views 3.7

text:
# Question
Title: Issue with adding fields in Views 3.7
I'm having an issue with Views 3.7 not displaying all fields in the 'add field' dialog when trying to add a field to a view. There is only a small number of fields available from nodes etc whilst on my development version (which is almost identical) there are loads of fields to choose.

I have tried to copy my development version database to use on the staging version and use that but I get the same problem. Flushed caches etc.

Another related problem is when you try to add a custom header to your view, there are no selections to choose from. Click on close, and you get a page full of JSON. I am unsure where to go on from here. Anyone had a similar issue in the past? Thanks.

# Answer
> 0 votes
Views uses a lot of JavaScript, also AJAX to get latest info from the server. I had a similar problem a long time ago but that was because my Drupal instance was on my localhost and that gave errors with AJAX requests.

# Answer
> 0 votes
Disable views data caching, located in ...-\>Structure-\>Views-\>Settings-\>Advanced

I got the solution from https://drupal.org/node/1954348#comment-7280942

---
Tags: views
---


# Question
Title: How to add Properties to an Entity in code?
With Drupal (v7.22) I'm using the Entity Construction Kit (ECK) module (v7.x-2.0-rc2) and want to extend the sub module called 'ECK Example' that comes with it. Currently the example module just creates an Entity using code but doesn't include any default properties like Title, Author, Changed etc. This is the current module code:

```
$entity_type = new EntityType();
$entity_type->name = "eck_employee";
$entity_type->label = "Employee";
$entity_type->addProperty('name', 'Name', 'text');
$entity_type->save();

```

How can I enable the default properties for the Entity?

# Answer
I've been researching and playing around with the ECK module all day and have managed to answer my own question. Hopefully someone else will find this helpful.

To the example code listed just add these lines before the save() function is called:

```
$entity_type->addProperty('title', 'Title', 'text', 'title');
$entity_type->addProperty('uid', 'Author', 'integer', 'author');
$entity_type->addProperty('created', 'Created', 'integer', 'created');
$entity_type->addProperty('changed', 'Changed', 'integer', 'changed');

```
> 1 votes

---
Tags: entities
---


# Question
Title: Embedding content in a panel ctools plugin- any other options
instead of using views, on some occasions, I want to write custom code to display a list of content. I know how to create ctools content type plugins, and in here I could create my EntityFieldQuery to display my content and allow it to be embedded. I was wondering if there are any other options for making my custom code available for embedding in a panel other than creating a ctools content type plugin as mentioned. Ctools content type plugin feel a little verbose for for the task...

# Answer
I definitely understand your problem with a ctools pane feeling verbose.

Unfortunately I don't have a great fix. I tend to copy an old content type to a new one and edit names and such.

What you make not know is that the normal `single => TRUE` property of a content type can be switched to `FALSE` allowing the code to create multiple panes in a single content type. (Actually I think `FALSE` is the default, so you don't even need to).

This allows you to share a lot more code between several panes that act similarly.

Another, simpler but more limited option is Fieldable panels panes, which basically allows you to take an entity, put fields on it, and stick it directly into a variant. If your needs are simply to display simple content, that could be enough, but this isn't enough when more complex logic is needed.

Actually a pane that requires a `EntityFieldQuery` context as an argument and then basically just themes it would be very interesting. There's probably use for at least a sandbox that provided the context and content type for that. :)

I'll try to write up more details if necessary, but look at `plugins/content_types/custom/custom.inc` for an example of a content type that does the above.

Someone may also have taken the time to write a drush command to generate a content type from a template. Haven't looked around for one though.
> 1 votes

# Answer
Use blocks. You can start from here.
> 0 votes

---
Tags: chaos-tool-suite, database
---


# Question
Title: Changing values in preprocess view function
I want to preprocess view to alter a field based on another field. I am able to print the value but not change it.

I did this:

```
function MYTHEME_preprocess_views_view__VIEWNAME(&$vars){

     kpr($vars['view']->result['0']->field_field_name[0]['rendered']['#markup']);
}

```

Which prints the correct value. But when I try to change/unset the value it does not work. Both of these do not work.

```
 unset($vars['view']->result['0']->field_field_name[0]['rendered']['#markup']);

 $vars['view']->result['0']->field_field_name[0]['rendered']['#markup'] = '';

```

I also tried another way which prints the value but does not change it:

```
 unset($vars['view']->result['0']->_field_data['nid']['entity']->field_name['und'][0]['value']);

```

Note: I am rewriting the results of a field with view UI.

# Answer
> 15 votes
The `MYTHEME_preprocess_views_view($vars)` hook is executed at the end of the process to build a view. The purpose of the *views\_view.tpl.php* is a general wrapper for all elements of the view. The result of fields have been builded and rendered and they have been stored in the variable `$vars['rows']`.

If you want to change, alter, unset a view, we can do in different phases. Between them, i've chosen the pre-render phase:

```
function HOOK_views_pre_render(&$view) {
  if(isset($view->name) && $view->name == 'YOUR_VIEW'){
    // kpr($view);
    foreach($view->result as $r){
      $r->field_field_NAME[0]['rendered']['#markup'] .= '. ADDING TEXT TO CHANGE THE RESULT';
    }
  }
}

```

These are the stages that are given by Views API (you will find it in the views folder). Maybe one of them is more useful:

```
hook_views_pre_view(&$view, &$display_id, &$args) {}

```

> Allows altering a view at the very beginning of views processing, before anything is done.

---

```
hook_views_pre_build(&$view)

```

> This hook is called right before the build process, but after displays are attached and the display performs its pre\_execute phase.

---

```
hook_views_post_build(&$view) {}

```

> This hook is called right after the build process. The query is now fully built, but it has not yet been run through db\_rewrite\_sql.

---

```
hook_views_pre_execute(&$view) {}

```

> This hook is called right before the execute process. The query is now fully built, but it has not yet been run through db\_rewrite\_sql.

---

```
hook_views_post_execute(&$view) {}

```

> This hook is called right after the execute process. The query has been executed, but the pre\_render() phase has not yet happened for handlers.

---

```
hook_views_pre_render(&$view) {}

```

> This hook is called right before the render process. The query has been executed, and the pre\_render() phase has already happened for handlers, so all data should be available.

---

```
hook_views_post_render(&$view, &$output, &$cache) {}

```

> Post process any rendered data.

---
Tags: views, theming
---


# Question
Title: Simplify Panels "Add content to" popup with fewer options for end users
Echoing this unanswered question on D.O.

Is there a way to limit (and possibly reorganize) the Panels content types and panes presented to website editors?

Basically taking it from this:

To this:

I tried using some of the cTools API alter hooks, but no dice. Any pointers?

# Answer
> 1 votes
Checkout https://drupal.org/project/Panopoly \- they make a lot of customizations to this to improve the ui.

Some more details from the project page:

> Panopoly is powerful base distribution of Drupal powered by lots of Chaos Tools and Panels magic. The distribution is designed to be both a general foundation for site building and a base framework upon which to build other Drupal distributions

---
Tags: panels
---


title: Display Suite field content type class

text:
# Question
Title: Display Suite field content type class
I've created a custom field in Display Suite using this code in my module:

```
function mymodule_ds_fields_info($entity_type) {
$fields = array();

$fields['node']['type_label'] = array(
  'title' => t('Label'),
  'field_type' => DS_FIELD_TYPE_FUNCTION,
  'function' => 'mymodule_ds_field_type_label',
);

function mymodule_ds_field_type_label($field) {

$entity = $field['entity'];
$content = $entity->type;

return $content;
}

```

Now, I was able to set the content of the field to match my content type, but I also want to set a dynamic class for this field equal to that content type, for example:

```
$fields['node']['type_label'] = array(
  'title' => t('Label'),
  'field_type' => DS_FIELD_TYPE_FUNCTION,
  'function' => 'mymodule_ds_field_type_label',
  'class' => 'CONTENTTYPE',
);

```

Or:

```
function mymodule_ds_field_type_label($field) {

  $entity = $field['entity'];
  $content = $entity->type;
  $class = $entity->type;

```

So the end result should be something like this:

```
<div class="field field--name-type-label field--type-ds CONTENTTYPE">...</div>

```

How can I do this?

Thanks in advance.

# Answer
> 0 votes
Each time Display Suite is used in content output, it's wrapped in an `<article>` element with the content type as a class. You can see below that the content type can be found as `node-enterprise-blog` class.

I'm not sure what your end purpose for this is, but this way you can select the element using `.node-enterprise-blog .field-field-name`. If you need to add a class to the field, consider using the **Field Template** option under DS Extras. It allows you to change the markup of each field in a view mode.

---
Tags: entities, theming, display-suite
---


# Question
Title: views aggregation - number of results per group
I have a content type - lets say favorite color - where you can choose blue, green, red ....

* One node of favorite color has red
* Another node of favorite color has green
* Another node of favorite color has again red

and do so on

I would like to show in views3.7 the name of the color and how often it occurs:

* red: 10
* green: 6
* blue: 3

How do I do this? I think its aggregation but I cant display the number of each result...

# Answer
If what you're trying to show is the number of nodes tagged with a certain term (I'm assuming that color field is a term, not a select text field), then the following Drupalwoo tutorial has detailed step-by-step instructions on creating a view that shows the number of nodes per term.

Here are the basics - just without the screenshots.

1. Your view should be setup to display taxonomy terms, not nodes.
2. Add a **relationship** that is '`Taxonomy term: Content using <term name>`', in your case the term name will be something like 'Color'
3. Configure the relationship to be required or not: depending on whether you want to show colors even if there are no nodes tagged with that color
4. Select to use **aggregation** in the view's advanced settings
5. Add a node field to this view that is excluded from the display, but is used to count the number of node instances under each term. I would select the '**Node: nid**' field for this purpose. Make sure to use the relationship setup above
6. Finally - select '**Count DISTINCT**' as the type of aggregation for this field
7. You'll probably want to style the output a little: in your example you want to use a colon between the term and the count, while in the blog's example above there are parentheses! Feel free to style however!
> 3 votes

---
Tags: views
---


# Question
Title: How to make content work with and without javascript
I have some content that I currently use a javascript dialog box to display. This works great when javascript is enabled but not so good when javascript isn't (it shows the dialog components on the screen along with original content). I would like to fix this so that dialog contents display on a separate screen when javascript is not enabled. I thought I saw some documentation somewhere on how to do this but for the life of me I can't find it by googling it again. Can someone point me to the proper online documentation on how to do this?

**Additional Info:** The page has a button on it that allows the user to create a new item. With JavaScript enabled, the add button displays a dialog box in which the user can enter information about the new item. Currently the text/input fields for that dialog box is on the same page the add button is on but hidden by Javascript using special divs (hence why it is visible when JavaScript is disabled). This is code I inherited from someone else and now would like to fix.

# Answer
> 2 votes
This isn't specific to Drupal but its a javascript technique known as 'unobtrusive javascript'. Not knowing how you are displaying the dialog contents, let's assume this simple case:

```
<a href="http://link-to-dialog-content" class="dialog-trigger">See Dialog Content</a>

```

and then somewhere else in your code (next to?) you've got a div with your dialog content set to not display, ex:

```
<div style="display:none">Your dialog content here .. </div>

```

What you want to do is use jquery (you can do this with native javascript but you're using drupal so its already loaded) to bind a click handler to this link. The idea is then that if javascript is not loaded, then the browser will automatically send them on their way. So that would look something like this:

```
$(".dialog-trigger").click(function() {
   // do your display stuff here,
   return false;
}

```

The 'return false' statement at the end is key here to making it so that the link won't be followed.

---
Tags: 7, javascript
---


# Question
Title: "Unable to generate the derived image located at public://styles/uc_category/public/tg.jpg"
(Drupal 7 under Linux)

This is clearly a Drupal permissions problem, but I'm baffled. If I

```
rm -rf styles

```

and refresh the page causing the error, styles and it's sub-dirs are re-created thus:

```
drwxr-xr-x 3 www-data www-data 4096 Jan 25 16:07 styles

drwxr-xr-x 3 www-data www-data 4096 Jan 25 16:07 uc_category

drwxrwxr-x 2 www-data www-data 4096 Jan 25 16:07 public

```

But I still get the error. And I *still* get it if I

```
chmod -R 777 styles

```

Any suggestions?

# Answer
> 0 votes
If you are sure this is not a permission issue, also make sure you have a graphical library installed on your server.

In D7, the configuration page for this is: /admin/config/media/image-toolkit

---
Tags: 7, files
---


# Question
Title: Does elysia cron need to be executed through Drush cron?
I am trying to understand how Elysia Cron works. If I execute the cron through a curl/wget requests, will the elysia cron still run normally without risking timeouts? Are there any advantages to running it through Drush rather than curl/wget?

# Answer
The module page is fairly clear ...

> For the basic install you only need to enable the module and Elysia Cron will be up and running.
>
> You can stop here if you don't need a great precision over task execution and you don't have to execute a task more often than once an hour. For example, if you need only the "Once a day", "Once a week" or "Once a month" schedule rules the basic install is fine. (For D6 users that want to stop here: you should have installed Drupal crontab as described in Drupal INSTALL guide).
>
> However to get the full potential out of elysia cron and have the full control over you tasks a further step is needed: you need to configure the system crontab to execute drupal cron every minute. Follow the Drupal guide about this: http://drupal.org/cron The only difference is that you should use the "\* * * * \*" rule part instead of "0 * * * \*" or "45 * * * \*" as described in the guide.

Cron is a server thing, not a Drupal thing. Hook\_cron is a nice PHP interface to stuffing custom tasks into the file `http://www.mysite.com/cron.php` which Drupal's Poor Man's cron or ElysiaCron can use to run your tasks.

As the above notes -- if you just need daily runs, weekly runs, monthly runs -- simply enable the barebones Elysia or Drupal cron. For more fine grained control over cron tasks they recommend a system crontab entry that polls Drupal cron every minute. Elysia's task management logic checks what tasks it has to do in X timeperiod every minute (whats Done, what is to begin, whats running, etc). This is the power of Elysia cron and also UltimateCron.

Whenever a browser hits `cron.php` you are subject to timeouts -- even if programming attempts to avoid it (such as the Batch API, which *can* sometimes timeout and fail -- eg what happens when your webserver (Apache) is under load and the next `cron.php` call is never successfully handled?).

By running via Drush you are 100% free of worrying about webserver timeouts -- because its now a server side PHP script which may run indefinately.

* 1 advantage of running through Drush is you can pipe output from your cron tasks (there shouldnt really be any) to a custom file.

You can invoke a Cron run directly using Drush via: `drush cron` for all options to Drush cron see `drush help cron`
> 3 votes

---
Tags: drush, cron
---


# Question
Title: D7: Change Drupal "Link" field to store node url instead of alias for internal links
I am using the "Link" field in Drupal 7 to store links. Sometimes these links are internal and sometimes they are external. In the case of internal links, I would like to be able to store the system URL ("node/371") instead of an alias ("about/mission-statement") so that the link field will auto-correct itself when someone changes the URL alias.

Entity Reference is great for keeping track of internal nodes, but I would like the same field instance to handle both internal and external links.

Advanced Link doesn't seem to do this processing either.

Is there another module I should use, or a hook I can use to intercept the link field processing pre-storage?

**EDIT**

I was able to hack the module to get the behavior I wanted by adding two lines of code to `_link_process` :

```
$systemPath = drupal_lookup_path('source',$item['url']);
$item['url'] = ($systemPath) ? $systemPath : $item['url'];

```

… although it would be nice to be able to do this in a way that preserves an upgrade path.

# Answer
> 0 votes
That's a pretty small hack, and probably fairly easy to keep track of, but as you likely know it's probably not a good idea for a variety of reasons.

Another option: The Link checker module. It has a setting for "Update permanently moved links" (see below).

So after your internal page moves, Link checker will automatically change the link to the new alias for you (depending on what you choose for the fail threshold).

# Answer
> 0 votes
I use pathauto. it should automatically keep up with your node name changes and point to the right internal ref, right?

Then there's Node redirect?

Extended path alias might be promising, too. Extended path aliases

---
Tags: 7, entities, navigation, path-aliases
---


title: Google Analytics Marketplace

text:
# Question
Title: Google Analytics Marketplace
I'm running Drupal 7 along with the Google Analytics module. I have an eCommerce Marketplace setup with store fronts and unique products per store. I'd like to have analytics per store so that each store owner can see the traffic coming to their page/products.

I'm using Organic Groups to setup the stores with Group Type: Store and Group Content: Products. I have custom variables setup relating to the Group Reference.

My question is:

How can I filter page requests in Google Analytics to specifically those relating to a certain group/store so that when a store owner views their analytics they are only seeing the requests for their "pages"?

# Answer
> 1 votes
One option may be to simply bring the Google Analytics data into your website, where you can then leverage the power of views to display the view statistics for the exact pages you want.

If you use the Google Analytics Statistics module, you should be able to set it up to download view stats either for the past 24 hours, 48 hours, week, month, etc and it'll do that as you run cron. The config page is at /admin/config/system/ga\_stats. After connecting it to your Google Account by typing in your Google Login, the module setup looks something like this:

Then - you can view your Google Analytics statistics on your site (rather than through the Google Analytics interface) and can create any number of views for your different page groups as you want. The module integrates with views...

Let us know if that works for you.

I've only recently found out about this module and started using it, so I'd be interested in any others chiming in here...

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


# Question
Title: Enforcing minimum number of characters for #autocomplete_path
I have a form that is using `#autocomplete_path` on a textfield. In general it works fine.

Is there a way to have the autocomplete callback not fire until a minimum number of characters have been entered?

Is the only real option to override `Drupal.ACDB.prototype.search` with my own version, or is there a clean way to do this?

I am not interested in server side solutions to limit the result set; I am trying to decrease server load here and really need a client-side solution to prevent useless requests from ever being generated.

# Answer
Here's two approaches:

1. Replace the entire `autocomplete.js` with your customized version

```
/**
 * Implements hook_js_alter
 * Replace autocomplete.js with customized version
 */
function MY_MODULE_js_alter(&$javascript) {
  $javascript['misc/autocomplete.js']['data'] = drupal_get_path('module', 'MY_MODULE') . '/js/autocomplete.js';
}

```
2. Override `Drupal.ACDB.prototype.search` with a custom version

Copy to theme script.js or module js file, as long as it's added after `/misc/autocomplete.js` it will override it.

```
(function($) {

/**
 * Performs a cached and delayed search.
 *
 * Override adds minimum text string length for lookup.
 * See /misc/autocomplete.js for original function.
 */
Drupal.ACDB.prototype.search = function (searchString) {

  // Minimum search string length
  var min = 3;
  var db = this;
  this.searchString = searchString;

  // See if this string needs to be searched for anyway.
  searchString = searchString.replace(/^\s+|\s+$/, '');
  if (searchString.length <= min ||
    searchString.charAt(searchString.length - 1) == ',') {
    return;
  }

  // See if this key has been searched for before.
  if (this.cache[searchString]) {
    return this.owner.found(this.cache[searchString]);
  }
  // Initiate delayed search.
  if (this.timer) {
    clearTimeout(this.timer);
  }
  this.timer = setTimeout(function () {
    db.owner.setStatus('begin');

    // Ajax GET request for autocompletion. We use Drupal.encodePath instead of
    // encodeURIComponent to allow autocomplete search terms to contain slashes.
    $.ajax({
      type: 'GET',
      url: db.uri + '/' + Drupal.encodePath(searchString),
      dataType: 'json',
      success: function (matches) {
        if (typeof matches.status == 'undefined' || matches.status != 0) {
          db.cache[searchString] = matches;
          // Verify if these are still the matches the user wants to see.
          if (db.searchString == searchString) {
            db.owner.found(matches);
          }
          db.owner.setStatus('found');
        }
      },
      error: function (xmlhttp) {
        alert(Drupal.ajaxError(xmlhttp, db.uri));
      }
    });
  }, this.delay);
};
})(jQuery);

```
> 3 votes

# Answer
I am not suggesting that you should just go and edit this directly, but, the behavior is dictated by just having any characters entered into the input field.

Thus, you could change

```
if (input.value.length > 0)

```

to

```
if (input.value.length > WHATEVERVALUE)

```

around line 94 in `misc/autocomplete.js,` and, for D7, you could change

```
if (input.value.length > 0 && !input.readOnly) {

```

around line 102 similarly.

Of course, this will be creating a site wide behavior change (and hacked core) so maybe/hopefully there is a way to include a different `autocomplete.js` in for your specific form/form element (overriding `theme_textfield()` might work).
> 2 votes

# Answer
I'm not aware of a clean way to do this persay besides overriding. D8 mostly re-wrote most of the autocomplete ajax because its a rather limited library in D7.

That being said if you dont want to override stuff you can always use the bundled jQuery and its auto-complete functions to do the same thing -- it doesnt end up being that much code. Here is an example from a Russian blog for jquery autocomplete in Drupal 7 with a live example on the page which I have adopted on 1 of my own projects.
> 1 votes

---
Tags: forms, ajax
---


# Question
Title: How to move every node to its own subdomain with Drupal?
I have a content site that was affected by Google Panda, and recently it was suggested that it is advised by Google that moving content to subdomains might work.

Does anyone have a working solution to move aliased nodes to their subdomains so mysite.com/subfolder/my-great-content moved to my-great-content.mysite.com ?

I found this but seems to be abandoned: http://drupal.org/project/subdomain

Also this which is very advanced: http://www.easymodrewrite.com/example-subdomains

Or is multisite the way to go? I notice drupalgardens.com has subdomains for user pages.

Also found another method that uses the PURL module for Open Atrium, described here: https://community.openatrium.com/documentation-en/node/708 I guess this could be combined somehow with a wildcard subdomain setup? I notice it even has a subordomain module http://drupal.org/project/subordomain

Here is a general solution https://stackoverflow.com/questions/1943356/creating-subdomains-programmatically

# Answer
> 1 votes
http://drupal.org/project/domain is probably the way to go. You can do subdomains/multisites and specify exactly what tables be to shared from the database. This video is good documentation on what the module can do and how to integrate it.

# Answer
> 2 votes
A couple years later... I have a similar requirement.

The Subdomain Field module works well for me. https://drupal.org/project/subdomain\_field

Has clear installation instructions: edit your `settings.php`, update your virtual host, add a wildcard DNS record. Then simply install the module and add a "Subdomain Field" field type to any content types that you want.

Now when I edit `/node/2` and change the subdomain, I have `subdomain.example.com` displaying the contents of node 2. Perfect!

Note that it requires the Entity API module, but that is currently not listed as a "requirement"

---
Tags: path-aliases
---


# Question
Title: How can I dynamically change the display format?
I have an entityreference field. I want to change the 'Format' under 'Manage Display' from 'Rendered Entity' to 'Label' based on custom logic. Basically, what I'm doing is, if there isn't an image in a node (field\_image), it will load a default image from the taxonomy term. If there is an image in the node, it will just display the label. Sorry if this has been answered, but I can't find anything on it. I've tried hook\_entity\_view\_alter, but I don't think that's the right one.

# Answer
You can do that printing directly the entityreference field in the node.tpl.php. First you need to check if the image field exists and then display the entity reference, so you can do something like this:

```
if(!$content['field_image']){
   //Load default image
}else{
   print 'Your custom label.';
}

```

You have to remember to set the format to hidden in the display section.
> 0 votes

---
Tags: entities
---


title: Field for publication status

text:
# Question
Title: Field for publication status
I already browsed several posts but did not find an answer. I want to be able to make a list view that shows all my articles. Additionally the articles' teasers should show if the article has been published or not yet.

My Problem: The publication status doesnt exist as a field, so I cant add it to the lists' teasers. How can I achieve this ?

Thanks in advance,

Martin

# Answer
Views has a field:

> Content: Published
> Whether or not the content is published.

You should be able to add that to your Field based View to show the published status.
> 0 votes

# Answer
You have two ways of doing it:

1. In node.tpl.php file simply access `$node->status` property and output what you need if `$view_mode == 'teaser'`.
2. Use Computed Field to create a field that simply copies value of `$node->status` property, then use it as any other field.
> 0 votes

---
Tags: database
---


# Question
Title: Load content without refreshing page in views
i am trying to create a view with pagination. In this view i have images and fivestar rating for it. When user clicks on next i want next image and fivestar to load with out refreshing page.

Thanks.

# Answer
> 4 votes
What you need is the views load more module

> This module has some very key differences then the other load more module.
>
> * Provide ajax/no-ajax views load more
> * Works with views default ajax implementation, no hacks (check/uncheck ajax)
> * Supports the Waypoints module for loading on various points, Such as when the scroller is visable on the page.
> * Supports the Fade effect when loading new content

---
Tags: views, media
---


# Question
Title: How can I get the number of comments per page?
I need the value "default comments per page" for special theming in comments-type.tpl.php for Drupal 6. Should I use `variable_get()`?

# Answer
Those variables are stored per content type, named `comment_default_per_page_TYPE`. So to get the default comments per page for the `article` content type you would use:

```
$default = 50;
$per_page = variable_get('comment_default_per_page_article', $default);

```
> 2 votes

---
Tags: theming, paging
---


# Question
Title: Multiple regions in a zone with different widths
I am using Omega / Delta / Context on my local environment and created a sub-theme with omega-tools. I want to add more regions to the footer section. I want the regions to be similar to that of Postscript One-to-Postscript Fourth.

Im not sure if ill be able to explain well in words, hence i have taken screen-shots of what i intend to do and what am i doing to get it and the output. http://pho.to/2qA1P (Sorry for the external link, i don't have enough reputation yet to share more images)

*How do i want the layout:* I want the regions Footer Links One, Footer Links Two, Footer Links Three, Footer Links Four to appear between: Footer First and Footer Second. In this order:

```
    Footer Zone        Column Count: 12 Cols
    Footer First       Width : 12 Cols
    Footer Links One   Width : 3 Cols
    Footer Links Two   Width : 3 Cols
    Footer Links Three Width : 3 Cols
    Footer Links Four  Width : 3 Cols
    Footer Second      Width : 12 Cols
    Footer Zone

```

and i have accordingly changed the region `Weights` and `Widths` in above regions, under `Zone Configuration`.

However, in the actual result the Footer Links regions are not displayed within Footer First and Footer Second regions.

Strangely, when i created a Delta and applied it to a Path with Context, i get the output exactly as i intended.

Please help me on how to fix this.

Alternatively, i was thinking to get Footer Link regions under a separate Zone and place 2 new zones above and below this zone with regions Footer First and Footer Second. Not sure if this is the correct way.

Kindly help. Thanks.

# Answer
This issue has been resolved.

What i did to resolve the issue:

I had to setup the Zone in the sub-theme settings first. So i went to the sub-theme settings and assigned Weights from 0-5 for Regions Footer First uptil Footer Second.

Once this was done, the changes were reflecting properly.
> 0 votes

---
Tags: theming
---


# Question
Title: Content encoding error after enabling cache, aggregation and compression
Yesterday I turned on caching, aggregation of css and js files and turned on compress cached pages. Then I logged out and closed my browser (FF). After a couple of minutes I openend my browser again, typed in the url of my website and got this error in FF: Content encoding error.

I tried opening my site in FF, Chrome and IE. None of them work.

I read some similar threads here and tried: \- setting display\_errors=Off in php.ini \- disabling gzip of files in .htaccess \- Changing "Header append" to "Header set" in .htaccess

Nothing seems to work.

What I would like to do now is manually disable caching, aggregation and compression in the database, but I don't know which tables these settings reside in.

# Answer
> 4 votes
Add this lines to your settings.php file.

```
$conf = array(
'cache' => '0',
'preprocess_css' => '0',
'preprocess_js' => '0',
'block_cache' => '0',
'page_compression' => '0',
);

```

or with Drush

// To turn on JS Aggregation

```
drush vset preprocess_js 1 --yes

```

// To disable JS Aggregation

```
drush vset preprocess_js 0 --yes

```

// To clear cache of JS and CSS only

```
drush cc css+js

```

// To enable CSS Aggregation

```
drush vset preprocess_css 1 --yes

```

// To disable CSS Aggregation

```
drush vset preprocess_css 0 --yes

```

---
Tags: 7, caching
---


# Question
Title: DB Query replaces %s inside LIKE operator
I have one query like :

`db_query("SELECT * FROM {foo} WHERE bar LIKE '%supply%' LIMIT %d,%d", 0, 10)`

Now if I use `db_query` API it will replace `%s` with the argument supplied and resulting query will be like

`SELECT * FROM foo WHERE bar LIKE '0upply%' LIMIT 0, 0`

Any ideas to overcome this ? I dont want to use `mysql_query()`

I am using temporarily `_db_query()`

# Answer
> 5 votes
You just need to escape `%` signs with another `%` sign in a Drupal db query:

```
db_query("SELECT * FROM {foo} WHERE bar LIKE '%%supply%%' LIMIT %d,%d", 0, 10);

```

If you wanted to use a placeholder it would be like so:

```
db_query("SELECT * FROM {foo} WHERE bar LIKE '%%%s%%' LIMIT %d,%d", 'supply', 0, 10);

```

# Answer
> 3 votes
I answer belatedly but it might be useful to another.

Simply set the LIKE condition as a string placeholder and passes its value as an argument to the function `deb_query()`:

```
db_query("SELECT * FROM {foo} WHERE bar LIKE '%s' LIMIT %d, %d", '%supply%', 0, 10);

```

---
Tags: 6, database
---


# Question
Title: Clear cache on view at a set date from a node field value?
What would be the best approach to clear the drupal cache on the exact date and time that a node Date field is set to? It's easy enough to do it on node save, but if the node is to be included in views at the specific time that a date field is set to, then I would need someway to set the cache to be cleared at specific times corresponding to date field values on nodes?

# Answer
If the node is scheduled to be published in the future then presumably the node will also be saved at that time, to update its status. So the cache can be cleared on node save at that point.
> 3 votes

---
Tags: views, caching, nodes
---


# Question
Title: Lightbox gallery is not working in mobile website
I am using D7 and lightbox2 for image gallery.

I'm using same in the mobile version too. But the lightbox popup is not opening and showing in mobile browsers. It will work sometimes and will never work on another occasion. What is the reason of this issue?

Using `Lightbox2: lightshow:thumbnail->original` in content filed display, I used other options, but showed the same issue.

After that is used colorbox, it's working ok but when we close the popup window the parent window is blank and showing the same error `undefined`

> undefined

Also the page url is changed to the image url. E.g., `www.site.com/sites/default/files/DSC_0164.jpg`

**Mobile jQuery 7.x-2.0-beta1 (default mobile theme by Mobile Switch)**

How can I overcome this issue? How can I open image in modal window. It was working perfectly before, now it's showing the problem.

# Answer
At last I found an alternative solution for image gallery:

Photoswipe,it is working for me...(Compatible with lots of mobile devices and all popular JavaScript libraries and development frameworks. )

```
http://www.photoswipe.com/

```

sample:

```
http://www.photoswipe.com/latest/examples/04-jquery-mobile.html

```
> 0 votes

---
Tags: javascript
---


# Question
Title: 7 - Mapping multiple LDAP groups to single Drupal roles using Boolean operators
I'm attempting to set up fairly complex permissions in D7 based on LDAP group membership, and it would help greatly if there were a way to use Boolean operators to perform the role mapping.

**Some context:**

1. **There are multiple, similar departments:** each has a pool of employees, and each has a manager.
2. **LDAP groups map to departments as well as roles.** The manager of the Finance department belongs to two groups: one that designates the group **Finance\_dept**, another that designates the group **Managers**.
3. Managers should have R/W access to parts of the site that **correspond only to their respective departments**; employees should only have R access.

**What I've tried (and ruled out):**

I have the LDAP module configured to provision Drupal roles based on LDAP group membership--that piece works well for one-to-one mappings; e.g.:

* Finance\_dept|finance
* Managers|managers

I've tried various iterations of LDAP search filters, to no effect:

* Finance\_dept & Managers|finance\_managers
* (&(Finance\_dept)(Managers))|finance\_managers

Has anyone gotten this to work?

# Answer
> 0 votes
Until I can find (or someone else posts) a better way to do this, my interim solution is:

1. Set up LDAP group -\> Drupal role provisioning as normal.
2. Use the Rules module to assign/revoke another role programmatically on events *User has logged in*, and *Before saving a user account*.

# **Example** (referring to my question above):

## LDAP Provisioning:

* Finance\_dept|finance
* Managers|managers

## Create roles manually:

* financemanagers

## Rules:

**Finance\_dept + Managers = FinanceManagers**

* *Events:* User has logged in, Before saving a user account
* *Elements:* User has role(s): finance, managers
* *Actions:* Add user role: financemanagers

**Removed from either Finance or Managers**

* *Events:* User has logged in, Before saving a user account
* *Elements:*
    + NOT User has role(s): finance
    + OR
    + NOT User has role(s): managers
* *Actions:* Remove user role: financemanagers

Works for now, but it won't scale well beyond a handful of role combinations.

---
Tags: users, authentication-authorization
---


title: 'print render($content['links']);'

text:
# Question
Title: 'print render($content['links']);'
Which links is Drupal referring to in 'print render($content\['links'\]? 'Links' is kind of general to me so I am wondering which links this php snippet is referring to.

I've looked at Drupal's theming references and saw only a list of variables for theming.

# Answer
The links it is referring to are the comment links, statistics links and translation links of a node.

So in a situation where you want just the comment links, it would be

```
print render($content['links']['comment']);

```

For more information, see this page.

https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal\_pre\_render\_links/7
> 2 votes

---
Tags: 7, theming
---


# Question
Title: Can the path of Search module (/search) be changed without altering the module, to allow use of this path by a custom module?
I am dealing with a custom search that, for years, has been accessible via /search. New site requirements call for the Search core module. However, that module has hardcoded /search in `hook_menu()`.

I can not find a way to change the path for the core module without changing that module, which I do not want to do.

Notes:

* I have seen `hook_url_inbound_alter` but I don't think this will work, as I still need /search to work.
* I have disabled the menu item, but that just results in a "Not Authorized" page to non-admin users.

# Answer
If you don't like what module sets in it's `hook_menu()`, alter it with your own `hook_menu_alter()`. Example code:

```
mymodule_menu_alter(&$items) {
  // Copy search to another place
  $items['look'] = $items['search'];

  // remove all old search settings
  // optional if you will also follow next step
  unset($items['search']);

  // add your menu item below instead of usual hook_menu
  $items['search'] = array(
    // ...
  );
}

```

This will unset /search path, and move all it's settings to /look path.

Worth noting is that if module generates links to /search anyway, it means it has it hardcoded somewhere. Happens. If so, you need `hook_form_alter()` or it's analogue to alter also these links.
> 2 votes

---
Tags: 7, routes, search
---


title: ocupload module functionality

text:
# Question
Title: ocupload module functionality
I have installed the ocupload module and works very well at my localhost enviroment.

But the problem appears to me when i deployed to the testing enviroment the upload failed ant the alert message says error 200 - 401.

I walked throw the installation steps well and give the permissions for files .

I know it isn't a module bug but i need help to fix it or catch where the error comes from (running nginx with authentication required by the web server).

thanks in advance

# Answer
> 0 votes
It solved by :

1- give the right permissions for the images folder (where the uploaded images).

2- disable the web server authentication.

hint (if you use ckeditor add the tag img to the text format)

---
Tags: wysiwyg
---


title: Fine-grained flag permissions

text:
# Question
Title: Fine-grained flag permissions
Is it possible to control permissions relating to flags more closely, either in flag.module or by installing another module? I'd like to be able to control permissions for each flag, such as "Flag content with this flag", "unflag content with this flag", "view this flag" etc etc.

# Answer
> 0 votes
Are you looking for a 'local' flag? Flags are already separated into global and local flags. For example, a global flag might be 'report this comment' and once one person flags the comment it is flagged for everyone. Local flags on the other hand are unique for each user, so for example a 'bookmark this' flag would only be for the current user context and other users wouldn't be able to modify their flags. From the documentation:

> Flags may be per-user, meaning that each user can mark an item individually, or global, meaning that the item is either marked or it is not marked, and any user who changes that changes it for everyone.

You set whether a flag is global or local when you create it.

---
Tags: 7, flags
---


title: Customise entity reference autocomplete

text:
# Question
Title: Customise entity reference autocomplete
How do I override the look up on an entity reference autocomplete field? I would like to limit the look up to nodes of a certain type that have been created by the user that is creating the current node.

# Answer
The Entity Reference module integrates with the Views module in a few ways. One of these is a new display called Entity Reference.

Create a view, and filter it to your needs. Then, add a new Entity Reference display. Configure this.

Then, on your content type(s), edit the entity reference field. Make sure you are using the AutoComplete widget. You should see a fieldset called Entity Selection. Change this from "Simple (with optional filter by bundle)" to "Views: Filter by an entity reference view". You should then see a dropdown appear which will have all of the views you have created that have Entity Reference displays. Pick your view and save.

Keep in mind, though, that views with large datasets can cause dramatic performance problems with autocomplete fields.
> 2 votes

---
Tags: entities
---


# Question
Title: Views Data Export Module hide button when unfiltered
I'm using the Views Data Export module to export an Excel spreadsheet of search results from a View. The problem is that the button is still visible when the View is unfiltered, and the full export of several thousand records (on the fly) chokes the server. Is there a way -- through the Drupal admin interface, since I don't have server access -- to simply hide the "XLS" button when the full dataset is being displayed? Hiding the button when the search results are above a certain threshold count would be even better.

# Answer
You have a number of options, you can apply a default views filter that is applied on page load through the view settings.

You can also use javascript to test if all the filters are on "All" then hide the button with CSS
> 0 votes

---
Tags: views, importing-exporting
---


title: Use multiple widget types for one field

text:
# Question
Title: Use multiple widget types for one field
I would like to have different field widgets for distinct forms. Is there a way to define multiple widget types for a single field? Here's my case: on the create content form, the widget for the field "Tags", which is a term reference field, is an autocomplete term; but on another form that uses that same field, I would like to use a select list for the widget.

# Answer
I'm seeking clarification but I'll go ahead and add this here:

As you commented, you can use `hook_field_widget_properties_alter()` like this:

```
function important_dates_field_widget_properties_alter(&$widget, $context) {
  // kpr($widget);

  $pageCheck = FALSE;
  $formPath = 'my/form/path';
  if ($formPath == current_path() || $formPath == request_path()) {
    $pageCheck = TRUE;
  }

  if ($pageCheck) {
    // switch from options to autocomplete
    /*if ($widget['type'] == 'options_select') {
      $widget['type'] = 'taxonomy_autocomplete';
      $widget['module'] = 'taxonomy';
    }*/
    // switch from autocomplete to options
    if ($widget['type'] == 'taxonomy_autocomplete') {
      $widget['type'] = 'options_select';
      $widget['module'] = 'options';
    }
  }
}

```

You can not define multiple widgets for a field. You can, however, create another field of type "Term Reference" and choose a different widget.
> 3 votes

---
Tags: hooks, entities
---


title: Search multiple databases

text:
# Question
Title: Search multiple databases
Running a website on Drupal 6.

I'm currently using Faceted Search to search the default database for the website.

I've installed a separate Knowledgebase application (KB Publisher) which has it's own database and search, but I would like to use one search box (the default website search box) to index/search BOTH the default website database & the Knowledgebase database.

I'm not really a hard core programmer and am looking for some ideas/assistance in doing this?

Thanks,

John

# Answer
> 0 votes
I don't think any easy solution exits. But you can connect to another database by adding below lines into your settings.php file.

$db\_url\['mydb'\] = 'mysql://user:pwd@localhost/anotherdb';

and use db\_set\_active() function in appropriate places to query other database while your existing database index. You may need to have a deep look in to the Search module for that.

---
Tags: search
---


title: Taxonomy terms with image?

text:
# Question
Title: Taxonomy terms with image?
Can I associate an image field to a taxonomy term? I need to do this in my panel that lists the children terms (with images to make it look nice) of a parent term page. I have already added image field in vocabulary thus images for each terms.

I'm on D7.

# Answer
> 7 votes
In D7 Terms are "entities", which means you can set an image field right on them, just like you could have with CCK in Drupal 6.

Just go to manage fields on whatever vocabulary you want, and you can add the image field.

# Answer
> 3 votes
In D7 taxonomy is an Entity so you can add fields to it and make more usable. Yes you can add an image field and you can use display formatters to display the image. You can use Display Suite module or Entity View Mode module to create new view mode and display it on entity view.

If you want to add term to content, just use Entity reference module not the term reference.

# Answer
> 2 votes
To display the images you assigned to your terms you need to follow the instructions here: https://drupal.org/node/1224916

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