# Question
Title: Prevent empty <li> item in Views (HTML List format)
I'm using the HTML List format for my View, which has three fields (nid and title, both excluded and Custom Text).

The content of Custom Text is as follows:

```
<li class="inspiration portfolio" data-content="#colio_c[nid]">
<a class="button colio-link" href="#">View Project</a>
<h4><a class="colio-link" href="#">[title]</a></h4>
<p>Lorem Ipsum</p>
</li>

```

I've noticed that using the `<li>` item in my Custom Text field will result in an empty `<li>` item wrapping my content. As such, the output I get from this is as follows:

```
<div class="view-content">
<div class="item-list portfolio">
<ul class="list">
<li class="">
<li class="inspiration portfolio" data-content="#colio_c7">
<a class="button colio-link" href="#">View Project</a>
<h4><a class="colio-link" href="#">Item 1</a></h4>
<p>Lorem Ipsum</p>
</li></li>
<li class="">
<li class="inspiration portfolio" data-content="#colio_c8">
<a class="button colio-link" href="#">View Project</a>
<h4><a class="colio-link" href="#">Item 2</a></h4>
<p>Lorem Ipsum</p>
</li></li>
</ul>
</div>
</div>

```

My question to you is: How do I remove those empty `<li class="">` tags?

I tried to set wrapping element to none but to no avail. I've also attempted to do it with an unformatted list and create everything in custom text but then I'd have a `<ul>` for each row and I do not have access to `data-content="#colio_c[nid]` that way.

An export of my view is available at http://ideone.com/KyNGO4

# Answer
It sounds like you want to override the row style output so that it doesn't output the wrapping li tag. There are other posts on here asking about that process. To get started though, in views, expand the Advanced section and click "Theme" - a window will then pop up showing you information on the template files for your theme.
> 0 votes

---
Tags: views
---


# Question
Title: It is possible to set up a menu item with hook_menu that points to an existing path?
The accepted answer here by marcvangend explains how to it with `hook_menu_alter`. His method works, even if you skip step one (the block View).

But just out of interest: Can you do this by means of `hook_menu`?

So far, I've tried to put the following in `hook_menu`:

```
$items['node/%node/delete'] = array(
  'title' => 'Delete',
  'access callback' => TRUE,
  'type' => MENU_LOCAL_TASK,
);

```

However, that did not have any effect.

(Just to make clear, I just want the "Delete" tab, pointing to this existing path `node/%node/delete`. I don't want to put a view on it.)

# Answer
> 2 votes
You can only use hook\_menu() if you're defining new paths, ideally, paths that are provided by the module implementing the hook.

If you want the Delete link to show up as a tab, hook\_menu\_alter is definitely the way to go, and adjusting the context value is what does the magic - as per Step 2 from marcvangend's post. If you want to change the "access callback" as per your snippet, then you can do that in hook\_menu\_alter() too, although I'm not sure why you'd want to let anyone delete pages?

# Answer
> 2 votes
One of the functions that invokes hook\_menu(), menu\_router\_build(), uses the following code.

```
  $callbacks = array();
  foreach (module_implements('menu') as $module) {
    $router_items = call_user_func($module . '_menu');
    if (isset($router_items) && is_array($router_items)) {
      foreach (array_keys($router_items) as $path) {
        $router_items[$path]['module'] = $module;
      }
      $callbacks = array_merge($callbacks, $router_items);
    }
  }
  // Alter the menu as defined in modules, keys are like user/%user.
  drupal_alter('menu', $callbacks);

```

Since the code is using `array_merge()`, when two modules define a menu for the same path, only the last executed module would set the menu used by Drupal.

Modules should not rely on this, anyway. The correct way to alter a menu defined from another module is using the relative alter hook.

---
Tags: routes
---


# Question
Title: Including custom functionality with multilingual capabilities from the start
Imagine you have a global Drupal site with several languages. One market wants to add custom functionality for just the English language. From a technical standpoint would it be better to develop the custom functionality with multilingual capabilities by default?

I understand this is a high-level question, but was wondering on the pros and cons. The custom functionality would fit well with other languages, so two specific questions are for instance:

* Is the consideration of multilingual often more expensive than developing the monolingual version?
* On the long-term is it better to have the multilingual version from the start instead of adding it in a later phase? (updating code after functionality was pushed live).

# Answer
Generally speaking, making a module ready for multilingual use is so incredibly easy when you're building it that it makes a LOT of sense to do it. Retrofitting would be a real pain in the ass!

I'm not exactly sure what module you're building, but it could be as simple as wrapping any user facing copy with t().
> 0 votes

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


title: How do I show the user full name?

text:
# Question
Title: How do I show the user full name?
I am building a Drupal 7 site, and using the Hybridauth module. On my site, users can register with Facebook and Twitter (through the Hybridauth module), or regularly through the registration form.

When I am using a view, and add the field "User: Name", if the user registered through Hybridauth, it will show the full name; if the user registered on the site, and entered the full name in two dedicated fields, the view will show only the first name.

How can I present always the full name in both the cases?

# Answer
> 1 votes
It seems the hybridauth module passes the username trough a hook before output an if the user is registered through hybridauth,
You should be able to get your desired outcome by also using the Real name module which Hybridauth seems to integrate with.

# Answer
> 1 votes
You have to use Real Name module and configure real name at admin/config/people/realname

after that you have to configure HybridAuth at admin/config/people/hybridauth

And now Use username as field in view .

---
Tags: views, users
---


# Question
Title: problems with entity translation insert hook
I'm using the **entity\_translation\_insert()** hook to set the value of a field when a node is translated. I can successfully edit the $entity from within the implementation, but how should I save the resulting node?

I can't call node\_save because it would start an endless loop. I tried field\_attach\_update but the result is the same (i.e. loop).

I've tried following this article, with no luck: http://anthonypower.com/notebook/assigning-node-field-values-hook-insert-and-update-right-way

# Answer
> 0 votes
A trick to bypass this could be to use a static variable to process nodes only once per request, e.g.

```
/**
 * Implements hook_entity_translation_insert().
 */
function yourmodule_entity_translation_insert($entity_type, $entity, $translation, $values = array()) {
  static $processed = array();
  if ($entity_type == 'node' && !isset($processed[$entity->nid])) {
    // Do something
    $processed[$entity->nid] = TRUE;
  }
}

```

---
Tags: 7, hooks, entities, i18n-l10n
---


# Question
Title: how add js files to create a responsive theme?
is possible to add these files http://alvarotrigo.com/blog/fullpage-jquery-plugin-for-fullscreen-scrolling-websites/ in a theme? I created from scratch and from Zen without success. some how i think the jquery and javascript files are not active.

thanks

# Answer
> 1 votes
Copy the plugin on your subtheme's folder like "plugins/fullpage/".

Edit subtheme.info file adding:

stylesheets\[all\]\[\] = plugins/fullpage/jquery.fullPage.css scripts\[\] = plugins/fullpage/jquery.fullPage.min.js

Check if you need to add the other js files like vendor/jquery.easings.min.js, jquery.slimscroll.min.js...

It seems that the plugin needs jQuery 1.9.1 so https://drupal.org/project/jquery\_update may be helpful

More info about the plugin: https://github.com/alvarotrigo/fullPage.js

---
Tags: javascript, theming
---


# Question
Title: What is the simplest way to transfer webform /data/ from one instance to another?
I have much webform data that I want to move from a data entry instance to a testing instance, but I don't want the entire database. What is a simple recipe for exporting and importing drupal webform data.

I know about the webform export / webform import modules, and the import module that this is possible, but I can't find the correct combination of parameters that makes it happen.

Thanks

# Answer
Sometimes it is possible to export/import only selected tables on testing environments (not recommended on production sites).

A simple way is to use backup&migrate module (https://drupal.org/project/backup\_migrate) and then export and import the webform tables you like. You can select this tables on the advanced options.
> 1 votes

---
Tags: webforms, importing-exporting
---


# Question
Title: Disable language prefix for non-default languages
I'm migrating a plain multilanguage HTML site to Drupal 7. One of the requirements of the migration is to preserve the current URLs of each page. Right now, the site has three languages and has URLs like these:
www.example.com/files/content1/es.html
www.example.com/files/content1/en.html

I've Internationalization and Pathauto modules enabled, and set the pattern for the node alias like this:
files/\[node:title\]/\[node:language\].html

However, the i18n module adds a prefix to the URL, like this:
www.example.com/es/files/content1/es.html
www.example.com/en/files/content1/en.html

In Language options, in Detection, I've enabled URL.
I've been able to remove the prefix for the default language, but I'm unable to remove it for the other languages. So, in the end, I have URLs like these:
www.example.com/files/content1/es.html
www.example.com/en/files/content1/en.html

How can I remove the prefix for the other languages too?

Thank you in advance!

# Answer
Path redirection from old paths to new may be a solution (workarround really). This is compatible with SEO https://drupal.org/project/redirect
> 0 votes

---
Tags: i18n-l10n, path-aliases
---


# Question
Title: Profile 2 - My account displayed together
i included profile2 into my account page via any settings, and now have realy problem to find where i set it, could someone please help me? It was just one check box, please help me. thx

# Answer
> 2 votes
Do you mean you want to have separate tabs to edit your account information and profile information? If so, edit the profile type and check the "Provide a separate page for editing profiles." option.

---
Tags: users
---


# Question
Title: Change the value in the user join date field
I am building a Drupal 7 site.

User can register in my site using Hybridauth or regular registration form.

I want to change the value in the joined date field. Meaning change the date a user joined the site.

How can I do that?

# Answer
Old users: update the users table in your database. It will be far more efficient.

New users: https://api.drupal.org/api/drupal/modules!user!user.api.php/function/hook\_user\_presave/7 I don't think the date/time are saved in that form, so what you could do is find the UID and update the table using a sql query after the save is done.
> 0 votes

# Answer
You have to implement hook\_user\_presave like

```
function hook_user_presave(&$edit, $account, $category) {
    // your condition goes here
    //$edit['created'] =  REQUEST_TIME - mt_rand(0, 100000);
    $edit['created'] = 1364094210; //timestamp that you want to assign
}

```

If you want to update some specific user joining date Use

```
// load user object
$existingUser = user_load('USERID');
// update some user property
$existingUser->created = 'TIMESTAMP';
// save existing user
user_save((object) array('uid' => $existingUser->uid), (array) $existingUser);

```
> 0 votes

---
Tags: users
---


title: Services user/login and system/connect

text:
# Question
Title: Services user/login and system/connect
I would like to know the difference between user/login and system/connect.

# Answer
system/connect

> Returns the details of currently logged in user.

user/login

> Login a user for a new session

To login a user you will use user/login service call... Once user is logged in if you would like to pull logged in user details you will use system/connect service.. You can see above details in services module help section
> 2 votes

---
Tags: services
---


# Question
Title: How to get a "node" value from URL using arg(0)?
I have this problem in getting a value from URL.

First I've created an url alias for a certain articles.

In example, from this `/node/899` the alias I've created it's `/news/investments/899`

Then when I use `arg(0)` which is to get the value of first parameter which is "news" I get a result "node". The url alias works.

# Answer
You can get aliased path using drupal\_get\_path\_alias API Function..

```
$alias_path = drupal_get_path_alias();
$alias_arguments =  explode('/', $alias_path);
print $alias_arguments[0];

```
> 4 votes

# Answer
As you are using url alias ,you wont be able to get it using arg(0),Because your actual url is http://sitename.com/node/899

You can access the 'news' using request\_uri function like as follow

```
$url_parts = explode('/',request_uri());

```

You can get 'news' in `$url_parts[1]`

Hope this will work for you
> 0 votes

# Answer
with this code you'll get the alias of the node/1. Then you can take the part you need with explode function.

```
drupal_get_path_alias('node/1');

```

if you want to get the alias of the current path, just write

```
drupal_get_path_alias();

```

for more info: https://api.drupal.org/api/drupal/includes!path.inc/function/drupal\_get\_path\_alias/7
> 0 votes

---
Tags: 7, nodes, uri
---


# Question
Title: Vimeo Video Browser While Creating New Page In Drupal
I'm new to Drupal, learning it from past few days.

I want to create a vimeo video browser field widget while creating a page content type. Is there any module available which could help me achieve this?

I have installed various modules like vimeo media module, media embed field which enables me to add the vimeo video URL while creating the new page, I want to make an addition to this functionality like a vimeo video browser window to be opened and I could select the video from the same. Any idea as in how I could accomplish the same?

# Answer
> 0 votes
I can advice you this module https://drupal.org/project/media https://drupal.org/project/media\_vimeo

I wish it helps you.

---
Tags: 7, media, files
---


title: Login/register web service

text:
# Question
Title: Login/register web service
I am creating a web service for login and register, but I want a single URL for register and login so that, when a user registers, it will automatically log in. No need for two services for register and login.

How can I get this?

# Answer
When user gets saved in DB using user\_save() it returns the user object. All you have to pass it to $GLOBAL\['user'\]; and save session

```
   //Here is your previous code I assume where you have user_save()

   $user = user_save($userData);

   if($user) {
        drupal_save_session(FALSE);
        $GLOBALS['user'] = $user;
        drupal_save_session(TRUE);
   }

```

Hope this may help you
> 1 votes

---
Tags: services
---


title: How to programmatically send an email?

text:
# Question
Title: How to programmatically send an email?
I'd like to use Drupal's email system to programmatically send an email from my custom module. Is that possible?

# Answer
> 67 votes
Using hook\_mail and drupal\_mail you can create and send an e-mail.

Implement an e-mail use hook\_mail:

```
function MODULENAME_mail ($key, &$message, $params) {
  switch ($key) {
    case 'mymail':
      // Set headers etc
      $message['to'] = 'foo@bar.com';
      $message['subject'] = t('Hello');
      $message['body'][] = t('Hello @username,', array('@username' => $params['username']));
      $message['body'][] = t('The main part of the message.');
      break;
  }
}

```

To send a mail use drupal\_mail:

```
drupal_mail($module, $key, $to, $language, $params = array('username' => 'John Potato'), $from = NULL, $send = TRUE)

```

Obviously replace the parameters: $key should equal 'mymail'

An e-mail is sent in a few steps:

1. drupal\_mail is called
2. Drupal builds the e-mail
3. hook\_mail is called for the specifics (implementation)
4. hook\_mail\_alter is called so other modules can modify it
5. drupal\_send\_mail is called

# Answer
> 14 votes
If you'd like a simpler way of sending emails, check out Simple Mail; it's a module I'm working on to make sending emails with Drupal 7+ much easier, and it doesn't require any extra hook implementations or MailSystem knowledge. Sending an email is as simple as:

```
simple_mail_send($from, $to, $subject, $message);

```

# Answer
> 2 votes
You can use a simpler way of sending emails, check out mailsystem ; it's a module.

```
<?php
$my_module = 'foo';
$from = variable_get('system_mail', 'organization@example.com');
$message = array(
  'id' => $my_module,
  'from' => $from,
  'to' => 'test@example.com',
  'subject' => 'test',
  'body' => 'test',
  'headers' => array(
    'From' => $from,
    'Sender' => $from,
    'Return-Path' => $from,
  ),
);

$system = drupal_mail_system($my_module, $my_mail_token);
if ($system->mail($message)) {
  // Success.
}
else {
  // Failure.
}
?>

```

# Answer
> 1 votes
You can use this code in a hook of your own choice within your custom module:

```
 function yourmodulename_mail($from = 'default_from', $to, $subject, $message) {
            $my_module = 'yourmodulename';
            $my_mail_token = microtime();
            if ($from == 'default_from') {
                // Change this to your own default 'from' email address.
                $from = variable_get('system_mail', 'admin@yoursite.com');
            }
            $message = array(
                'id' => $my_module . '_' . $my_mail_token,
                'to' => $to,
                'subject' => $subject,
                'body' => array($message),
                'headers' => array(
                    'From' => $from,
                    'Sender' => $from,
                    'Return-Path' => $from,
                ),
            );
            $system = drupal_mail_system($my_module, $my_mail_token);
            $message = $system->format($message);
            if ($system->mail($message)) {
                return TRUE;
            } else {
                return FALSE;
            }
        }

```

Then you can use the above function like this:

```
        $user = user_load($userid); // load a user using its uid
        $usermail = (string) $user->mail; // load user email to send a mail to it OR you can specify an email here to which the email will be sent
        customdraw_mail('default_from', $usermail, 'You Have Won a Draw -- this is the subject',  'Congrats! You have won a draw --this is the body');

```

---
Tags: 7, emails
---


title: news site for a complete beginner

text:
# Question
Title: news site for a complete beginner
I'm a programmer with medium skills in Java-C# with few knowledge about web development. Now I want to create a news site for our corporation.

I searched a bit and found that Drupal is a good tool to create a news site but I don't know if I can do this or not. Currently I know nothing about PHP and Drupal.

So my questions are

* Is it possible to create, manage and maintain a small news site using Drupal without (or with few) PHP skills?
* If Drupal is not a good choice, what other options I have?

# Answer
> 1 votes
Yes, Drupal is a good choice to get started.. You can create and maintain site without PHP knowledge using Drupal since your requirements is very simple and can be achieved using out of the box Drupal.

You can try using OpenPublish Distro..

> OpenPublish is a packaged distribution designed for the online news industry. It is ideal for the implementation of a variety of media outlets sites including magazines, newspapers, journals, trade publications, broadcast, wire service, multimedia sites and membership publications. OpenPublish is built for flexibility, customization, and extension -- a powerful CMS to help publishers focus on their content.

---
Tags: emails
---


title: Adding sub menu to Management menu

text:
# Question
Title: Adding sub menu to Management menu
I'm trying to add a sub-menu under administration, for example:

Management:

* ......
* Content
* Structure
* ......
* My test (sub menu under administration)
+ My view 1 (a view that I created)
+ My view 2 (another view that I created)

Under structure-\> menu, I see that I can create a new menu and add link to existing menues, but I cannot understand how can I add a sub menu to Management.
**Note:** I'm using Drupal 7.

**Edit:** I added a link (My test) under management (Like in @Clive's answer) with path `admin/test` under `My Test` I created another link with path admin/test/form-view-test-3 and also gave that path to the view.

When I click on `My menu` I what to see a list of subcategories, in my case `Some view`. Instead Test 3 (The View) appears as overlay tab and I see the list of admin menus.

# Answer
> 1 votes
1. Go to admin/structure/menu/manage/management; you'll see all the links currently in the menu.
2. Click "Add link"
3. Fill in the title, path and any other relevant data.
4. Click "Save"
5. Re-order the menu items if necessary
6. Repeat the process for as many links as you need to place under the new top-level item you just created.
7. If you're using the Admin Menu module, you might need to flush caches before changes take effect (but you might not).

---
Tags: 7, views, routes
---


# Question
Title: Menu settings missing from all node edit forms
Apart from what I mention in the title, there are also a couple of other things that give me the impression that they may be related to the same issue:

* **Can’t add link to any menu from admin/structure/menu/manage/my-menu/add**. What does happen when I try to add a link to any menu is that it ends up in the Navigation menu that comes OOTB.
* **Can’t assign any menu to taxonomy menu**. Having `taxonomy_menu` enabled, I noticed that when configuring the vocabulary via admin/structure/taxonomy/gamma/edit there is no possiblity to assign any menu as taxonomy menu. The only option in the drop-down list is `=NONE=`

There is also A list of modules on which I did this series of events: disabled the module, cleared cache, checked if the problem persisted (which it obviously did), and enabled the module again:

Here is the list:

Big Menu
Jump Menu
Mysite configurator (custom)
Mysite (custom)
Store locator (custom)
roleperm\_import (custom)
mforms
mforms example
Menu Block
Menu import
Menu translation
Taxonomy menu _ custom paths
Taxonomy menu
Administration views
Backup and Migrate
Taxonomy translation
Menu translation

Needless to say the core *Menu* module is enabled.

Went looking on the internet, found this issue (https://drupal.org/node/358844) on drupal.org but this was drupal6 plus the big problem there was that the everything menu related seemed to be missing. The solution there was that menu permission weren’t right, which I have verified on my site that they are ok.

# Answer
> 1 votes
> "Menu settings missing from all node edit forms"

You need to enable the menus for use on each content type. This can be achieved on pages via Structure-\>Content type-\>Basic page, then click on the "Menu settings" vertical tab and toggle which menus should be enabled.

Also, if you're using the revisioning system in core, or any kind of workflow type module (workflow or workbench), unpublished pages in the menu won't show up in your list of menu items in Structure-\>Menus-\>Main Menu (for example), as well as the obvious rendered menu on the front end too.

---
Tags: 7, routes
---


# Question
Title: "Class not found" error when attempting to access inbuilt DateTime class
I am attempting to convert a working Drupal 6 module to Drupal 8 in preparation for the up coming release, and as an exercise in learning the new system.

In my existing module, I do some calculations on whether or not it is currently the weekend or a weekday and output some HTML in a block based on that.

In my code I have a `is_weekend()` function which returns `TRUE` if it is currently the weekend, and `FALSE` if it is a weekday.

My code for that function starts like this.

```
function is_weekend() {
  $ESTTZ = new DateTimeZone('America/New_York');
  $dt = new DateTime();
  $dt->setTimezone($ESTTZ);
  $day = $dt->format("w");
  $hour = $dt->format("H");
  $minute = $dt->format("i");
  $weekend = FALSE;

  if ($day == 6) {
    // ...
  }

  return $weekend;
}

```

It works fine; however, when I try to put this function into my new block class I get the following error:

> Fatal error: Class 'Drupal\livequotes\Plugin\Block\DateTimeZone' not found in C:\Work\ex-global-8

How can I call this PHP class from within my own block class?

# Answer
> 7 votes
You're just running into namespace problems. `DateTimeZone` is in the root namespace, so refer to it as:

```
\DateTimeZone

```

Same for

```
\DateTime

```

---
Tags: blocks, 8
---


# Question
Title: How can I check a Rules condition to see if the Statuses sender and recipient are the same?
I am using "Execute custom PHP" as a condition in a Rule which is being triggered when a new Status is saved. Here is the PHP I am using, it keeps causing "Trying to get property of non-object" errors whenever I create a new status:

```
if($sender->uid == $recipient-id){
return TRUE;
} else {
return FALSE;
}

```

Basically what I am trying to do is detect cases when the sender is sending a status message to himself so I can use an appropriate Rules action, and also the opposite:

```
if($sender->uid != $recipient-id){
return TRUE;
} else {
return FALSE;
}

```

I have tried a number of different variable combinations but I can't work out what I am doing wrong. Any suggestions?

# Answer
> 0 votes
This should do what you want.

```
if($status->sender == $status->recipient) {
  drupal_set_message('A match');
}
else{
  drupal_set_message('Not a match');
}

```

Rules Code

```
{ "rules_status_test" : {
    "LABEL" : "Status Test",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "php", "rules", "fbss_rules" ],
    "ON" : { "statuses_save" : [] },
    "IF" : [
      { "php_eval" : { "code" : "if($status-\u003Esender == $status-\u003Erecipient) {\r\n  drupal_set_message(\u0027A match\u0027);\r\n}\r\nelse{\r\n  drupal_set_message(\u0027Not a match\u0027);\r\n}" } }
    ],
    "DO" : []
  }
}

```

---
Tags: rules, status-messages
---


# Question
Title: Best way to get best breadcrumbs for Commerce
When a user is checking the product page, the breadcrumb trail should give Home \> Shop \> Category \> Product aka Home \> Shop \> Hats \> A Hat

I used Crumbs, but it only gives me Home \> Hats \> A Hat and I cannot figure out how to include \> Shop \>.

Well obviously at the same time the breadcrumbs should also work fine in the rest of the pages like for contacts page it would be Home \> Contacts

What would you recommend? What module? Or is it still possible with Crumbs and I am missing something?

# Answer
> 3 votes
You can add breadcrumbs in your page using drupal\_get\_breadcrumb and drupal\_set\_breadcrumb function

In template.php

```
 function THEMENAME_preprocess_page(&$variables, $hook) {

        if(arg(0)=='shoppage'){  //Put appropriate condition
            $breadcrumb = drupal_get_breadcrumb();
            $breadcrumb[1] = l('Shop', 'shop_link');
            $breadcrumb[2] = l('Category', 'category_link');
            drupal_set_breadcrumb($breadcrumb);
        }
    }

```

---
Tags: 7, commerce, breadcrumbs
---


title: URL transliteration in Views rewrite?

text:
# Question
Title: URL transliteration in Views rewrite?
I have a View of taxonomy terms and for some reason I need to overwrite the terms' fields and link them "manually", using "Output this field as link". How can I process the '\[name\]' token through transliteration process before outputting it on the screen?

# Answer
> 1 votes
Here's a workaround that worked for me.

Prerequisites: Pathauto and Transliteration modules.

1. Add a new text field to your taxonomy called "cleaned\_name", or whatever you like. In a later step we will populate this field at view execution with the term name after passing it through pathauto\_cleanstring.
2. Add the "Taxonomy term: Name", and "Taxonomy term: cleaned\_name" to your view. The "cleaned\_name" field must be below the "Name" field.
3. In the view settings for the "Name" field, mark the "exclude from display" checkbox.
4. In the view settings for the "cleaned\_name" field, click on "Rewrite results" to open the rewrite settings, then mark the "Rewrite the output of this field" checkbox.
5. This will cause a textbox to appear, where you can build your link html. For example:

```
<a href='PUT-YOUR-PATH-HERE/[field_cleaned_name]'>[name]</a>

```
6. Next implement hook\_views\_pre\_render. The idea is to take the the name, run it through pathauto\_cleanstring, and store it in the cleaned\_name field. I used the following code:

```
function YOUR_MODULE_NAME_views_pre_render(&$view) {
    if ($view->name == "MACHINE_NAME_OF_YOUR_VIEW") {
       //dpm($view->result); INSTALL DEVEL MODULE AND UNCOMMENT THIS IF YOU NEED TO SEE WHAT FIELD NAMES TO USE
   module_load_include('inc','pathauto');
   foreach($view->result as $key => &$result) {
      $cleaned_name = pathauto_cleanstring($result->taxonomy_term_data_name);
  $result->field_field_cleaned_name[0]['rendered']['#markup'] =  $cleaned_name;
   } // End of FOREACH statement
   unset($result);
     }
}

```

Adding a field to your taxonomy just to have a place to return a transliterated version of your field is a little ugly. Another alternative I tried was to add the name field to the view twice, with the idea of running only one of them through pathauto\_cleanstring, and thus having both a clean and uncleaned version available as tokens to build the link. This did not work however, because although you can add the term name field twice to a view, and views will create two tokens (\[name\], \[name\_1\]), in the backend both tokens point to the same field. If we modify this field, both tokens will output the modified value.

Another alternative I tried was to build the link html inside the hook\_views\_pre\_render function, and use that to overwrite the value in $result-\>taxonomy\_term\_data\_name. That avoids the need to add a field to the taxonomy. However, the problem here is that views will escape the html when it displays it. I wasn't able to find a way around this.

---
Tags: views, transliteration
---


# Question
Title: How to display all values of List (text) instead of just the selected ones?
When viewing a node, how can I display all values of a List (text) instead of just the selected ones.

So, instead of displaying:

```
B (good)

```

I want to display all values, with some markup telling selected and unselected apart:

```
[_] A (superior)
[_] A-
[_] B+
[X] B (good)
[_] B-
[_] C+
[_] C (average)
[_] C-
[_] D+
[_] D (poor)
[_] F (failure)
[_] I (incomplete)
[_] PR (course in progress)
[_] W (withdrew from course)
[_] FF (failing in a pass/fail course)
[_] PP (passing in a pass/fail course)
[_] N/C (not for credit)

```

Now, I have actually solved this already for myself and for some others (who had desperately been searching for this functionality) in my sandbox module https://drupal.org/sandbox/kari.kaariainen/1349570, but I just wanted to ask if anyone else has a) needed this, b) solved it and how?

Edit: my solution is to rebuild the $items at hook\_field\_formatter\_prepare\_view so that it doesn't have just the selected items, but all items, including data about whether an item has been selected or not. $items will then be handled by hook\_field\_formatter\_view actually outputting items with added markup and translated.

It's kind of frustrating to bring back data at prepare\_view, so I'm wondering if data for all items could be retrieved from database initially.

Another thing is i18n support, which I'm now copying from i18n module. Code for each field type (there will be more than just text lists) will need to be duplicated and modified separately. I'm wondering if field translation could be left for i18n and not duplicating code.

# Answer
> 2 votes
Even if no one here says they have needed to do that you can pretty much bet others out there have, so it's good that you have your code on drupal.org where other can use it if they need it.

I had a quick look over your code and your solution is the way I would do it: create a new field formatter for text list fields using hook\_field\_formatter\_info() and hook\_field\_formatter\_view().

A couple of things I notice though are:

1. The name of the module is very long. If you can make it shorter while still being somewhat descriptive I think that would be good (also better for you as the coder).
2. The markup you are outputting is not themeable, so if other people start to use the module and want to override the markup in any way it is harder for them. See image\_field\_formatter\_view() as an example of creating a render array with a specific theme function. Also see hook\_theme() for defining your own theme functions.
3. Text that gets displayed to the user that is hard coded into the module should be run through the t() function so that others can write translations for your module. See the drupal 6 version of that t() api docs page for better and more thorough information. t() is not currently used is for `$form['instructions']`.
4. This one is a bit more of a personal choice but I would probably make the markup options a lot less than 500 characters. I would also quite possibly not allow HTML markup and just allow them to enter characters that would then display in a span. If the user wants something fancy they can override the theme function (as per point 2). Also, the instructions encourage users to use inline styles, which are not recommended. Users should use the classes you provide to add any css in their theme's css files.

---
Tags: entities
---


# Question
Title: How to get a list of all Groups sorted according to latest comment created on any of the Group Content belonging to that Group?
I wrote the following custom query to get a List of Groups sorted according to latest comment created on any of the Group Content belonging to that Group (**not on the group itself**) .

However this query does not return the list of Groups for which there is no Group Content OR any comment on any of Group Content is created.

```
SELECT DISTINCT   group_view.nid AS group_nid,
                  group_view.created_date AS group_created_date,
                  discussion.nid AS discussion_nid,
                  comment.created AS comment_created_date,
                  comment.created_date AS comment_created_date
  FROM `node` AS group_view
      LEFT JOIN `og_membership` AS group_map
          ON group_view.nid = group_map.gid
      LEFT JOIN `node` AS discussion
          ON group_map.etid = discussion.nid
             AND group_map.entity_type = 'node'
      LEFT JOIN `comment` AS comment
          ON discussion.nid = comment.nid
  WHERE group_view.type = 'group'
  ORDER BY comment.created DESC

```

What changes do I need to make in this query to include a list of Groups with no comments

I do not want to use **views**.

# Answer
> 0 votes
I have not tested a query as I don't have data to test.But I hope the following query will work for you.I am matching comment created date with fetched latest comment by using sub query.

```
SELECT DISTINCT   group_view.nid AS group_nid,
                      group_view.created_date AS group_created_date,
                      discussion.nid AS discussion_nid,
                      comment.created AS comment_created_date,
                      comment.created_date AS comment_created_date
      FROM `node` AS group_view
          LEFT JOIN `og_membership` AS group_map
              ON group_view.nid = group_map.gid
          LEFT JOIN `node` AS discussion
              ON group_map.etid = discussion.nid
                 AND group_map.entity_type = 'node'
          LEFT JOIN `comment` AS comment
              ON discussion.nid = comment.nid
      WHERE group_view.type = 'group' and (comment.created=SELECT max(c.created) AS latest
      FROM comment c
      WHERE  (c.nid = node.nid)
      GROUP BY c.cid)

```

---
Tags: 7, organic-groups, database
---


# Question
Title: What is the difference between an 'Attachment display' and a 'Global: View area' put into header/footer of a view?
I'm trying to decide which should I use. Both can inherit contextual filters, so in my case both of them are good solutions. Except that I already have the other view that I want to put together with the first, so with Attachment I would have to redo the whole other view as a new display of the first, but with View area I could just reuse the other view.

What is the concept behind them? Are there other differences than what I noted above?

# Answer
> 8 votes
Background: View is a view, a view can have many displays, such as page, feed, attachment, block.

With Attachment display, you can attached one display of a view to another display. A good video demo can be found by Doug Vann (its a drupal 6 demo, that can relate to drupal 7).

With Global: View area (Drupal 7 only) you can add a view inside a view header or footer.

This is no huge pro/con of doing it one way over another. The only thing I can think of is templating a view and styling it. There will be different html tags and classes for you to style.

# Answer
> 1 votes
As iStryker says, attachments allow you to attach one display of a view to another display **of the same view**.

Using Global: View area allows you to attach a display of another view altogether. This can be useful if the two views are not compatible.

For example, if you want a view of taxonomy terms attached to a view of nodes.

# Answer
> 0 votes
I don't know if I'm confused but;

I can use pagination of the host view without any problems if I attach another view in it (header or footer) but the pagination isn't available if I embed another view's block or page into header (or footer) so it's a big difference to me...

---
Tags: 7, views
---


title: Configuring the Popup Calendar Widget

text:
# Question
Title: Configuring the Popup Calendar Widget
Currently I have a date contextual filter. When I click the date field the popup calendar displays. when I click on a date (for example today's date) it displays as `3/18/2014`, but I would like it to display as `March 18th, 2014`. Would anyone know how I should go about this?

Any help would be much appreciated. Thanks!

# Answer
> 0 votes
Technically, it seems that the issue would be fixed by reformatting the `Short` date type located in `admin/config/regional/date-time`. Although, I tried this and it was not working.

Then I remembered that I had altered some javascript to add a calendar image button on my form. That javascript was overriding some of the default configurations of the code and after fixing that it worked like charm.

# Answer
> 0 votes
Go to your content type and edit the field. You'll find "More settings and values" as a collapsed fieldset (which is how I always missed it at first.)

The first option will be to change the "Date entry options" and how this is displayed.

You can also modify the default start and end dates here, as well.

---
Tags: 7, views, datetime
---


# Question
Title: Custom Block - How to get additional variables
I am new to Drupal and slowly getting my head around it. I'm using Pay to Publish module on my site, I've setup a custom block that gets recent posted advert (very simple) now I want to style the block to look a bit different which isn't too hard. I've managed to create a new .tpl.php for my specific block. However past here I cannot figure out how to gain access to the variables for each post. This is what I have currently and what I want: http://gyazo.com/e91c01cd9b64d4a31a01c9e5039c7362

So i'll need to gain access to the price and picture url from each post. If anyone can point me in the right direction that would be great, being new to Drupal I'm not entirely sure I've been using the right keywords in my searches on Google.

Much appreciated, Ross.

# Answer
You can create custom block and you can render variables using block view function

```
function MODULENAME_block_info() {
    $blocks = array();
    $blocks['top_five_adverts'] = array(
        'info' => t('Top Five Adverts'),
    );
}

function MODULENAME_block_view($delta = '') {
    $block = array();

    switch ($delta) {
        case 'top_five_adverts':
            $block['subject'] = '';
            $block['content'] = theme('top_five_adverts_list', array('data' => getAdverts()));
            break;
    }
    return $block;
}

function MODULENAME_theme() {
    return array(
            'top_five_adverts_list' => array(
            'variables' => array('data' => null),
            'template' => 'theme/top_five_adverts_list',
        ),
    );
}

```

Create top\_five\_adverts\_list.tpl.php in theme folder of that module
> 1 votes

---
Tags: theming, blocks
---


# Question
Title: Views: Insert Profile2 information in a node
I have a problem and here's my graphical illustration of it:

I have tried many things that didn't work. I think the answer has something to do with adding a relationship with a node field, but I don't know how to get it to work here.

# Answer
1. You need to have an entity reference field on the node type that allows you to reference a user as the creator of the necklace.
2. Then you want a node view that has a contextual filter of nid, that uses node id from the url as a default value when no contextual filter value is provided.
3. Then you can add a relationship to the user via the entity reference field you added.
4. Then add a relationship for the profile2 profile, so you can use the profile fields in your view.
5. Add a block view display.
6. Add the block to your node pages.
> 1 votes

---
Tags: views, display-suite
---


# Question
Title: Deleting users who have created content can lead to access bypass?
The statement below appears in several places on the Internet about Drupal security. Is it the case that someone once wrote this and people repeat it in the their '10 Drupal security tips' posts without checking - or is there some truth to it?

> Disable user accounts and keep their contents. Deleting users who have created content can lead to access bypass.

Thanks.

# Answer
> 1 votes
Indeed the page at https://drupal.org/node/1732920 has an example scenario of how this can happen. I don't remember verifying that myself, but believe it came out of some research on an issue reported to the security team. I think Greg\_1\_anderson's comment about "edit own page content" is probably an important element to that scenario.

I've also seen this happen with node access modules. In discussing it with people, the theory that seems most likely:

1. User 42 exists and has been granted access to view and/or edit some nodes on a site using a node access module.
2. User 42 gets deleted, this invokes hooks including in the node access module which may take some action like updating the records it previously stored about user 42 to now point to uid 0 instead of 42
3. OR...perhaps it forgets update those records and instead they just exist with user 42 on them
4. When node access records are rebuilt, the code of this node access module either sets faulty records with uid 0 (based on step 2) or it fails to properly load a user and php/mysql will behave in their usual loosely typed ways and take the need for a record with a missing uid value and just insert a zero for the uid.

It's definitely a bug that has occurred more than once. If it can be prevented in code then it should be submitted to that module's issue queue to fix it.

# Answer
> 0 votes
I've seen this happen with no node access modules enabled.

The cause was as mentioned by the Gregs, a user is deleted and all their content was then assigned to anonymous.

Anonymous had incorrectly been given access to edit their own content and so they then had access to edit those nodes.

Note that the sites I have seen this on were drupal 6 sites. This is less of an issue in drupal 7 because you have more control over users being able to cancel/delete users and what happens to their content.

Although having said that, the issue I've seen are largely due to misconfiguration, which can still happen in drupal 7 to get you in that same bad place.

---
Tags: security
---


# Question
Title: How do I define this simple views relationship?
* I have a `person` table that has a primary key `id`. This is a base table.
* I have an `address` table that has a foreign key `person_id`. This is NOT a base table (has no primary key)
* The address table contains a `person`'s address, but not every `person` has an `address`.

When describing these two tables to views, how do I set it up so that when the `person` table is used as a base table, I can optionally add a relationship to `address` to join in the information?

I know I can add an **implicit join** on the `address` definition like so:

```
$data['address']['table']['join'] = array(
  'person' => array(
    'field' => 'person_id',
    'left_field' => 'id',
  ),
);

```

This allows me to add any `address` fields automatically in the Views UI. Views would by default use a `LEFT JOIN` to bring in the `address` data. I can change this to an `INNER JOIN` in the above definition, but **I want to allow the user to chose**, which is exactly what using a relationship handler does (has the "require this relationship checkbox", which controls `INNER` vs `LEFT`).

However, in my analysis of how these handlers work, I don't think I can define the handler in a way that this will work. It seems the relationship handler should be added to *the foreign key on the base table*. My base table is `person`, which does not have the foreign key.

For instance, I tried this:

```
$data['address']['person_id']['relationship'] = array(
  'base' => 'person',
  'base field' => 'id',
  'handler' => 'views_handler_relationship',
  'label' => t('Address'),
  'help' => t("Has basic information on a person's address.")
);

```

But this doesn't work, since `address` is not used as a base table in my View.

How can I do this?

**P.S.** part of my confusion/trouble stem from my inability to define a table neither as a base table nor an implicit join table, which is what I want to do for `address`.

**UPDATE 1**: For a real-world example, look at the table `accesslog` and how it relates to `users`. When working with a view w/ `users` base table, you cannot explicitly add the `accesslog` relationship, but you can add all the `accesslog` fields since `statistics.views.inc` creates the implicit relationship. My schema is similar, but I want to use explicit relationships instead.

# Answer
The very first point is that, the table itself should be defined in order for Views to access it. It's not necessary to define all the fields in the table; just define what you want to access.

You can however, define additional fields that are not in the table. The ***default*** convention in the `$data` array is the `table name => column_name` but you still can add non-existing keys to the array without Views looking for that field in the query.

Try this:

```
<?php

$data['person']['addresses'] = array(
  'title' => 'Addresses',
  'help' => 'Load persons address information',
  'relationship' => array(
     'title' => t('Person\'s address'),
     'base' => 'address', // base table
     'base field' => 'person_id',
     'relationship field' => 'id',
     'handler' => 'views_handler_relationship',
     'label' => t('Address information'),
     'help' => t('Address information'),
  ),
);

```

You will now see a new relationship, Address, to join the table, along with a checkbox to make it an `INNER` instead of a default `LEFT` join.

Similarly, you can add additional fields, arguments and filters without having a real field with the array's key in the table.
> 1 votes

---
Tags: 7, views
---


title: Webform token in emails: need example

text:
# Question
Title: Webform token in emails: need example
I've got multiple web forms that email their submissions. I need to break it out into fields and keep it clean.

Say, on my webform, I've got a field named zip\_code. How can I print that in a token, with no label?

Thank you.

EDIT: I want to use the built-it (but not documented) functionality

# Answer
> 3 votes
Under Webforms \> E-mails \> E-mail template choose Custom Template.

Remove the \[submission:values\] token. That's what lists all the fields and their values with labels. Customize the other text as you wish.

Note the "Browse available tokens." link below the text box. This pops up a window that shows you what placeholders you can put in to build your email. You can even click on the browse tokens popup to add them to the text field. Some of them can be used as-is. Some need additional info, like the field tokens.

Field values are under the Submission header.

For your zip\_code field example, you can use:

For just field: \[submission:values:zip\_code\]

For just label: \[submission:values:zip\_code:label\]

For label and field: \[submission:values:zip\_code:withlabel\]

You'll see there's lots of other stuff you can use, too.

Hope this answers your questions.

# Answer
> 0 votes
I was asked to find out how to remove the empty fields from Webforms emails. I ended up creating the template (webform-mail.tpl.php) in the theme and using some PHP. Maybe this will help get you started. I'll share it here. You can also look at the original file in the module for some more info on the variables available to you. If you dump the values of those variables you'll learn a lot. That's how I got started.

Now I was asked to print the labels (in caps!) but you can take those lines out.

This code also respects the excluded field settings in the UI, so that going forward, the users can control what fields they see or don't see. I'm new to PHP and Drupal so this may not be the best way to do it, but it worked for me.

```
<?php
function email_print($text) {
  global $email;
  print ($email['html'] ? '<p>' : '') . t($text) . ($email['html'] ? "</p>\n" : "\n");
}
?>

<?php email_print('On [current-date:short] a request was submitted by [submission:user] from form [node:title]') ?>
<?php email_print('-----------------------------------------------------'); ?>

<?php

// Make sure we have a submission; avoids error in the admin UI where this file is parsed for display
if ($submission) {
  // Get excluded fields
  $excluded = array_values($email['excluded_components']);

  foreach($submission->data as $key => $field) {
    // Reset include boolean
    $include = true;

    // Get value
    $value = trim($field[0]);
    // If it's blank, don't include it
    if (strlen($value) == 0) {
      $include = false;
    }

    // If it's listed as excluded, don't include it.
    if (in_array ($key, $excluded)) {
      $include = false;
    }

    // If it should be included...
    if ($include) {
      // ...get and upcase the label...
      $label = strtoupper(trim($node->webform['components'][$key]['name']));
      // ...and print out the field.
      email_print($label);
      email_print($value);
      print "\n"; // Blank line between
    }
  }
}
?>

```

---
Tags: 7, webforms, tokens
---


# Question
Title: How do I render contextual links for blocks I render in my code?
I loaded a block subject and content with `module_invoke()` and used `render()` for rendering them. I want to use contextual links for this block. How can I render them too?

This is the code I am using insde the page--front.tpl.php template.

```
$block = module_invoke('block', 'block_view', '4);
print render($block);

```

What code should I instead use?

# Answer
```
$block = block_load('module', 'delta');
print drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));

```

Too bad we have to use private functions from the block module (\_*()) to achieve this.
> 16 votes

# Answer
Bart's answer will give a Strict Standards warning (enabled by default in PHP 5.4). To fix this just use an intermediate variable for the renderable array:

```
$block = block_load('module', 'delta');
$renderable_array = _block_get_renderable_array(_block_render_blocks(array($block)));
print drupal_render($renderable_array);

```

The reason the warning occurs is because the `drupal_render` function expects its parameter to be a reference. It has the signature `drupal_render(&$elements)`. For more information see the answer to this similar question.
> 12 votes

# Answer
Contextual links are helpful and really easy to implement. For your use-case you need to implement `hook_block_view_alter()` to change #contextual\_links item to suit your needs. These references will help you out:

GL :)
> 2 votes

---
Tags: 7, blocks
---


title: Adding attributes to field_view_value

text:
# Question
Title: Adding attributes to field_view_value
I'm using the following function to render a image field in a template, this works great but I would also like to add a custom `alt` attribute to the image:

```
function <module>_render_field($node, $field_name, $delta = 0, $display = array()) {
   $field = field_get_items('node', $node, $field_name);
   $field = field_view_value('node', $node, $field_name, $field[$delta], $display);
   return render($field);
}

<module>_render_field($node, 'field_image', 0, array(
  'type' => 'image',
  'settings' => array(
     'image_style' => 'object_380x250',
     'image_link' => 'content',
   ),
));

```

I was trying to add the `alt` attribute to the image by changing the above code to:

```
<module>_render_field($node, 'field_image', 0, array(
  'type' => 'image',
  'settings' => array(
     'image_style' => 'object_380x250',
     'image_link' => 'content',
   ),
      'attributes' => array(
         'alt' => 'alternate'
      )
));

```

The above didn't worked but I managed to add the attribute by changing the module code to:

```
function <module>_render_field($node, $field_name, $delta = 0, $display = array()) {
   $field = field_get_items('node', $node, $field_name);
   $field = field_view_value('node', $node, $field_name, $field[$delta], $display);
   // add alt attribute
   $field['#item']['alt'] = 'alternate';
   return render($field);
}

```

I'm hoping there is a nicer way to achive this.

# Answer
This is an ideal case for using a preprocess in your template.php. You can use a field preprocess. Something like:

```
function THEME_preprocess_field(&$variables) {
  // do a dpm on $variables to see what you can use.
  $variables['items']['0']['#item']['alt'] = 'alternate';
}

```

You can also add a template file for your field. Check theme\_hook\_suggestion part in `template_preprocess_field` function for available theme\_hook\_suggestions. Check this to see how you could use them.

Edit: Here is a working code I tested:

```
// Here I use bartik as an exmample. You can change it to your theme name.
// First we add a preprocess to a certain field. The following is ONE way to allow
// you to create   preprocess functions for any field. There might be better ways.
function bartik_preprocess_field(&$variables) {
// this will tell our theme system to look for preprocess's of the form
// THEME_NAME_field__field_FIELD_NAME.
$function = 'bartik_preprocess_field__'. $variables['element']['#field_name'];
  if(function_exists($function)) {
    $vars = $function($variables);
  }

}
// Then we change what needs to be changed.
function bartik_preprocess_field__field_nice_pic(&$variables) {
  // krumo($variables);
  $variables['items']['0']['#item']['alt'] = '123';
  // krumo($variables);
}

```
> 2 votes

# Answer
If you look at it, you'll notice `MODULE_render_field` is not useful at all. Once you get the renderable array from `field_view_value` you can change the values in it and render it. If you're adding that to a template, it will look fugly, for sure. But it belongs in a preprocess call, where it will look just normal:

```
<?php

function MYTHEME_preprocess_SOME_TEMPLATE($vars) {
  $field_items = field_get_items('node', $vars['node'], $vars['field']['field_name']);
  $field_value = field_view_value('node', $vars['node'], $vars['field']['field_name'], $vars['field'][$delta], $display);
  // Alter the renderable array.
  $field_value['#item']['alt'] = 'alternate';
  $vars['altered_field'] = $field_value;
}

```

And in the template:

```
<div class="something">
 <?php print render($altered_field); ?>
</div>

```
> 2 votes

---
Tags: 7, entities
---


title: Show who has flagged you

text:
# Question
Title: Show who has flagged you
I have a content view of user images. They have a 'flag user' flag attached to them. I suppose it all works just the same if I had the user flag in the user page.

I wanted to create a block view (or page) that shows who has flagged a logged-in user when that user is viewing their own profile.

I have tried every relationship under the sun. I alwasy seem to end up of a list of users the logged-in user has flagged, not the other way around.

Could anyone help put me out my misery?

I am using the latest releases of the Views and Flags modules.

# Answer
> 1 votes
Have you tried with a contextual filter with Flags: content ID, and then take the default value of type 'User ID from logged in user'.

It worked for me.

---
Tags: views, flags
---


# Question
Title: Reordering values in a multi value field
Is there a module that allows you to reorder the values of a multi value field? By drag and drop or by weight.

Example:

```
Field XYZ:
+ Value 1
+ Value 2
+ Value 3
+ Value 4

```

Reorder to:

```
Field XYZ:
+ Value 4
+ Value 2
+ Value 3
+ Value 1

```

# Answer
If you need to do this in the context of adding/editing nodes, Drupal 7 core provides this functionality on node add/edit pages.
> 1 votes

# Answer
You can Try Multiple value widget module.

> Drupal utilizes draggable tables to handle multiple value forms. It's quite convenient for most simple field types. However, for complex field types such form can be cumbersome. For example, the widget for Image field type can contain a preview of a file, an upload button, a text field for title and alt attributes. Sometimes you have a lot of images to be uploaded and the form takes up a lot of space.

*This module integrates the jQuery UI tabs and accordion plugins as a replacement for draggable tables to make multiple value forms more user friendly. All field items can still be ordered through jQuery UI sortable widget.*
> 0 votes

---
Tags: 7
---


# Question
Title: List of people who flagged me since my last login
I've created a Like flag using flag module and a page view to list all people who like the currently logged in user. The views works good and am getting a list of users who like me (the currently logged in user). I want to filter the list of people who've liked me since my last login.

Been messing with the user:last login and user:last access filters. Can't find to make it work. Can anyone please help me with this?? (edit: I realize that the user:last login and user:last access filters is for filtering the list of users so no luck yet)

# Answer
> 2 votes
In the filter criteria add flaggeds time filter. An operator with is greater than or equal to and write a date whatever you want, doesnt matter wich one, because where are going to modify programmatically later.

Then in your module we have to rewrite that filter to put the last login from the user.

```
/**
 * Implements hook_views_pre_view.
 */
function YOUR_MODULE_views_pre_view(&$view) {
  if ($view->name == 'VIEW_NAME') {
    global $user; //Load user
    $view_filters = $view->display_handler->get_option('filters');
    // Put the user last login in the flag filter we created before
    $view_filters['timestamp']['value']['value'] = date('Y-m-d H:i:s', $user->login);
    $view->display_handler->override_option('filters', $view_filters);
  }
}

```

---
Tags: 7, views
---


# Question
Title: How do you change the email recipient of drupal 7 webform based on checkbox value using hook form alter?
How do you change the email recipient of drupal 7 webform based on checkbox value using hook form alter? I have a group of checkboxes (Texas, DC, Maryland, Virginia). I would like to change the recipient if Texas is checked and use the default for the other options. I do not want to change the key of the checkbox component to the Texas email address because I need to state which location was selected in the email template.

# Answer
> 4 votes
You do not need to use hook\_form\_alter for this, you can set this up in Webform on admin, here is how:

1. Go to the Edit interface of your webform
2. Go to E-mails
3. At the bottom, choose 'Component value' and choose your checkbox field, click Add http://cl.ly/image/1K3V2N3k3q30
4. At 'Component e-mail options' you can specify an email address for each option http://cl.ly/image/1g3c1r15060r

Description below says:

*"You may enter an e-mail address for each choice. When that choice is selected, an e-mail will be sent to the corresponding address. If a field is left blank, no e-mail will be sent for that option."*

# Answer
> -2 votes
This is one solution that works but I'm sure there is a more Drupal friendly way to do it.

I basically created a hidden input field called email recipient with the default value as the default email address. Then used jquery to change it's value depending on if the checkbox is checked or not.

```
    $('#checkbox').click(function() {
  $("input[name='submitted[email_recipient]']").val($(this).is(':checked') ? 'email1' : 'email2');
});

```

Then in Drupal admin under webform emails, set 'Email to' as the hidden input field. Also unchecked the field from the list of available fields in the email template so it doesn't get printed in the emails that get sent out.

---
Tags: webforms, forms
---


title: Rules for how Drush vset works

text:
# Question
Title: Rules for how Drush vset works
I want to perform some admin configurations through drush using vset the way I've used it in the past, such as the following:

```
drush vset site_name Example;

drush vset site_offline 1;

drush vset preprocess_css;

```

If I wanted to turn off email varification on the following page, is there a variable I can use drush vset to set the variable to 0 or 1?

admin/config/people/accounts

If so, how would I find the variable names for admin configurations to know which ones can be set by drush?

# Answer
On administration forms system\_settings\_form is normally used to return form, so the element id is same as the variable name without the "#edit-" with underscores.

For example on: /admin/config/system/site-information

```
id="edit-site-mail" -> drush vset site_mail peter@email.com

```

To turn off the email verification:

```
"edit-user-email-verification" -> drush vset user_email_verification 1

```

Drush returns all variables that match with your variable name, so if you only know part of the name you can try:

```
drush vget email

```

returns all matches:

```
user_mail_status_canceled_notify: 0
user_mail_status_canceled_subject: "Account details for [user:name] at [site:name] (canceled)"
reroute_email_address: "debug@email.net"
reroute_email_enable: "TRUE"

```

Module devel (https://drupal.org/project/devel) let you check all drupal variables on this menu callback: /devel/variable
> 3 votes

---
Tags: drush
---


# Question
Title: Make a views of data entered in composed fields
How to output the data entered in Composed Fields to Views?

I have used Composed fields of 3 subfields, it was OK while entering the data. But When I want to display the entered data in Views, I get only blank fields.

After digging dip into it, I tried rewrite the Result, Only in Write result I get **Token** like `[field_field_name-composed]`, which outputs the serialized PHP code:

`a:3:{i:1;s:14:"First Subfield";i:2;s:15:"Second Subfield";i:3;s:14:"Third Subfield";}`

where ***First Subfield, Second Subfield, Third Subfield*** are the data I entered into 3 subfields of Composed field, and is also defined by `s:` before it. If it is *String* type and 14 Characters long, then its written as `s:14:`

I also see the **Token** like `[field_field_name]` but it outputs blank (NULL).

So, I planned to use Views PHP to get the data from Composed Field and use some PHP code, but in Views PHP field, I am unable to use the Token `[field_field_name-composed]`.

I want to make a Views with 3 fields to display each Subfield in its own field, is it possible?

EDIT:

I came to know this is using PHP Serialize function, but when I tried PHP Unserialize in Views PHP, I get blank string.

EDIT2:

The result of Unserialized value of above serialized field is:

```
print_r(unserialize('a:3:{i:1;s:14:"First Subfield";i:2;s:15:"Second Subfield";i:3;s:14:"Third Subfield";}'));
Array
(
    [1] => First Subfield
    [2] => Second Subfield
    [3] => Third Subfield
)

```

# Answer
> 0 votes
There are several problems with Composed Field module. Some issues with text format handling prevented the values from ever showing up at views! See https://drupal.org/node/1929462 for a fix for that.

Now, once displaying the field in views is fixed, choosing the field components to display is not hard. First of all, you will have to override the field handler for composed fields. It's not harder than this:

```
 /**
    * Implements hook_field_views_data_views_data_alter().
    */
    function composed_field_field_views_data_views_data_alter(&$data, $field) {
      $field_name = $field['field_name'];
      $data['field_data_' . $field_name][$field_name]['field']['handler'] = 'composed_field_handler_field_composed_field';
    }

```

Then, in the overriden handler, inherit all you can from `views_handler_field_field`, which implements everything you need to display a field in views. But let's override three methods:

```
/**
 * Defines options for composed fields.
 */
function option_definition() {
  $options = parent::option_definition();
  $options['composed_field']['components'] = array('default' => array());
  return $options;
}

```

This just tells Views we will be setting up some options in the form. It is needed to actually save the values. Mind the `parent` call, it *is* needed.

```
/**
 * Defines checkboxes for composed field components in a fieldset.
 */
function options_form(&$form, &$form_state) {
  parent::options_form($form, $form_state);

  $field_name = $this->field_info['field_name'];

```

Composed Field lets you set the components for every field instance, meaning the same field might be used in wildly different ways. And since views uses the same handler for any field\_instance of the same field, we can't rely on component titles (the composed\_field doesn't enforce the titles anyway) nor how many components a field has. We have to figure it out in a more abstract way: just pick the biggest number of components for that field.

```
  $cardinalities = array();

  foreach ($this->field_info['bundles'] as $entity_type => $bundles) {
    foreach ($bundles as $bundle) {
      $instance = field_info_instance($entity_type, $field_name, $bundle);
      $cardinalities[] = $instance['widget']['settings']['number_of_subfields'];
    }
  }

  // Let's just get the maximum number of subfields.
  $cardinality = max($cardinalities);

```

Then, just create a form. No surprises here, except tha `#tree` is TRUE by default (and that's why we have to put option in a keyed array in the previous method).

```
  $form['composed_field'] = array(
    '#type' => 'fieldset',
    '#title' => t('Composed Field Components'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    'components' => array(
      '#title' => t('Select the field components to display'),
      '#description' => t('If no component is selected, all will be displayed.'),
      '#type' => 'checkboxes',
      '#options' => $this->composed_field_component_options($cardinality),
      '#default_value' => $this->options['composed_field']['components'],
    ),
  );
}

```

That will be enough to have a UI in views to choose the components (`composed_field_component_options()` is an implementation detail, but it has to be keyed by the component numeric id, which is not 0-indexed).

Now, to display only the selected components:

```
/**
 * Filter out disabled components.
 */
function set_items($values, $row_id) {
  $items = parent::set_items($values, $row_id);

  $components = array_filter($this->options['composed_field']['components']);
  // If no component was chosen, show all. This makes for a good default.
  if (!empty($components)) {
    foreach ($items as $delta => $item) {
      foreach ($item['rendered']['#item'] as $component => $value) {
        if (!in_array($component, $components)) {
          unset($items[$delta]['rendered']['#item'][$component]);
        }
      }
    }
  }

  return $items;
}

```

That last part is easy: retrieve data from the handler options and unset the components that were not selected to be displayed. Of course, display every component if no component was selected (a reasonable default).

# Answer
> 1 votes
Write a function in your module/theme that will accept two arguments,

1) the serialized value `a:3:i:1;s:3:"First Subfield";i:2;s:4:"Second Subfield";i:3;s:7:"Third Subfield";`

2) the name of the key you want to use.

Have it return the value.

Create three new columns that use PHP code in your view, and pass the appropriate arguments to your module/theme.

---
Tags: 7, views
---


# Question
Title: node_save is not same as saving a node manually
I've removed many terms from a vocabulary and now I see this error when I see a node referencing the deleted term(also the attachment):

```
EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7693 of D:\xampp\htdocs\gij\includes\common.inc).

```

I know it is an issue( like this) which goes away if I edit and save the node manually but does not work out if I run this code from Drush:

```
$node = node_load($nid);

 if ($node !== FALSE) {
  print "Saving the $full_path\n";
  node_save($node);
  }

```

Why this difference?

# Answer
> 3 votes
Try one of this options:

Explicit field deletion:

```
$node = node_load($nid, NULL, FALSE); // Force to load
if (!empty($node->nid)) {
  $node->field_taxonomy_term = NULL; // Reset the field
  node_save($node);
}

```

Submit the node form programmatically:

```
$node = node_load($nid, NULL, FALSE); // Force to load
if (!empty($node->nid)) {
  $form_state['node'] = $node;
  $form_state['values']['op'] = t('Save');
  drupal_form_submit($node->type . '_node_form', $form_state, $node);
}

```

Edit all nodes on bulk with views bulk operations:

1. Install https://drupal.org/project/views\_bulk\_operations
2. Add a new view page of content (node) and set fields as display.
3. Add field "Bulk operations: Content"
4. Configure the fields: SELECTED BULK OPERATIONS: "Save content" (check)
5. Save the view and go to the views path.
6. Select all items and the "Save" operation and execute it!
7. Done!

# Answer
> 2 votes
What you are doing there is loading a node then saving it with same values. When using the UI, I assume that the referenced taxonomy terms are not available to render hence your fields will have reset values which are valid. So upon saving, you end up with updated records on your node.

I would reset the values of these fields if the taxonomy terms do not exist after node\_load. Then save.

I hope it helps.

---
Tags: 7
---


# Question
Title: Views: Define table without describing it as a base OR join table?
The Views API in advanced help says "For Views to use your table, it has to either be a base table, or know how to link to an existing base table. Or sometimes both. "

I'm trying to add an "address" table to joins to the "person" table. The "person" table is a base table, "address" is not.

I can do this:

```
  $data['address'] = array(
    'table' => array(
      'group' => t('Address'),
      'join' => array(
        'person' => array(
          'left_field' => 'id',
          'field' => 'personID',
        ),
      ),
    ),
  );

```

However, this creates an implicit join relationship in views, meaning it will automatically make all fields in the "address" table available to the view and join the data with LEFT JOIN.

What I want to do is instead just add a relationship handler to the "personID" field so that the relationship is explicit, meaning a user must manually add the relationship.

I have successfully added this relationship handler to the "personID" field, and I can add the relationship. When adding the fields from this table, I can chose to use the relationship to add the field instead of the implicit relationship.

I want to completely remove the implicit relationship, and only allow users to add the data from the relationship handler. When I remove the 'join' data above, views won't allow me to add the relationship manually.

Is this possible? Or does that require that I define my joined table as a base table as well?

# Answer
> 0 votes
So, as it turns out, I do NOT need to describe the table as a `base` or `join` table (yay!). I just need to describe the fields. In my case, I needed to add a relationship handler to the `person` table like this:

```
$data['person']['address'] = array(
  'title' => t('Address'),
  'help' => t("Load person's address information from the address table."),
  'relationship' => array(
    'title' => t("Person's Address"),
    'label' => t("Address"),
    'base' => 'address',
    'base field' => 'personID',
    'relationship field' => 'id',
  ),
);

```

There are a couple of things at play here:

1. Normally when adding fields to a table definition, the field has to exist on the database. As it turns out, you can describe "fake" fields as I've done above.
2. This fake field adds a relationship to the table `address` joined by the local **relationship field** `id`.

With this in place, when `person` is the base table, I can add a relationship to `address`. See How do I define this simple views relationship? for more info.

# Answer
> 0 votes
You should be able to add a relationship by using hook\_views\_data. You should however not use the join, but the relationship (right below the huge php comment on the linked page):

```
// Node ID table field.
$data['example_table']['nid'] = array(
  'title' => t('Example content'),
  'help' => t('Some example content that references a node.'),

  // Define a relationship to the {node} table, so example_table views can
  // add a relationship to nodes. If you want to define a relationship the
  // other direction, use hook_views_data_alter(), or use the 'implicit' join
  // method described above.
  'relationship' => array(
    'base' => 'node', // The name of the table to join with.
    'base field' => 'nid', // The name of the field on the joined table.
    // 'field' => 'nid' -- see hook_views_data_alter(); not needed here.
    'handler' => 'views_handler_relationship',
    'label' => t('Default label for the relationship'),
    'title' => t('Title shown when adding the relationship'),
    'help' => t('More information on this relationship'),
  ),
);

```

---
Tags: views
---


# Question
Title: How does Drupal display the correct time for a specific time zone?
I have a custom module that displays today's date and time:

```
t('Today: ') . date('d F - H:i')

```

When I change a user's time zone on their account page the time is 'magically' outputted correctly.

How does Drupal do this?

# Answer
> 0 votes
The magic comes from PHP's `date_default_timezone_set()`:

> Sets the default timezone used by all date/time functions in a script

Drupal uses it in

# Answer
> 0 votes
I've never seen the code itself, but it likely uses this: https://www.php.net/manual/en/datetime.settimezone.php

---
Tags: datetime
---


# Question
Title: In Drupal Fullcalendar, how do I add an additional field to the calendar view?
I need to add one more field to the Fullcalender views. Anyone know what code I need to edit to take care of this?

# Answer
> 1 votes
There's no need to edit any code to add additional field to calendar view.

To add additional field, you need to install Views fields combine or Token module.

**How to use Views fields combine:**

1. Edit your calendar view
2. Add fields you want to display (from field)
3. Add Combined fields field and select which fields you want to display
4. Under format -\> settings -\> customize fields, check **Use a custom title** checkbox and select the combined fields you created on step 3
5. Apply changes and save your view then preview the results on the actual page/block.

---
Tags: views, 7, entities, datetime, javascript
---


# Question
Title: Styling Superfish menu with Zen and Sass
Can anyone advise on the best way to style your superfish menu when using latest version of zen and sass? I am currently styling my responsive theme using the sass files which regenerate the css, which is going great, but superfish comes with its own set of css files which are located sites/all/libraries/superfish/style/css.

I ideally want to use sass to style it from my sass folder (under theme root) so its all consistent, so I dont have to keep changing into the supefish folder changing css directly.

Any ideas?

# Answer
The latest version of Zen is organized according to the SMACSS way. However, what SMACCS calls modules is called components in Zen. This to avoid confusion, since Drupal already has a definition for 'modules'. SMACSS defines modules (or components in Zen) as follows:

*..Module is a more discrete component of the page. It is your navigation bars and your carousels and your dialogs and your widgets and so on...*source

All SASS code concerning components is stored therefore in `your_zen_subtheme/sass/components/_misc.scss` file. I would choose to add style rules for your Superfish menu there. You can use the Superfish classes (with the `.sf` prefix) to target only the Superfish menu instead of all menus.
> 1 votes

---
Tags: navigation, theming
---


title: URL, wildcards, path

text:
# Question
Title: URL, wildcards, path
I am having problems with a sort of pattern matching or path parsing issue.

If I have the following URL: http://www.mysite.com/sem-one-two/play

I have an application that runs at /play, which is not within Drupal.

What I want to do is take URLs, like the above, and pass them to the app.

So in this case, an SEM add links here: http://www.mysite.com/sem-one-two/play

Basically, I want to make the 'sem-one-two' mean nothing in Drupal, but pass it along to the app. In the module Match Redirect (https://drupal.org/project/match\_redirect), Im able to take any URL, like above, and redirect to '/play'. Which gets me half-way, but I need Drupal to ignore 'sem-one-two' if it ends in '/play', but still pass it along to the app.

Am I making any sense? Is there anyone out there that understands what Im asking and has any ideas?

thanks, Mac

# Answer
A couple of ways to look at this in a custom module:

With hook\_init() you should be able to do something like this:

```
function YOURMODULE_init() {

  if (arg(1)=='play') {  //  arg(0) is equal to sem-one-two, arg(1) is equal to play, in your example anyway
    drupal_goto('play');
  }

}

```

but this doesn't take into account any caching of pages for anonymous users so I really don't know how it might work in the real world but if you don't care about the first argument, it should be ok. (hook\_boot() is run for anonymous users/cached pages but does leave out edge caches such as Varnish etc)

What you most probably IMHO *should* do is something with hook\_menu(), eg set up something like this:

```
function YOURMODULE_menu() {

  array $items;

  $items['your-module/%/play'] = array(
    'title' => 'Play',
    'page callback' => 'yourmodule_play',
    'page arguments' => array(1),
    'access callback' => TRUE,
  );

  return $items;

}

```

along with:

```
function yourmodule_play($what) {

  // do whatever with $what...

}

```

This way, you have one menu callback for everything your module wants to "play" plus you know what the "two words" are you are dealing with.

Note that in this second example, it is prefaced with `your-module` as I really haven't seen (and personally think it to be in poor form to have) the first argument in a Drupal path to be itself a wildcard.
> 0 votes

---
Tags: path-aliases
---


title: Recover a deleted field

text:
# Question
Title: Recover a deleted field
I have a content-type with 4 fields each of which is a term reference. There are 100 nodes each assigned 4 term references. I have accidentally deleted one of these fields from the admin\>structure\>content-types\>mycontent-type...resulting in all 100 nodes losing the term reference this lost field contained.

After installing the Database Admin module I could see that the database for my deleted field was still present, it had been renamed to something like "field\_deleted\_field\_74"

1. Using mysql I have been able to rename this database back to "field\_data\_field\_originalname" - i.e. using the original machine name for the deleted field
2. Furthermore I have been able to switch the value of the deleted column inside this database from '1' to '0'.

I have done the above with the other 'ghost' database that I found that was called something like "field\_revision\_field\_74" ...

My problem now is that my renamed field is not appearing as a pre-existing field on my content-type manage fields display nor at admin\>reports\>fields list. When I run 'drush field-info fields' it is also missing.

How to I bring it back? I am assuming that there is another database that refers to it that I need to edit.

Thanks!

# Answer
> 15 votes
A good question, and surprising there's not an easier way to rollback a deleted field, given the data is still available.

Assuming you have:

1. Renamed the field\_deleted\_\* tables back to field\_data\_field\_myfield and field\_revision\_field\_myfield (latter also important)
2. Updated the 'deleted' flag from 1 to 0 in the relevant data tables.

There is also

* `field_config`

> The main field configuration

* `field_config_instance`

> The field configuration on a particular entity bundle.

You may need to adjust the 'deleted' flag there also:

e.g:

```
UPDATE field_config SET deleted = 0 where field_name = 'field_my_deleted_field';
UPDATE field_config_instance SET deleted = 0 where field_name = 'field_my_deleted_field';
TRUNCATE TABLE cache_field;

```

---
Tags: entities, database
---


# Question
Title: Set view header full width (css child conflict)
I created a drupal website using the foundation theme. At the page level the content is put inside a container. Now I created a view and I want the header of this view (using an entity rendered entity) to be full width.

But the page layout is inside a container so the child (views template) cannot exceed it's width. How can I set the header to full width without breaking the page layout?

# Answer
> 1 votes
Create header content as a seperate block and place it in the desired region. Set block visibility as views content.

# Answer
> 0 votes
change the page layout in page.tpl.php: move the container up the DOM structure until you get 100% width, this will result in closing the parent(s) of the container, having the container, and opening the parent(s) again.

or create a new region that will be in 100% width scope, and place the block there

# Answer
> 0 votes
best thing to do is just comment/hide of most of the html/php in page.tpl and then go from there.

*First* way to solve issues relating to css is go in views and go through all format/field and make sure there is no extra html/css markup.

Second best thing is to get CSS formatter class module and go in manage displays of that view and set a new css class and update the .css with a wrapper.

# Answer
> 0 votes
1 - Create a sub-theme based on your current theme and make the page.tpl to full width.

2 - Install theme-key module.

3 - Create a rule to switch theme based on the view you want.

---
Tags: theming
---


# Question
Title: How to set to Webform's fields a 'Number of values' setting like in default content types?
Yeah, so in content type fields like Article or any other when you add a field it has an option 'Number of values' and if you select Unlimited it adds a button 'Add another item' when creating a content.

So I was thinking is it possible to do that with Webform module's forms? Let's say a user is filling in the form, let's say he fills in his phone number into Phone number field and then maybe he has a another phone number, so he could click 'Add another item' and that would open up a second field of a Phone Number field.

To be exact, I need that Unlimited option to work on Webform fieldset fields. So if I have a fieldset of three fields, I can click 'add another item' and it opens up a 2nd fieldset.

# Answer
Webform Addmore

> Webform Add More enables selected fieldsets to be initially hidden and progressively shown with an Add more button, mimicking CCK multiple fields. The approach was proposed by Bartezz, and code originally implemented by span and kranklin . This module adds a checkbox setting to webform fieldset components to select which should have Add more functionality, as well as an advanced setting to override the button label per Webform.
> 2 votes

# Answer
This functionality unfortunately doesn't exist yet. You can read this thread: https://drupal.org/node/354381 which has some hacks/work-arounds that might suit your needs (including the Webform Add More module solution from Mohammed Shameem's response. You may want to subscribe to this thread to be informed if/when the functionality becomes available.
> 0 votes

---
Tags: 7, forms, webforms
---


# Question
Title: Site with Themekey has CSS cross-contamination
I'm using Themekey with Context to enable one of three different themes on a site, depending on a themekey field. The homepage is set to use my main theme, called 'sitetheme'. Sitetheme is set as default, but many themes are enabled.

All the pages that I've tested look good, including the homepage. There's just one exception. My main menu, a horizontal header region menu block that uses Nice Menus to create dropdowns, has weird styling on it. When I inspect the element, I see that it has styling applied from a CSS file that lives in a different theme than the one that is enabled on the front page.

The front page is also of a nodetype that doesn't have the themekey field that some of the nodetypes have, that can be used to override the theme.

Why is my foo theme's CSS for Nice Menus getting applied on pages that use Sitetheme?

# Answer
> 2 votes
I think Nice menus apply to all themes unless you have specified other.

Just go to the following location admin/appearance/settings/your\_theme\_A. Then look for "Path to custom Nice menus CSS file"

Then go to your next theme admin/appearance/settings/your\_theme\_B And also check "Path to custom Nice menus CSS file"

You might surprise, Nice menu use common CSS file regardless of your theme unless you have changed.

---
Tags: theme-negotiation, navigation
---


title: Drupal 7 Twitter

text:
# Question
Title: Drupal 7 Twitter
I have a requirement where I need to tweet through many tweet accounts for which I have username and password.

I have read many tutorials on `oauth`, but I am still confused about using this for multiple twitter accounts.

Is there any way to achieve the same in Drupal using a module?

# Answer
> 3 votes
The Twitter module provides a good way to interact with twitter. It allows you to pull/push tweets. The only problem is that it's not ported yet to Drupal 7, but there is a long issue on drupal.org already.

# Answer
> 0 votes
The Drupal OAuth module has now been available for some time. It is the best way to use OAuth with Drupal: https://drupal.org/project/oauth

For those who come here via Google trying to find info about oauth\_common after installing or updating twitter\_pull (which now requires the twitter module, which leads to an oauth\_common dependency.) You can resolve the oauth\_common dependency by installing oauth, which contains oauth\_common and oauth\_common\_providerui modules.

Thanks VoxPelli for pointing the way.

---
Tags: 7, authentication-authorization, social-network
---


# Question
Title: How to enable install from url in Drupal Commons?
I cannot find any option to install the modules from a url. Currently, I am installing them through cpanel by manually uploading, unzipping etc. Can anyone suggest a solution?

# Answer
Also you can try Drush

> Drush or drupal shell is a command-line utility to help the site building and maintenance workflows.

The following will download and enable the module:

```
drush en module_name -y

```

Example Commands

```
drush dl cck zen

```

Download current recommended versions of CCK module and Zen theme.

```
drush en content

```

Enable the content (cck) module.

```
 drush vset theme_default theme_name

```

make theme\_name theme default theme
> 1 votes

---
Tags: 7
---


# Question
Title: How to quick start sub-theming in Adaptive Theme?
I have a question. I'm a little confused on if I should copy the entire contents of the "adaptivetheme" folder to create a sub-theme, or if only the "at\_subtheme" folder should be copied.

I'm following the instructions from the project at https://drupal.org/project/adaptivetheme, which says that you need to update the theme-setting.php and template.php files, replacing "adaptivetheme\_subtheme" with your new subtheme name. However, within the contents of the instructions it states to only copy the new "at\_subtheme" folder, not the entire "adaptivetheme" folder, and I do not see a theme-setting.php and template.php file in the new "at\_subtheme" folder. I only see theme-setting.php and template.php in the original "adaptivetheme" folder within "at\_core".

Should I copy the entire original "adaptivetheme" folder?

I'm using Drupal 7.26

# Answer
> 2 votes
No, you should copy only the sub theme folder. I have just downloaded all versions of AT and both theme-settings.php and template.php files are there. You may consider deleting the existing adaptivetheme folder and downloading it again.

---
Tags: 7, theming
---


# Question
Title: Open an image in a new pop up window when form submit button is clicked in Drupal 7
I have a form with only a submit button in it and I want to display an image in a new pop up window whenever form submit button is clicked in Drupal 7 node.

```
function custommodule_my_form($form, &$form_state) {
$imgurl = $form_state['build_info']['args'][1];
$form['submit'] = array(
    '#value' => 'Print Coupon',
    '#type' => 'submit',
);
return $form;
}

```

The image is present in the loaded node and I already have its URL inside a variable $imgurl.

Now how can add an attribute in this form so that $imgurl opens up in a new window whenever this submit button is clicked.

```
$form['submit']['#attributes']['onclick'] = ??

```

# Answer
I resolved it like this:

```
 $form['submit']['#attributes']['onclick'] = "javascript: newwindow=window.open('$imgurl','height=500,width=300');";

```

So, the complete form code now becomes:

```
$form['submit'] = array(
    '#value' => 'Print Coupon',
    '#type' => 'submit',
);
$form['submit']['#attributes']['class'][] = 'form-submitone';
$form['submit']['#attributes']['onclick'] = "javascript: newwindow=window.open('$imgurl','height=500,width=300');";
return $form;

```
> 0 votes

# Answer
You can give like this:

```
$form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Submit'),
        '#attributes' => array(
            'onclick' => 'function_name()'),
        )
    );

```
> 0 votes

# Answer
I would inject a bit of js code to listen to your click and show the popup with the image. You can open the popup url before the page reloads or after.

You may want to have a url path to a page that shows the image so that it will not get downloaded. e.g.

```
http://yoursite.com/showcoupon/[unique id of coupon]

```
> 0 votes

---
Tags: forms
---


# Question
Title: How to create the slideshow as the background slideshow using drupal 7?
We are currently developing a single page responsive site in drupal 7.In our home page we tried implementing slideshow through view slideshow module (drupal 7). The slideshow is working perfectly fine. I want to know how to create a background slideshow using views slideshow?

# Answer
> 0 votes
Use Backstretch module and see the demo in action(In dropdown select "Using Backstrech as slideshow") Even though it is in dev stage but it works well in my production without issue.

> This module provides a field formatter and Context integration for jQuery Backstretch - A simple jQuery plugin that allows you to add a dynamically-resized, slideshow-capable background image to any page or element.

# Answer
> 2 votes
You can try using the Vegas Background jQuery Plugin module.

> Vegas is a jQuery plugin to add beautiful fullscreen backgrounds and slideshows to your webpages.

Try out the module demo.

# Answer
> -1 votes
The Photo module is great but still alpha stage. Details from its project page:

> Photo is a photography and multimedia theme with a full screen slideshow. Showcase your important work, imagination with full screen photo slider. Photo is Drupal theme for photographic professionals, photo artist, amateur photographers to create photo gallery, portfolio with photos, video blogs. It is also useful for architecture, travel sites, hotels, restaurants, sculpture artist and for any purpose who want to emphasis on photos for the website.

Otherwise Write your own JS or add JS plugin to get this effect. With Jquery, anything is possible.

---
Tags: theming, views, javascript
---


# Question
Title: Which is the better module for shopping cart?
I would like to use a shopping cart module in my site.

Can any one suggest which would be the better one with basic functionality like displaying content (media), cost, adding to cart, billing, etc. It must include all necessary features of a shopping cart.

Will Ubercart fulfill the basic requirements?

# Answer
From the sounds of it, you actually want a whole e-commerce system, not just a shopping cart.

Ubercart will do this for you, but the general trend now is to go with Drupal Commerce (project page | Commerce homepage).

Both modules will allow for shopping carts, as well as integration with a variety of payment service providers. I'd personally go with Drupal Commerce. It seems a little more difficult than Ubecart at first glance, but once you get over that you'll realise it is much more flexible/powerful.

Try using the Commerce Quickstart installation profile to get yourself familiar/started with it.

There are a lot of good videos for Commerce as well such as Selling Content with Drupal Commerce using Content Access and Roles from the Commerce Guys.

Lastly, there is a blog post here that weighs up the pros and cons of each system (although it is from 2011)

Edit:

You might find the getting started guide useful also.
> 6 votes

# Answer
If you want a simple and easy to configure e-commerce solution for Drupal 7, try the Light Shop module.

However, do note that it doesn't provide any payment integration (only e-mail notifications are there).
> 0 votes

---
Tags: ubercart
---


title: Pathauto: Bulk update not working

text:
# Question
Title: Pathauto: Bulk update not working
Pathauto was working for me in the past but just now, after setting a new pattern for my content clicking bulk update while checking every single content type to be sure, I get the "No new URL aliases to generate" message.

I even tried changing the pattern of my other content that already has generated url aliases and ran bulk update later, but I still got the "No new URL aliases to generate" message.

How can I debug this problem? My pattern is straightforward:

```
blogs/[node:title]

```

Devel shows that the \[node:title\] token exists.

# Answer
Updating it from the admin/content page works as normal. I select what needs to be updated and scroll to the bottom to "Bulk operations -\> Update URL alias".

I don't need to delete any URL aliases manually
> 0 votes

---
Tags: path-aliases
---


title: Creating a "User edit path" menu

text:
# Question
Title: Creating a "User edit path" menu
I want to create a menu with title "Edit" and path "user edit path". I tried to put user/%user/edit; user/%id/edit but no success. Any idea?

# Answer
You can use user/\[current-user:uid\]/edit once you have the menu\_token module installed.
> 9 votes

# Answer
You can also use the Me Aliases module. It provides shortcut paths to current user's pages, eg user/me, blog/me, user/me/edit, tracker/me etc.

This means you can use 'me' in your menu path.
> 5 votes

# Answer
Programatically a link to current logged in user's edit page can be created like this (in a custom module or in user template page):

```
    <?php
    if (user_is_logged_in()) {
        global $user;?>
        <a href="<?php print $user->uid . '/edit/'; ?> " >Edit</a>
    <?php } ?>

```
> 1 votes

---
Tags: 7, users
---