# Question
Title: How to output a view field only on the first row?
I have a view where notification messages are listed and on the top a simple field that shows a value from the user's "notifications" field.

The problem is that it shows on each row, whereas I just want it to output in the first row.

How can this be done excluding css and jQuery?

This is the view code:

```
$view = new view();
$view->name = 'user_activity';
$view->description = 'Show all existing messages.';
$view->tag = 'Message';
$view->base_table = 'message';
$view->human_name = 'User activity';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'administer message types';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '30';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* No results behavior: Global: Text area */
$handler->display->display_options['empty']['area']['id'] = 'area';
$handler->display->display_options['empty']['area']['table'] = 'views';
$handler->display->display_options['empty']['area']['field'] = 'area';
$handler->display->display_options['empty']['area']['content'] = 'No messages created yet.';
$handler->display->display_options['empty']['area']['format'] = 'filtered_html';
/* Relationship: Message: User uid */
$handler->display->display_options['relationships']['user']['id'] = 'user';
$handler->display->display_options['relationships']['user']['table'] = 'message';
$handler->display->display_options['relationships']['user']['field'] = 'user';
/* Field: User: Notifications */
$handler->display->display_options['fields']['field_notifications']['id'] = 'field_notifications';
$handler->display->display_options['fields']['field_notifications']['table'] = 'field_data_field_notifications';
$handler->display->display_options['fields']['field_notifications']['field'] = 'field_notifications';
$handler->display->display_options['fields']['field_notifications']['relationship'] = 'user';
$handler->display->display_options['fields']['field_notifications']['group_type'] = 'count_distinct';
$handler->display->display_options['fields']['field_notifications']['label'] = '';
$handler->display->display_options['fields']['field_notifications']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_notifications']['settings'] = array(
  'thousand_separator' => '',
  'decimal_separator' => '.',
  'scale' => '0',
  'prefix_suffix' => 1,
);
/* Field: Message: Render message (Get text) */
$handler->display->display_options['fields']['message_render']['id'] = 'message_render';
$handler->display->display_options['fields']['message_render']['table'] = 'message';
$handler->display->display_options['fields']['message_render']['field'] = 'message_render';
$handler->display->display_options['fields']['message_render']['label'] = 'Text';
$handler->display->display_options['fields']['message_render']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['message_render']['hide_alter_empty'] = FALSE;
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'user';
$handler->display->display_options['fields']['name']['label'] = 'User';
/* Field: Message: Timestamp */
$handler->display->display_options['fields']['timestamp']['id'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['table'] = 'message';
$handler->display->display_options['fields']['timestamp']['field'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['label'] = '';
$handler->display->display_options['fields']['timestamp']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['timestamp']['date_format'] = 'time ago';
/* Sort criterion: Message: Timestamp */
$handler->display->display_options['sorts']['timestamp']['id'] = 'timestamp';
$handler->display->display_options['sorts']['timestamp']['table'] = 'message';
$handler->display->display_options['sorts']['timestamp']['field'] = 'timestamp';
$handler->display->display_options['sorts']['timestamp']['order'] = 'DESC';
/* Filter criterion: Message: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'message';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['exposed'] = TRUE;
$handler->display->display_options['filters']['type']['expose']['operator_id'] = 'type_op';
$handler->display->display_options['filters']['type']['expose']['label'] = 'Message type';
$handler->display->display_options['filters']['type']['expose']['operator'] = 'type_op';
$handler->display->display_options['filters']['type']['expose']['identifier'] = 'type';

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->display->display_options['path'] = 'admin/content/message';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Messages';
$handler->display->display_options['menu']['description'] = 'A list of all messages.';
$handler->display->display_options['menu']['weight'] = '0';
$handler->display->display_options['menu']['name'] = 'management';

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->display->display_options['block_description'] = 'User activity';

```

# Answer
If you include the field you want to have displayed at the top included in the fields of the View, but then excluded from display, you can use it as a replacement token in a global text area in the Header of the View, eg:

will include the node title in the View, but won't print it in the rows, and:

will put it at the top of the View when it is displayed.
> 1 votes

# Answer
Might it be an option to use two views - create the first one so that it includes the notification field, then the second view to list all the other entries other than the first, without that field?
> 1 votes

---
Tags: views, entities, notifications
---


# Question
Title: module's local *.tpl.php, defined in $theme_registry, "not found or invalid" when referenced later in module
I built a custom login module for my Drupal7.26 install.

Extending it, I've added a \*.tpl.php locally

```
ls sites/all/modules/custom/jl_login/templates/
    user-login-member-form.tpl.php

```

To get the tpl.php into theme registry, in "my\_login\_mod.module" I added

```
function jl_login_theme() {
    return array(
        'user_login_member_form' => array(
            'render element' => 'form',
            'template' => 'templates/user-login-member-form',
        )
    );
}

```

After module disable/uninstall/enable, and clear all caches, I load my site/page.

Checking output with

```
<?php print '<pre>'; var_dump(theme_get_registry()); print '</pre>'; ?>

```

I see the form in the registry

```
 ["user_login_member_form"]=>
  array(6) {
    ["render element"]=>
    string(4) "form"
    ["template"]=>
    string(76) "sites/all/modules/custom/jl_login/templates/user-login-member-form"
    ["type"]=>
    string(6) "module"
    ["theme path"]=>
    string(43) "sites/all/modules/custom/jl_login"
    ["preprocess functions"]=>
    array(1) {
      [0]=>
      string(19) "template_preprocess"
    }
    ["process functions"]=>
    array(2) {
      [0]=>
      string(16) "template_process"
      [1]=>
      string(14) "ctools_process"
    }
  }

```

Later in my .module, I use the form:

```
function _jl_login_login_block_view($delta='') {
    $this_user_login_form    = drupal_get_form('user_login_member_form');
    ...

```

But on load I see in drupal logs,

```
Feb 24 16:32:16 dev d7: http://dev.loc|1393288336|php|127.0.0.1|http://dev.loc/||0||Notice: Undefined index: user_login_member_form in drupal_retrieve_form() (line 771 of /home/jl/d7/includes/form.inc).
Feb 24 16:32:16 dev d7: http://dev.loc|1393288336|php|127.0.0.1|http://dev.loc/||0||Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'user_login_member_form' not found or invalid function name in drupal_retrieve_form() (line 806 of /home/jl/d7/includes/form.inc).

```

What do I need to change to be able to use/reference the local form?

# Answer
`drupal_get_form()` expects the name of a function that builds a form array, e.g.

```
function MYMODULE_some_form($form, &$form_state) {
  $form['#theme'] = 'user_login_member_form';

  $form['foo'] = array(
    '#type' => 'textfield',
    '#title' => t('Bar'),
    '#default_value' => t('Baz'),
  );

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

  return $form;
}

function MYMODULE_some_form_submit($form, &$form_state) {
  // Process $form_state['values']
}

// In a hook...
$form = drupal_get_form('MYMODULE_some_form');

```

You don't need to add the form function to a registry as such, just giving it the same name as the string you pass to `drupal_get_form()` is enough.

`hook_theme()` is for registering theme functions, which is why you're currently getting an error.

The Form generation docs have a bit more information, and the FAPI reference is invaluable if you're new to the form API. For theming the form, there are some excellent answers to this question which should help.
> 2 votes

---
Tags: 7, forms, theming
---


# Question
Title: D7 - Print node taxonomy terms including custom term field as CSS Class
I have a list of possible taxonomy terms (vocab is called *Categories*) that can be referenced on a given node. For this particular vocabulary, I have a custom field called `field_icon_class`. The intention here is to make use of CSS Sprites, so when the terms for the page are rendered, they hopefully get printed out with the field as the CSS Class for the individual taxonomy term.

I've tried numerous ways to get these to render the way I would like to no avail. I've tried:

```
taxonomy_term_load_multiple($node->field_categories);

```

along with a combination of other iterative statements which weren't successful. Ideally, I would like for each taxonomy term for that node to render along the following lines:

```
<div class="[field_icon_class]">[taxonomy term name]</div>

```

Any ideas how this can be accomplished, or any module exists to do so? Much thanks!

# Answer
Are you cool with using views? I do this type of thing all the time on my site. If you are then reply back and I'll post an example.
> 1 votes

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


# Question
Title: Creating multiple nodes of different content type at once
Can someone tell me if there is a module that will allow a user to create multiple nodes of different content types within one form? I have a base content type that can have a 1 to many relationship to another content type. I want the user to be able to create the base content type node along with 1 to n nodes for the second content type.

# Answer
> 1 votes
The module you are looking for is Node Reference Create. Here is a quote about it (from the module's project page):

> ... is an enhancement to the nodereference autocomplete widget that allows users to reference non-existent nodes.
>
> When no matching node is selected, the new nodes are automatically created allowing for a seamless and intuitive user experience that is similar to free tagging.

---
Tags: nodes
---


# Question
Title: How drupal.org found a website installed module
I want to know how drupal.org counts the websites which use a specified module, as example in views module page reports:

`Reported installs: 717,794 sites currently report using this module. View usage statistics.
Downloads: 4,815,869`.

It is not hard to find the number of downloads but I want to know how drupal.org gets `Reported installs`?

Is there any way to find out the number of websites that use my custom modules that are not published in the drupal.org website?

# Answer
> 10 votes
Drupal.org gets 'reported installs' from the Update manager module. So to do something like that you would need you custom module to report back to a server of yours, and preferrably have your users be notified for that.

# Answer
> 8 votes
I'd guess they track that data when sites request update info (it's the only possible time, thinking about it).

So unless you're explicitly tracking and saving that data yourself somehow, be it through your own module server or other method, then unfortunately not.

# Answer
> 3 votes
> **Only sites running the Update Status module report data back to drupal.org.**

As the statistics page for the module mentions

> These statistics are incomplete; only Drupal websites using the **Update Status** module are included in the data.

If you want further details please read https://drupal.org/node/329620

If you want to track your module installs you will need to know how drupal.org generates these statistics. Your first check point should be taking a look at the code in the Project module.

---
Tags: 7
---


# Question
Title: EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityMetadataWrapper->set()
I am creating nodes programmatically. I Have written following code,

```
$e = entity_create('node', array('type' => 'some_node'));
// Specify the author.
$e->uid = 1;
// Create a Entity Wrapper of that new Entity.
$entity = entity_metadata_wrapper('node', $e);

// Specify the title.
$entity->title = 'Some Title';
$entity->body = 'abc';
$entity->save();

```

On giving value to body i am getting following error. Commenting body it works fine

> EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityMetadataWrapper-\>set()

What is causing this error and how can I fix it?

# Answer
> 10 votes
Body is a Field API field and not a native PHP variable, therefore you cannot assign values to it like that. Instead, you would need to pass an array with the following keys:

```
$entity->body->set(array(
  'value' => 'This is the body',
  'summary' => 'This is the summary',
  'format' => 'full_html',
));

```

If you wish to set the value for a specific language, you call prior to set:

```
$entity->language(LANGUAGE_NONE); // or 'en' or whatever

```

More on wrappers: https://drupal.org/node/1021556

# Answer
> 2 votes
Try using below code

```
$entity->body->set(array('value' => "abc"));

```

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


title: hook_file_download not triggered

text:
# Question
Title: hook_file_download not triggered
I set the private file system to `/system/files/export` , I create a file in private directory programmatically and it not belong to any field ,and show link to user , I implement `Hook_file_download` , I want check some condition in it but when user click on link to download the file created in private path it return me **Forbidden** and `mymodule_file_download` not tirggered ( I put some code to it , even die but never called). I clear cache but noting changes, the link that showed for user is `http://localhost/mytestdrupal/system/files/export/Export-couponcards-1393307265.csv` where is problem?

Part of my code to create file in submit

```
function mymodule_export_form_submit($form, $form_state) {
    $temp1 = variable_get('file_private_path');
    if (!file_prepare_directory($temp1, FILE_CREATE_DIRECTORY)) {
        drupal_set_message(t('Problem in write file in directory'), 'error');
        return;
    }
    $filename = 'Export-file'. '.csv';
    $filepath = $temp1 . '/' . $filename;
    $df = fopen($filepath, 'w');
    if (!$df) {
        drupal_set_message(t('Can not write file in') . $filepath, 'error');
        return;
    }
            fputcsv($df, array('code', 'name'));
            fputcsv($df, array('test','test'));

    fclose($df);
    $path = file_create_url($filepath);
    drupal_set_message(t('Export done. ') . '<a href="' . $path . '">' . t('Download export file') . '</a>');
}

```

# Answer
> 1 votes
hook\_file\_download working perfectly, List of steps which worked for me

1. I made File System to Private
2. Created a File Field in Article Content Type and marked it as Private In Settings
3. Uploaded a PDF File
4. Link to file is something link below

http://example.com/d7/system/files/***\*.pdf

Created a custom module with hook\_file\_download, When ever i access above URL and visit any page i can see drupal set message "Hi"

```
function drup_custom_file_download($uri) {
  drupal_set_message("Hi");
}

```

# Answer
> 1 votes
First you need to verify your file is being saved to the correct place.

You say you want to save to a sub-directory 'export' but that is not what your code is doing.

You should be saving to the private file system, not the public one. So `variable_get('file_private_path', '')` instead of `variable_get('file_public_path')`.

Then append you export directory, so it would be:

```
$temp1 = variable_get('file_private_path', '') . '/export';

```

Then if you file is successfully saved at `/sites/default/files/private/export` (or wherever your private files should be), then you are ready for the next step.

When making the link to the file you have to pass in a uri, so

```
$path = file_create_url($filepath);

```

should be something like:

```
$path = file_create_url('private://export/' . $filename);

```

Using the 'private' stream wrapper means that internal links match to /sites/default/files/private (or whatever you have `variable_get('file_private_path', '')` set to) and external links generate like www.example.com/system/files/...

For more information see: DrupalPrivateStreamWrapper

---
Tags: hooks, files
---


title: How to add a view inside a view?

text:
# Question
Title: How to add a view inside a view?
I have 2 groups of blocks in a view, I would like to join both of them in one view, showing the first block (I have the groups all linked one to the other). I did download Views Field View but I can not manage the way to get it work, joining these 2 views.

# Answer
> 2 votes
The module 'Views Field View' that you have mentioned is very good imo. In order to use it, you have to edit a view A and add another existing view B as a *field* of view A.

But this is as far as it gets, it does not facilitate a 'joining' of views of any sort, for that matter I think it would be better for you to rebuild a new view with relationships etc, if Views Field View is not adequate for you.

# Answer
> 0 votes
You can add the second "block" as "attachment" display (instead of the block display) and choose "block 1" on your new attachment display.

Attachments are very handy in this kind of situations.

About view displays: What is the purpose of Views "Attachment", "Content pane" & "Context"?

---
Tags: entities, views
---


# Question
Title: Runing PHP Code inside region.tpl.php file
I'm trying to create a dynamic site based on a static theme. I wonder to know why when I want to put my main menu in the *region--page-top.tpl.php* it does't work. this code

```
<?php print theme('links__system_main_menu',
                   array('links' => $main_menu,
                            'attributes' => array( 'class' => array('links','inline'))));?>

```

works correctly inside the page.tpl.php but it seems that php code doesn't recognize in the region section. The HTML codes work fine, though.

# Answer
I believe you cannot render main menu in this way within a region, the variable is not there. You could try with:

```
$main_menu_tree = menu_tree(variable_get("menu_main_links_source", "main-menu"));
print drupal_render($main_menu_tree);

```

Even better, I would recommend that you simply render the output of the particular region properly and add the menu dynamically from Blocks administration.

To render a region in your theme shortly, you need to define a proper region in your theme's `.info` file (eg. `my_region`) and render it using `print render($page['my_region']);` in the `.tpl.php` file. I hope this guide will help you: https://drupal.org/documentation/theme
> 1 votes

---
Tags: theming
---


# Question
Title: Redirecting after login for specific roles
I want to redirect specific users after a succesful login but I can't make it work. Here's my code:

```
function concessionaire_login_user_login(&$edit, $account) {
foreach ($account->roles as $role){
    if($role == "administrator"){
    } else if ($role=="concessionnaire"){
        global $language;
        unset($_REQUEST['destination']);
        unset($_REQUEST['edit']['destination']);
        $url = "http://www.my-site.com/myfile.php";
        $options = array(
        'query' => 'id_rub=14&lg='.$language->language
        );
        drupal_goto($url,$options)

    }
}

```

}

I tried also with `header('location: $url')`, but it doesn't work either. Login\_destination module was my first guess but I can't use variables..

Also is it possible to redirect to an external URL and passing POST parameters at the same time ?

Thanks in advance.

# Answer
Some things to look at:

'query' itself needs to be an array, not a string, eg...

```
array('id_rub' => '14', 'lg' => $language->language)

```

and if you want to call header() directly, you need some more parameters:

```
header('Location: ' . $url, TRUE, $http_response_code);
drupal_exit($url);

```

(and an exit for good measure...btw, that's all drupal\_goto() is really doing anyway)
> 1 votes

# Answer
This might help you out.

function login\_user\_login(&$edit, $account) {

```
 $urlAdministrator = 'yoururl';

```

$urlconcessionnaire = 'yoururl'

if (in\_array('administrator', $account-\>roles)) {
drupal\_goto( $urlAdministrator );
}
if (in\_array('concessionnaire', $account-\>roles)) {
drupal\_goto( $urlconcessionnaire );
}
}

Thanks
> 0 votes

# Answer
You can use the Login Destination module.
> -1 votes

---
Tags: 7, users
---


# Question
Title: Delay in logging Drupal user through Services
I have two Drupal7 sites. I am using a service that allows a registered user to login using session authentication.

On the site that performs the call to my remote service I measured the time when I enter the login function and after I got my session id response. It is 6 seconds apart.

When I use the browser to login it works as normal, no delays. Both Drupal7 instances are running on localhost.

I need some pointers as to where to look in order to reduce this latency.

```
watchdog("LOG", "Login function hit at " . date(DATE_RFC2822));
$resource = 'access/';

$this->options = array(
  'headers' => array(
    'Accept' => 'application/json',
    'Content-Type' => 'application/json',
  ),
  'method' => 'POST',
  'data' => json_encode(array(
    'username' => $this->username,
    'password' => $this->password,
  )),
);

$response = drupal_http_request($this->base_url . $resource . 'user/login', $this->options);
$data = json_decode($response->data);

// Check response code
if ($response->code == 200 && $data != null) {
  $this->options['headers']['Cookie'] = $data->session_name . '=' . $data->sessid;
  watchdog("LOG", "Connected to remote at " . date(DATE_RFC2822));
}

```

I wrote a basic php login function to run it from outside a Drupal install and the time to login is 5 seconds. Measured the web login and it's instant. I also switched from Services Resource API 1.0 to 1.1 with no improvements.

# Answer
> 1 votes
This looks unrelated to drupal itself but it's more likely to be a glitch / misconfiguration in the web server/LAMPP settings or a DNS lookup issue.

Can you please let us know more about your LAMPP stack and OS?

Also consider trying the following:

1. Setting the ServerName property in httpd.conf ( `ServerName
 127.0.0.1:80` )
2. If the above doesn't work, in your httpd.conf be sure to set the setting `HostnameLookups Off`
3. Enable slow query log in MySQL.
4. Have a look at this post https://serverfault.com/questions/66347/why-is-the-response-on-localhost-so-slow

---
Tags: users, services
---


title: Alternative of Hierachical Select

text:
# Question
Title: Alternative of Hierachical Select
I see this module is currently old and not maintained by the developers. Is there any alternative module for this?

# Answer
> 1 votes
Try Simple Hierarchical Select.

> Simple hierarchical select defines a new form widget for taxonomy fields to select a term by "browsing" through the vocabularies hierarchy. The widget is available in node forms and as Views exposed filter.

---
Tags: taxonomy-terms
---


title: Popular tags view active class

text:
# Question
Title: Popular tags view active class
I have a view which is a HTML list of the most popular tags in a specific vocabulary it is displayed as a block on a page of most recent news items. It is also displayed on each individual news item.

When it is displayed on the individual news item page I would like any tag that the news item has been tagged with and that also appears in the popular tags block to be highlighted by adding a css class called active.

How would I achieve this?

# Answer
Well, the only method I can think of is to do it the template, but have a feeling there must be a better solution than this... But to do it this way:

Edit your view and under Advanced click on Theme: Information. This shows a list of template file names that would apply to your view. If you had a view called tags then creating a template file called **views-view-fields--tags.tpl.php** would be appropriate. After adding your template file (in your themes directory) click the Rescan template files button.

The standard template file looks like this:

```
<?php foreach ($fields as $id => $field): ?>
  <?php if (!empty($field->separator)): ?>
    <?php print $field->separator; ?>
  <?php endif; ?>

  <?php print $field->wrapper_prefix; ?>
    <?php print $field->label_html; ?>
    <?php print $field->content; ?>
  <?php print $field->wrapper_suffix; ?>
<?php endforeach; ?>

```

But if you changed it to this:

```
<?php foreach ($fields as $id => $field): ?>
<?php if (!empty($field->separator)): ?>
<?php print $field->separator; ?>
<?php endif; ?>
<?php print $field->wrapper_prefix; ?>
<?php print $field->label_html; ?>
<?php
$current = false;
if(arg(0)=='node' && is_numeric(arg(1))) { // check if we are on a node page
    $node = node_load(arg(1)); // load the node
    $tag = strip_tags($field->content);
    foreach($node->field_tags[LANGUAGE_NONE] as $term) { // loop over the tags attached to the node
        if($term['taxonomy_term']->name == $tag) { // there is a match
            $current = true;
            break;
        }
    }
}
if($current) {
    print '<span class="current">'.$field->content.'</span>'; // add a span with current class
} else {
    print $field->content;
}
?>
<?php print $field->wrapper_suffix; ?>
<?php endforeach; ?>

```

The disadvantage of this method it that code needs to run for each tag in the list, but it would achieve the desired result.
> 1 votes

# Answer
MY\_MODULE.module

```
function MY_MODULE_views_api() {
  return array(
    'api' => 3,
    'path' => drupal_get_path('module', 'MY_MODULE') . '/includes',
  );
}

```

MY\_MODULE.views.inc

```
function MY_MODULE_views_data_alter(&$data) {
  $data['taxonomy_term_data']['name']['field']['handler'] = 'MY_MODULE_views_handler_field_taxonomy_active';
}

```

MY\_MODULE\_views\_handler\_field\_taxonomy\_active.inc

```
class MY_MODULE_views_handler_field_taxonomy_active extends views_handler_field_taxonomy {

  function options_form(&$form, &$form_state) {
     $form['active_class'] = array(
       '#title' => t('Add active class to term link'),
       '#description' => t('This allows you to add an active class to a link id the term exists on the current page.'),
       '#type' => 'checkbox',
       '#default_value' => !empty($this->options['active_class']),
     );
    parent::options_form($form, $form_state);
  }

  function render_link($data, $values) {
    $tid = $this->get_value($values, 'tid');
    if (!empty($this->options['link_to_taxonomy']) && !empty($tid) && $data !== NULL && $data !== '') {
      $term = new stdClass();
      $term->tid = $tid;
      $term->vid = $this->get_value($values, 'vid');
      $term->vocabulary_machine_name = $values->{$this->aliases['vocabulary_machine_name']};
      $this->options['alter']['make_link'] = TRUE;
      $uri = entity_uri('taxonomy_term', $term);
      $this->options['alter']['path'] = $uri['path'];
    }

    if (!empty($this->options['active_class']) && arg(0) == 'node' && is_numeric(arg(1))) {
      $raw_terms = array();
      $node = entity_load_single('node', arg(1));
      $terms = field_get_items('node', $node, 'field_tags');
      foreach($terms as $k => $v) {
        $raw_terms[] = $v['tid'];
      }

      if(in_array($tid, $raw_terms)){
       $this->options['alter']['link_class'] = 'active';
      }
      else {
        $this->options['alter']['link_class'] = '';
      }
    }

    if (!empty($this->options['convert_spaces'])) {
      $data = str_replace(' ', '-', $data);
    }
    return $data;
  }
}

```
> 0 votes

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


title: Modifying the HTML generated for Menus

text:
# Question
Title: Modifying the HTML generated for Menus
I've read the questions already asked but they didn't answer my question. But they were sucessful in confusing me more. There are hooks, render functions of two types, theme functions, pre-processing functions, processing functions. In every question I read over internet the answer is different every time. My head's gonna explode.

Coming to question, I need just the `text` & `href` from menu-item or link. I'll handle the rest.

**How I want it?**

```
//I need control over the HTML wrapper elements for menu
foreach $menu_items as $menu_item:
    if(has_submenu($menu_item)):
        print "custom html here";
        foreach $menu_item as $sub_menu_item:
            print "custom html here".$sub_menu_item['name'].$sub_menu_item['href']."custome html here";
    endif
    print "custom html here".$menu_item['name'].$menu_item['href']."custome html here";

```

# Answer
Try to use: menu\_tree\_all\_data(). It will get a menu tree of your given menu machine name.
> 2 votes

---
Tags: 7, routes
---


# Question
Title: How to theme the Event content type node creation form in drupal 6?
I have installed Event module which gave me an "Event" content type.

I want to theme the node edit/creation form for the Event content type that automatically comes once the Event module is enabled.

I have tried defining the custom tpl to handle but it's not working. Any help would be appreciated.

Thanks.

# Answer
> 1 votes
It all depends on what changes you want to make, but the standard way of altering forms in D6 (and D7) is invoking hook\_form\_alter() in a custom module. Do a switch on the form\_id, and enter your edits, something like this:

```
YOUR_MODULE_form_alter(&$form, &$form_state, $form_id) {
  // print $form_id; exit;
  switch($form_id){
    case 'event_node_form':
      // change the form. The following will alter the text on the submit button:
      $form['submit']['#value'] = 'Go!';
      break;
  }
  return $form;
}

```

If you don't know what the form\_id is of the form you want to edit, just uncomment the `print $form_id` line and visit the form in your browser. You can refer to the D6 form api guide to find what form elements go with which properties. Hope that helps!

---
Tags: theming, forms, 6
---


# Question
Title: How to get the actual value of a field in Views?
I'm using the Views module and Drupal 7 and want to add a class to all rows of my table that have a certain value for a certain field.

The field is a bit field and is included in my query. I have added a PHP field (a separate Views module that is installed) with the following code:

```
if ($row->field_kampioen || $row->field_spirit) {
    return 'views-table-highlight';
} else {
    return '';
}

```

This should allow me to set the row class to `[php]`. This works, but all rows get the css class. When I output this for debugging:

```
return $row->field_champion . ' ' . $row->field_spirit . ' ';

```

I see that the classes are all different numbers, and `field_champion` is equal to `field_spirit`. This makes me think I'm seeing the ID.

How can I get a `TRUE` of `FALSE`? So, how can I get the actual bit value of this field?

It would be nice if I could do this via the Views module only, but I've seen pages where hooks are used. Maybe I'll have to use that.

# Answer
> 0 votes
I'm assuming you are using Drupal 6, since you mentioned about PHP filed.

below is the code to retrieve value from a field and where \['tid\_1'\] is the token for a field. I think this is similar for Drupal 7 too.

```
<?php
$static = $this->view->display_handler->get_handlers('field');

$b=$static['tid_1']->last_render; //$b contains the value of the field
$d=$static['tid_2']->last_render; //$d contains the value of the field
//use your logic
 ?>

```

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


# Question
Title: modify Drush uli returned URL string of to include port?
I want to modify a variable (preferably in a Bash Script format) because my PHP environment requires a port number.

To open a browser in Drush, one executes

```
$ drush uli

```

In a script:

```
$ bash-3.2$ VAR='drush uli'; echo ${VAR}; ${VAR}

```

outputs:

> drush uli

```
http:/ /website-7-26-2-17-res124725.local/user/reset/1/1393147909/zMiquSr_ikA7xdp7kA3g4CvTGd82mWsVdqEiMCs/login

```

Can I modify that URL before Drush opens the browser?

Can I stop it from executing and manipulate the URL in a Bash script?

# Answer
You can create settings.local.php with your development base url:

```
$base_url = 'http://website-7-26-2-17-res124725.local:8888';  // NO trailing slash!

```

Drush just uses Drupal's `url()` function to build user one-time-login link.
> 2 votes

---
Tags: drush, users
---


title: Database Each table Usage

text:
# Question
Title: Database Each table Usage
Where can I see the each table usage, which is getting created in default installation of a **Drupal** site.

Likes **node** table - `used to store all nodes in them`. For other tables where i can get the information. Any documentation for each table usage in database??

Thanks in advance.

# Answer
For databases that implement information schema, use:

```
SELECT table_name, table_comment
FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema='my_cdrupal_database'

```
> 2 votes

# Answer
Run below query on your database and see last column in the result table.

```
SHOW TABLE STATUS

```

See Screenshot below for example.
> 2 votes

# Answer
Just to add the Drupal-y answer...

You can install the Schema module for that, amongst its features is:

> Schema documentation: hyperlinked display of the schema's embedded documentation explaining what each table and field is for.
> 2 votes

---
Tags: 7, database
---


# Question
Title: Changing video content type (mime type) in CDN
I am using media module to save media in CDN. To play videos, we are using jwplayer in Drupal 7. Jwplayer throws error in IE, If video is not of content type \[mime type\] video/mp4. I have changed the existing CDN videos mime type from application/octet-stream to video/mp4.

Now whatever mp4 videos are being uploaded/saved to cdn should only be of video/mp4 mime type but when I upload mp4 videos in media module it is saved in CDN with mime type application/octet-stream, How do I change the uploaded mime type \[content type\] to video/mp4.

How do I change mime type\[content type\] to video/mp4 in media module, Drupal 7, when mp4 video are being uploaded.

# Answer
> 1 votes
Found the Answer :

1) "A MIME-TYPE is a server side setting. You can ask your hosting provider to add the MP4 MIME-TYPE for you.

Or, you can add a .htaccess file to the directory where you uploads are stored".

A sample .htaccess file that adds the MP4 MIME-TYPE is:

```
<IfModule mod_rewrite.c>
  AddType video/mp4 .mp4
</IfModule>"

```

Source : Need to Change Video Content Type to video/mp4 so it plays in IE

But this did not work for me for some reason

2) I did the change in my core class file which i was using in drupal module for CDN upload I had made a change in my class.s3.php file -\> in mime\_type\[\] array and also, cross checked with putObject() function.

\**

> Setting of mime type is always done in coding side and not in AWS S3 bucket, We need to use AWS PHP Class file or sdk to do the manipulation in mime type or make the necessary changes in core class file (eg. class.s3.php )

\** For details check here find-mime-type-of-file-or-url-using-php-for-all-file-format

Second Answer has worked for me :)

---
Tags: 7, media, cdn
---


title: Drupal ui inside module

text:
# Question
Title: Drupal ui inside module
Am i doing wrong to define, jQuery Accordion inside my .module file, just like this:

```
<?php
  drupal_add_library('system', 'ui.accordion');

```

Drupal no longer loading jquery itself.

# Answer
You can add below code in your theme template.php

```
function NAME_OF_THEME_preprocess_page(&$variables) {
  drupal_add_library('system', 'ui.accordion');
}

```
> 3 votes

# Answer
Yes that's wrong, you need to put it inside a hook function.

Which one depends on where you're trying to use it. To add it to a render array, for example a form, you might use

```
$form['#attached']['library'][] = array('system', 'ui.accordion');

```
> 7 votes

---
Tags: 7, javascript
---


# Question
Title: How to get available view modes per content type?
I am looking for an function that returns all view modes per content type. I already tried to use `mobile_theme_entity_view_mode_alter` but this function will return all available view modes for a node entity. What I need are the available view modes per node type...

any suggestions?

# Answer
> 1 votes
You can use following function to get this information

```
$view_mode_settings = field_view_mode_settings($entity_type, $bundle);

```

example:

```
$view_mode_settings = field_view_mode_settings('node', 'article');

```

---
Tags: 7, entities
---


# Question
Title: How to patch module files with netbeans 7.4?
Trying to apply patch https://drupal.org/files/webform\_preview-435232\_1.patch to webform 7.x-3.19 via Netbeans tool - apply dif-patch. Downloaded this patch and put into drupal root directory. When applying patch to module files see the following: "The patch cannot be applied in the selected context". Module files are in Netbeans project and all paths are properly set. The code to which patch changes are applied exists in the target file, so what else problems can be?

Thanks!

# Answer
> 1 votes
If you duplicate the file in Netbeans that gets patched (this is important that you do this on the file, **NOT the project**) then right click on it under **Tools -\> Apply Diff Patch** then select your patch file. It should then say everything went as planned and allow you a summary.

You will need to repeat this for every file in the patch, or you can just apply it using Git or one of the other methods listed.

---
Tags: version-control
---


title: Theme settings doesn't work

text:
# Question
Title: Theme settings doesn't work
When i `dpm` that `$vars`, in `classes` key, there is no `r_style` class, whyyyy? I tried clear cache through `devel` module, but still the same, what i am doing wrong?

```
name = JH Template
core = 7.x
engine = phptemplate

styles[all][] = css/style.css
settings[bg_style] = 'r_style'

```

**theme-settings.php**

```
function jh_process_html(&$vars) {
    $vars['classes'] .= ' ' . theme_get_setting('bg_style');
    dpm($vars); // in classes string isn't r_style class
}

```

**EDIT:** the real question is, why `theme_get_setting('bg_style')` returns `NULL`

**SOLVED:** that jh\_process\_html function must be in template.php file, but i don't understand that drupal :D, because that function was executed even in if it was in theme-settings.php, but actually just sometimes and it causes some fails like that theme\_get\_setting returned null. I don't know why this happened, but it's really funny after so many years of development of drupal, this magic happened.

# Answer
> 1 votes
Try this...

```
function jh_preprocess_html(&$vars) {
$vars['classes_array'][] = theme_get_setting('bg_style');
}

```

You need to do this at an earlier stage of the processing.

---
Tags: theming, debugging
---


# Question
Title: Referring created users to 'admins' that created them
I know user can be given a permission to create other users. However, it doesn't seem that user table has any created\_by field to store the ID of the creator. Does it?

Is there a way not only to create a field like that (could do it through profiles management) but also to actually put creators ID in it with just using drupal base config or some module?

I simply need to be able to list users created by a particular 'admin'

# Answer
Add a field (e.g. created\_by) to the user profile by going to /admin/config/people/accounts/fields.

Then implement hook\_user\_insert to populate the field whenever a new user is added.

hook\_user\_insert is called after "*A user account was created.*" So both $edit-\>uid and $account-\>uid have the user id present.

If you changed any values in either of these objects you would need to call user\_save in order to save your changes.

An alternative to avoid calling user\_save again, just after the initial user object has been saved would be to use hook\_user\_presave that is called when *"A user account is about to be created or updated"*

The description of hook\_user\_presave goes on to say:

*This hook is primarily intended for modules that want to store properties in the serialized {users}.data column, which is automatically loaded whenever a user account object is loaded, modules may add to $edit\['data'\] in order to have their data serialized on save.*

So another option here would be instead of creating a new field (with a new table), this information could just be stored as a serialized array in the data column of the user table.

This would mean it would be slower to search for users created by a certain admin, but would would have less storage overheads.
> 0 votes

---
Tags: users
---


# Question
Title: I want to get all of the allowed values of a field
Let's say I have a field in Drupal called `resource_type`, and I wanted to get all allowed values. Is there any easy way to do this with a command, or do I have to do a database query? I'm not seeing anything specifically that would make this easy.

# Answer
For list type field you can use list\_allowed\_values function , You can also use field\_info\_field($field\_name) for more details about field.

```
$my_field = field_info_field('field_resource_type');
$allowed_values= list_allowed_values($my_field);

```
> 6 votes

---
Tags: 7, entities, database
---


# Question
Title: Auto-upload image feature with image browser module (e.g: Image picker)
I am using the imagepicker module for browsing the uploaded images, I have tried searching for the auto-upload integration for this module but still no luck.

I am searching for any alternative way if there for similar thing (mainly I require image browser to use the already uploaded images, and implementing the auto-upload functionality on it).

Any suggestion/recommendation would be appreciated.

# Answer
> 0 votes
Not sure it would help, because I don't know what you mean by "auto" uplaod, but here is the configuration I use:

FileField Sources module https://drupal.org/project/filefield\_sources

with IMCE module: https://drupal.org/project/imce

FileField source is pretty usefull to present user a set of upload options for a single image field.

---
Tags: 7, media
---


title: Drupal Blog Post templating

text:
# Question
Title: Drupal Blog Post templating
I would like to know how to add to a template file a blog post content rendering code so that all blogs will be displayed whenever that template is rendered.

# Answer
> 0 votes
You can copy node.tpl.php and rename it to node--blog.tpl.php for any blog specific changes. Find more about Drupal Template changes

# Answer
> 0 votes
I'm confused about your question. But if you are trying to add a block of "related posts" or something like that, you need to create a view first, and then add it to a specific region.

**Create a region from the .info file, e.g.:**

```
regions[REGION_NAME] = REGION NAME

```

**Then add this code to template.php file:**

```
function THEME_NAME_preprocess_node(&$variables, $hook)
{
  $variables['REGION_NAME'] = theme('blocks', 'REGION_NAME');
}

```

**Put this code into your node template file:**

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

```

For detailed information see this post: In DRUPAL7, how to add a region in a node.tpl.php(node--contenttype.tpl.php)?

---
Tags: 7, nodes
---


# Question
Title: Import Book content and structure from another drupal website
I am looking to implement an 'Open Government Guide' on my website.

Here is a link to one of the books that I would like to copy

My question is - How do I copy both the Book Content and Book Structure from another Drupal site that I do not have admin access to? Ideally I would be able to do this for all 50 States.

# Answer
If you haven't got admin access then you'll need to scrape the content. The module Example Web Scraper would be a good starting point.

I think this question on the ethics of web scraping may also be relevant.
> 1 votes

---
Tags: importing-exporting, nodes
---


# Question
Title: How to set nodes to be excluded from a block view based in the url of current node?
I have a view block listing nodes. Let's say I have the following nodes (it's urls)

```
node/first-node
node/second-node
node/third-node
node/fourth-node

```

Then I have the view block listing this 4 nodes. This block is shown in the **First sidebar** in all pages.

**What I need:** when the block is shown at the page **node/fourth-node**, I need to **arbitrarily** exclude from the view block from the following nodes.

```
   node/second-node
   node/third-node

```

I need to do this in a way so that then after I can do the same thing with other nodes.

I thought of adding a field to the node called: "Exclude from view block at:" to be filled with the paths (one per line) where the node will not be listed in the view block (similar to blocks settings). Then I will need to modify the view.

Is this a correct approach? If so, what do I have to do in the view?

# Answer
What you could do if you could use either Views Filters and use the view Filter options to set which URL's to exclude based on tokens.

You could also maybe use Views Rule to try and do something similar.

I think the Views Filters may be an easier option. But if you want to do your suggestion (add a field to the node) then what you can do is pretty much exactly what you said, you would add a filter to the view based upon the available tokens and field data.
> 2 votes

# Answer
I think this sentence is confusing

> I need to do this in a way so that then after I can do the same thing with other nodes and pages.

Pages and nodes could means different things, like if you create a "Page" with Views, how do you want to store the list of excluded node? You can't store it in a "field". Also, if there are different nodes displayed on the same page, which page are you going to exclude from your views? Both of them? The first one?

Well, with your description, I see two options:

1 - If you're only working with nodes, then you can create Node Reference field, instead of listing the URIs, so if the URIs changes, they will be updated. You can then access the "NID" that you want to exclude from the page loading the current node. Then you make a hook\_views\_query\_alter and add a filter to the listed node ids.

2 - You could create a mapping URI to URIs programmatically (it's also possible to store it as variable or somewhere else, but needs more coding). Then you need to run your view, get the results, check the URIs and exclude some based on your mapping.

I really suggest you don't do the second solution, because it's uggly :) You'll load a lot more nodes that you actually display. In the first solution, you only fetch the nodes you want. Also in the second solution, everytime your URIs changes, you need to change the mapping...

But the first solution might not match all your needs...

Hope this helps !
> 1 votes

---
Tags: nodes, blocks
---


# Question
Title: How to eliminate extra Drupal Logout Link
Hi, there, I am working with Organic Groups on an existing drupal 7 site. For some reason, there are three log out links. I checked with User Menu, which is not even enabled in this site. How can I find out why there are three log out links?

Any ideas? Thanks!

# Answer
Try using the Devel Themer (https://drupal.org/project/devel\_themer). That works kinda like a firebug/backtrace for themeing, and it should point you to where those links are coming from. Keep in mind Themer is a bit buggy, and can cause some issues, so you might want to switch it off when your done, but it should help you diagnose your problem.
> 0 votes

---
Tags: users
---


title: Create a menu under a menu?

text:
# Question
Title: Create a menu under a menu?
I am wondering if there is a way to have a menu under another menu in Drupal 7. Let's say I have a new menu called Blah and I want it to appear under the main menu item Top.

So I would end up with

```
Main Menu

|- Top
|---Blah Menu
|------ Blah Menu Item

```

# Answer
The obvious approach would be to have your main-menu built with sub-links.

If that doesn't work, you could:

edit your template to call the new menu right underneath the first.

or

add the new menu to the same block as your first menu (you may want to define new block areas for this)
> 0 votes

---
Tags: 7, routes
---


title: Adding comment count to view

text:
# Question
Title: Adding comment count to view
I want to be able to add a comment comment to a view , through comment.tpl.php as I have tried to add the comment counter through the admin area and it doesn't work

# Answer
Can you elaborate on the error?

I just did a quick test and was able to add comment count to a view:

Go to the views admin page , click fields, add

> Content: Comment count The number of comments a node has.
> 1 votes

---
Tags: views, theming, comments
---


# Question
Title: apachesolr search form block that points to search page
I have a custom search page configured in apachesolr\_search module which displays only products as results (bundle:product\_display). I want to create a simple block that contains an input field for a keyword and the submit button, and when the user submits the form it should direct to the specific search page.

I haven't found an easy way to do that. Other developers seem to modify the core block search form, but this does not help as I will have the same requirement in many pages over the same website (many apachesolr search blocks pointing to different apachesolr pages).

# Answer
There is an issue queue asking for such feature: https://drupal.org/node/326375

I also found a module (a sandbox) for Drupal7 to export for each search-page a search-block: https://drupal.org/sandbox/incrn8/1315802
> 2 votes

---
Tags: 7, search
---


# Question
Title: Allow block display on child nodes but not grandchildren
In a block configuration, I would like to show the block on /programs/\* but not on programs/\* /\*

I have seen a number of questions similar to mine. Block display using wildcard, non-greedy for example.

The recommendation from the above link to use drupal\_match\_path() makes the most sense to me. I have implemented the following,

```
    <?php
if (drupal_match_path(current_path(), "programs/*") && !arg(2)) {
  return TRUE;
}
?>

```

expecting the block to appear on /projects/name but not on /projects/name/grandchild-node. The block doesn't appear anywhere. Just to test the system, I tried this:

```
    <?php
if (drupal_match_path(current_path(), "programs/*") {
  return TRUE;
}
?>

```

and still the block doesn't show. I'm certain that I'm doing something wrong that is very basic. Any ideas?

# Answer
Hmm. Are you sure current\_path() is returning the alias? cause I don't think match\_path takes that in to consideration at all.

$path = current\_path(); $path\_alias = drupal\_lookup\_path('alias',$path);
> 0 votes

---
Tags: blocks
---


# Question
Title: Is it possible to use ajax inside the html output of a computed field?
I tried making a simple computed field that outputs some html that can be latter modified with Ajax. If we consider a typical hello world example, the computed field output would be a link saying 'say hello' and when you click on it the AJAX adds the text 'hello world' in the div below the link. This is based on a javascript/ajax example inside 'Drupal 7 Module Development' by Matt Butcher. It works inside a normal page, but inside a computed field it gives an error.

Here is the code for my computed field. It just creates a link which is ajax enabled and a second div where ajax content will be inserted.

```
drupal_add_js('misc/ajax.js');
$link = l(t('Say Hello'), 'hello_world_link_callback/ajax/', array(
           'attributes' => array('class' => array('use-ajax'))));
$output = '<div>' . $link . '</div><div id="saying-hello"></div>';
$entity_field[0]['value'] = $output;

```

Implementation of hook\_menu() to create the AJAX callback function:

```
$items['hello_world_link_callback'] = array(
    'page callback' => 'hello_world_link_response',
    'access callback' => 'user_access',
    'access arguments' => array('access content'),
);

```

Here is my callback function:

```
function hello_world_link_response($type = 'ajax') {
    if ($type == 'ajax') {
        $output = t("Hello World!");
        $commands = array();
        $commands[] = ajax_command_append('#saying-hello', $output);
        $page = array('#type' => 'ajax', '#commands' => $commands);
        ajax_deliver($page);
    }
    else {
        return t("Hello World in a new page.");
    }
}

```

When I click the link it crashes to a white screen with this text:

\[{"command":"settings","settings":{"basePath":"/drupal/","pathPrefix":"","ajaxPageState":{"theme":"bartik","theme\_token":"fN8xkldpLQAwubNZ1n0BzdQPnF577BDw6sfuzoVrcmw"},"overlay":{"paths":{"admin":"node/\*/maestro\nnode/add/\*/maestro/\*\nnode/\*/edit/maestro/edit/\*\nmaestro/trace/\*/\*/\*\nnode/\*/edit\nnode/\*/delete\nnode/\*/revisions\nnode/\*/revisions/\*/revert\nnode/\*/revisions/\*/delete\nnode/add\nnode/add/\*\noverlay/dismiss-message\nuser/\*/shortcuts\nadmin\nadmin/\*\nbatch\ntaxonomy/term/\*/edit\nuser/\*/cancel\nuser/\*/edit\nuser/\*/edit/\*\ndevel/\*\nnode/\*/devel\nnode/\*/devel/\*\ncomment/\*/devel\ncomment/\*/devel/\*\nuser/\*/devel\nuser/\*/devel/\*\ntaxonomy/term/\*/devel\ntaxonomy/term/\*/devel/\*","non\_admin":"admin/structure/block/demo/\*\nadmin/reports/status/php"},"pathPrefixes":\[\],"ajaxCallback":"overlay-ajax"}},"merge":true},{"command":"insert","method":null,"selector":null,"data":"","settings":null},{"command":"insert","method":"prepend","selector":null,"data":"","settings":null}\]

Any ideas?

# **Updated based on comments from tenken**

I've altered hook\_menu to be a callback only and set the delivery callback to be an ajax response. I've also split the hook\_menu into items for the cases with and without ajax. So the hook\_menus now look like this:

```
$items['hello_world_link_callback/nojs'] = array(
    'page callback' => 'hello_world_link_response',
    'access callback' => TRUE,
    'access arguments' => TRUE,
    'type' => MENU_CALLBACK,
    'page arguments' => array(1),
);
$items['hello_world_link_callback/ajax'] = array(
    'page callback' => 'hello_world_link_response',
    'access callback' => TRUE,
    'access arguments' => TRUE,
    'type' => MENU_CALLBACK,
    'delivery callback' => 'ajax_deliver',
    'page arguments' => array(1),
);

```

The callback function is unchanged from above with the exception that it now returns the AJAX commands, rather than calling 'ajax\_deliver'. So it returns:

```
return array('#type' => 'ajax', '#ajax' => $commands);

```

This code is now working for me, so it had nothing to do with the fact that it was a computed field. This code is also covered here.

# Answer
> 0 votes
Well, it's not *Crashing* with a white screen. You are using `ajax_deliver` which returns the content of your response as plain text and stops further page rendering.

A *Crash* would be a WSOD and no output. Check your `hook_menu` definition and be sure its setup as a non-menu item ... just a callback. You do this by setting the `type` in the `$items` array. You may also want to set the `delivery callback` value to be an ajax response.

Lastly, your link goes to `hello_world_link_callback/ajax/`, but that is not the URL you have defined in your `hook_menu` function. It may be a best-fit match for Drupal on a lookup.... but I doubt it.

---
Tags: ajax, entities
---


# Question
Title: Does the 'field table' always hold the current value? Or is it only in newest revision?
As I understand it, the current value for every field can be found in corresponding data table (e. g. field\_data\_body) and the history of its changes in corresponding revision table (field\_revision\_body) with the value of newest revision being the same as the value in data table.

Is that, however, really true or do I have to (to get the current value) look into the newest revision (which id can be obtained from 'entity type' table (e. g. node table)). If that's the case then does the data table hold the first value or what?

In other words, when dealing with content in Drupal 7 directly (accessing database and not using Drupal functions (load\_entity, etc.)) is it safe to work only with 'data' tables and not caring about 'revision' ones?

//I'm almost sure the way I understand is right and everything seems to verify it, I'd still like to be totally sure.

# Answer
You are totally correct, the newest value is in the field\_data table, you can rely on that.

field\_revision just has a copy of the same data so that it knows about the revision immediately. I think it's just more hassle free to keep field\_revision completely up to date rather than being one step behind field\_data.
> 2 votes

---
Tags: entities, nodes
---


# Question
Title: Is it possible to write node migrations for D8 alpha/nightly yet?
If the migrate api in core is currently capable of doing simple d8-to-d8 migrations, where could I find documentation on how to do so?

This is more or less a learning exercise and I am only trying to migrate standard article nodes from one alpha version to the next.

# Answer
We haven't written Drupal 8 sources *yet* and they won't be written until Drupal 6 and Drupal 7 is done. It's not a priority. You could, of course, help with writing them :)
> 2 votes

---
Tags: 8, migrations
---


# Question
Title: 'Manage fields' and 'manage display' links not working for content types
I did an update of several modules (core included, from 7.xx to 7.26), a couple of weeks ago, and until now I had not tried to access content types.

Today I did, but while I can see the 'manage fields' and 'manage display' links, when I click on them I'm taken to the 'edit' page. Also, if you have admin\_menu installed and just hover on structure/content-type/custom-content-type, a menu with the available edit options appears, but in my case only 'delete' is there.

Searching around I see this is most commonly caused by the 'field ui' module being disabled, but I checked and it's in fact enabled. I disabled/re-enabled it but nothing happened.

Per this post, I also tried enabling all checkboxes at admin/config/administration/admin\_menu under the 'performance' tab, flushed caches, and still no result.

I did the site's update for a client, and still have a version of the site on localhost, where all menus work fine. I sent them all files/database so their hosting provider would upload the site and now this issue comes up. I have no access to the database, only the admin pages. What else could be the problem and how could I fix it?

Thank you in advance.

# Answer
> 0 votes
Solved. I could get access via FTP and found out there were 2 missing files from the server. After uploading them the problem is fixed.

---
Tags: 7, nodes
---


# Question
Title: Aggregating CSS breaks with Internet Explorer
Selecting the option to aggregate and compress css files breaks display in internet explorer 11. It displays fine with other browsers, or fine in ie11 if I deselect that option. The site in question is wowforfun.org

Thanks in advance.

Edit: Here's a part of the css as served to ie:

‹ µYér¤8þ?OÁŽ£#Ú³M•¶!öÇ\>Á\>ƒ T 1 F»Üï¾™:@ªÚîÙí—Ë:Ryç§Ô é%ÏxÝVTÒáÈENE²oÏAÇ+–§ü•ŠSÅß’’å9mÒ–wL2Þ$äzIÓ!krzNöq\<Þ¸Ä‚¾\*ÖÉ°“ïMÞÐtþ;d5)ÌhMDÁš$N\[’ç¬)ŸRÅ†#É^

Looks like it wasn't uncompressed at all.

Edit 2:

My .htaccess section related to compression:

```
<IfModule mod_headers.c>
# Serve gzip compressed CSS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.css $1\.css\.gz [QSA]

# Serve gzip compressed JS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.js $1\.js\.gz [QSA]

# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]

<FilesMatch "(\.js\.gz|\.css\.gz)$">
  # Serve correct encoding type.
  Header set Content-Encoding gzip
  # Force proxies to cache gzipped & non-gzipped css/js files separately.
  Header append Vary Accept-Encoding
</FilesMatch>

```

And here's the settings.php section:

```
# $conf['css_gzip_compression'] = FALSE;
# $conf['js_gzip_compression'] = FALSE;

```

I've tried those two lines both commented and uncommented, didn't make a difference.

# Answer
The Advanced CSS/JS Aggregation Module might make it work correctly. If not, the advagg validator sub module might help identify the CSS that is breaking in IE.
> 2 votes

---
Tags: theming
---


title: Permissions Administration Module

text:
# Question
Title: Permissions Administration Module
Is there a working module for Drupal 7 to restyle `admin/people/permissions/list` to add more usable controls? Some serious boons to building a large site with lots of permissions:

* Incremental search/filtering of shown permissions
* Add/Remove/Toggle all permissions for a role (globally, or per module — one column, or part of a column)
* Grant/Revoke/toggle a permission to all roles (one table row)
* Collapsible/tabbed groups

Something like Module Filter, but meant for permissions administration, would be ideal.

I've tried a couple of modules, but haven't had much luck with them. E.g. the stable version of Permission Select from 2009 (!) fails to do anything, while the development version at least adds its checkboxes (but clicking on them does nothing).

Short of writing my own module and/or hacking something in jQuery, is there some understated gem of a module out there I should be using for this?

# Answer
See the Fast Permissions Administration module; it is like the Module Filter module, but for permissions.

> This module is here to alleviate frustration when trying to manage permissions in Drupal. By providing a better permissions interface hopefully a few innocent keyboards and mice can be saved.

You can filter on the module name with @module, or permission@module:

> Module filtering:
> You can also filter on the module a permission belongs to using the @ symbol: permission@module.
>
> For example, if you want to show only permissions that contain the word admin for the comment module you would enter: admin@comment.
> 8 votes

# Answer
I've been looking for this myself, and I've not been able to find anything (including the time to start writing a solution myself).

It might be worth looking through the source of Module Filter to see if there's anything that you can port or contacting the maintainer of Filter Perms to see if they'd be willing to share maintainership of a stable D7 version.
> 3 votes

# Answer
Today I've upgraded a few modules on my Drupal 7 site (views, ctools, ...), as well as Drupal's core. I was pleasently surprized to see that the permissions administration interface have been highly redesigned:

1. Groups are now initially collapsed.
2. The Table Header is always visible even if you scroll down.

This largely solved my issue.

The Fast Permissions Administration module didn't work for me - the javascript on the page was endlessly loading. The Filter Perms module works greatly - it's the best option with the highest usability.
> 2 votes

# Answer
I tried various solutions as below.

* **Fast Permissions Administration** module
* collapsing modules via the **admin menu** module
* the new permissions-filtering functionality provided by the **module filter**

I can confirm that the Filter permissions is the best and recently probably the only solution with enhances performance of the `admin/people/permissions` page (which is the crucial feature).

> This module provides filters at the top of the Permissions page for easier management when your site has a large amount of roles and/or permissions. The module was originally created because the excessive amount of checkboxes combined with some jquery activity was causing "Unresponsive Script" js errors on every load and save of the permissions page.
> 0 votes

# Answer
Check out https://drupal.org/project/permission\_select for these:

> Add/Remove/Toggle all permissions for a role (globally, or per module — one column, or part of a column) Grant/Revoke/toggle a permission to all roles (one table row)
> 0 votes

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


# Question
Title: CDN module enabling "Far Future expiration" breaks whole site theme drupal 7
CDN module Version: 7.x-2.6 component -- Origin Pull mode — Far Future expiration

I am using CDN module on drupal 7.22. We are using custom theme where adaptive theme is as base theme for all other users and "seven" theme for admin. As soon as i check the "Far Future expiration" and save, whole site theme is breaking except admin theme.

And without checking "Far Future expiration" Iam facing http://drupal.org/node/1993600 issue.

# Answer
> 1 votes
These modules might help you out (quotes added here are from their project pages):

* Advanced CSS/JS Aggregation:

> + On demand generation of CSS/JS Aggregates. If the file doesn't exist it will be generated on demand.
>     + Stampede protection for CSS and JS aggregation. Uses locking so multiple requests for the same thing will result in only one thread doing the work.
>     + Fully cached CSS/JS assets allow for zero file I/O if the Aggregated file already exists. Results in better page generation performance.
>     + Can add JS to any region of the theme & have it work and be aggregated.
>     + Combine CSS files by using media queries.
>     + Prevent more than 4095 CSS selectors in an aggregated CSS file (IE 6-9 limitation).
>     + ...
* Imageinfo Cache:

> ... will generate image styles right after an image is uploaded and also on entity save. This will help with front end performance as the needed image style will already have been generated; thus the end user doesn't have to wait for the image to be generated. This can also mitigate some issues with image style generation if your CDN is configured incorrectly as the images will be generated without the request going through the CDN.

---
Tags: media, theming, cdn
---


# Question
Title: Why won't JS fire on ubercart checkout page and how do I fix?
I need some custom JS (jQuery to be precise) to run on ubercart's `/cart/checkout` page. I turned off JS optimization and tried adding it to several different files that are already loading and the JS never fires. It is in the page as if I view-source I can search and find it. I did put $(document).ready(... so it should be waiting for the page to load before running. If I run the same JS from the console of firefox or chrome it does exactly what it's supposed to do. The JS files are all loaded with `drupal_add_js()`.

My only solution at this point is the make a block that only contains that JS and only shows on that page, which it not an optimum solution, but will probably work. Anything else I'm missing on this though?

# Answer
Only solution I came up with for this was to create a `block`, assign a `blocktheme` and in the `tpl.php` file put the `JS`. Then assign the block to only show on that page. Bit of a work-around, but it did work.
> 0 votes

---
Tags: ubercart, javascript
---


# Question
Title: Show parent child relationship of taxonomy term in view
I am looking for a way to display the list of taxonomy terms in a view indenting the child tax terms. I need to be able to see all Taxonomy terms including the ones that do not have children terms. any ideas?

```
Domain 1
    Sub-domain 1
    Sub-domain 2
Domain 2
    Sub-domain3
    Sub-domain4
Domain 3
Domain 4

```

I tried to follow the suggested solutions but they did not work out for me. The first one in the link is asking you to provide a parent taxonomy term to filter by. I want to get the complete list. the Second one only provide the Taxonomy terms that have a parent child relationship. I need to see all taxonomy terms even if they don't have children. Here is the screenshot of my view setup, I followed the exact steps outlined by louieliu. As you can see it only shows Environment with subchildren of Soil and Weather but does not show the other Domains without subchildren.

# Answer
You can also try Views tree module.

Project page says

> This module provides a tree-based style plugin for Views. It is equivalent to the tree-based style template from Views 1.
>
> It is based off of the list style. Although it generates a nested view, there is still only a single query run for the view making it quite performant.
>
> Compatibility
>
> This module has been tested and used with the following relationship-oriented modules:
>
> Taxonomy (in core) - parent/child relationships
> 1 votes

---
Tags: taxonomy-terms
---


# Question
Title: What is causing pathauto to generate unwanted text in these URLs?
I have configured `pathauto` to generate URLs for content according to this pattern `article/[node:author]/[current-page:title]-[node:nid]`. `article` is a literal input, to reflect the content type description `Site Article` not token generated.

The content type description is `Site Article`

The node title is: `this is a title`

The author's name is: `nodecreator`

The node id is: `101`

When I generate the URL alias using the pattern `article/[nodecreator]/[current-page:title]-[node:nid]`, the resulting path 's `article/nodecreator/edit-site-article-this-is-a-title-101`. The last section on the URL shouldn't be prefixed by `edit-site-article`.

What could be the cause?

# Answer
Pathauto creates the alias when a node is being added or edited, so, if you are using `current-page:title` it will include the title that Drupal generates for that page, eg, in your case, "Edit Site Article: This is a title", and not just the title of the node. So I would look into using `node:title` instead so as to remove any of those potential prefixings.
> 1 votes

---
Tags: path-aliases
---


# Question
Title: Trying to keep facets visible even when the terms restrict facets
I believe the setting I am looking for is minimum facet count, so that I can set it to 0.

I'm going based on this:

https://drupal.org/node/1669600#comment-6190924

I don't have search API installed, however I do have Apache Solr installed.

When I'm searching for something, say tech, whenever there are results that don't have that keyword, the facets are disappearing - the client doesn't want the facets to disappear.

I tried to disable this disappearance in the template.php above, but it didn't work.

How do I keep facets visible in Apache Solr even when there are 0 results?

# Answer
> How do I keep facets visible in Apache Solr even when there are 0 results?

As I know, it's not possible. You can make separate query for display facets, but they cannot be displayed if solr return no data.
> 0 votes

---
Tags: search
---


title: How to create link libraries?

text:
# Question
Title: How to create link libraries?
Is there a way around to build link library repository on a drupal site, so that there can be one place to edit the links and changes will reflect in the instances used else where (like body field of a content type)

Any starting pointers?

# Answer
I can't answer that exact question, but to solve that problem we typically use the Linkit module.

This will add an additional button to the WYSIWYG for creating links. When you click it, you get a popup which lets you choose a link (somewhat similar to the entity reference autocomplete widget), and also set link options.

It will then build a link in the markup using a token. When the page is rendered, the token gets replaced with the path alias for what you selected. So, if the path for a node changes, the token replacement will take care of fixing everything.
> 2 votes

# Answer
Found one more interesting module as Word Link.
> 0 votes

---
Tags: navigation
---


# Question
Title: How to redirect views of entity types (bean) for user roles?
RabbitHole does not provide this functionality for bean blocks and Entity Bundle Redirect does not seem to work. There is a user role which may edit bean blocks but I want to prevent them from viewing the bean block itself, it rather gets included via php/ views on different nodes.

How can you do that?

EDIT

this is the way the bean blocks are printed

```
<?php
    $bean_left = bean_load(2);
    print render(bean_view($bean_left));
?>

```

# Answer
From quick view of RabbitHole I would suspect that it doesnt support blocks. One way to prevent this could be to use hook\_block\_view\_alter and drop the data when comparing the url. Something like

```
function MYMODULE_block_view_alter(&$data, $block) {
  // Remove the data if some page view, possibly
  // this would also disable the data on bean/123/delete... :/
  // mayby instead dpm($block) with devel for better targeting?
  if (arg(0)=='bean' && arg(2) !='edit') {
    unset($data['content']);
    //or redirect
    //drupal_goto('somepage');
  }
}

```
> 0 votes

# Answer
The bean module provides this out of the box (if I understand your question properly).

If you make sure the user doesn't have the 'View Bean page' permission (go to admin/people/permissions) then they will still be able to edit the bean blocks (provided they have the correct editing permission) but they won't be able to use the beam pages (they will get access denied errors).

Then you can just put the beans where you want around the site and users can see them there. Users who have permission can edit the beans via contextual links if you have that module enabled (it's a drupal core module) and they have permissions to use contextual links.

There isn't really any need to have a redirect in my opinion although you could still pursue the redirect if you prefer that.
> 0 votes

---
Tags: users, redirection, entities, blocks
---


# Question
Title: Index Data from External Database for Search - Views
I have a Drupal 7 view which obtains data from an external database and displays it on the page. I would like to index this external data (read through Views) so that the resulting items can be searched for using Drupal Search. How do I go about doing this?

# Answer
Like Michiel said Solr is a good option but is complicated to set up.

Another option is to implement a Google search server that can then be integrated with Drupal using the Google Search Appliance module. This is a paid solution but easier to setup.
> 0 votes

---
Tags: views, search
---


title: Output filter for dates

text:
# Question
Title: Output filter for dates
How can I change the output of dates in a long text field based on the locale?

I was looking for a module that might work with WYSIWYG to denote a date within a text field.

My goal was to allow articles to be viewed in several locales that use different date formats, without having to create separate versions of the articles. All of the article content is the same except for references to dates.

# Answer
> 0 votes
Use the Drupal date module.

Users can set their timezone and date will automatically be converted to the timezone of current user (you are presented with options about this when creating the field).

---
Tags: 7, datetime, wysiwyg
---


title: Change rendered content in template

text:
# Question
Title: Change rendered content in template
I created a custom node template in order to change what fields are generated.

```
  <?php
        print render($content['field_pdf']);

        ?>

```

The above php code renders the following html:

```
<div class="field field-name-field-pdf field-type-file field-label-hidden field-wrapper"><span class="file"><img class="file-icon" alt="" title="application/pdf" src="/modules/file/icons/application-pdf.png"> <a href="/sites/default/files/testmanual.pdf" type="application/pdf; length=1607045">lindamanual.pdf</a></span></div>

```

The problem is I only want the href to be rendered (not the image and the outer div). How can I do this?

# Answer
> 1 votes
In the display settings of your field, you can choose to display the "Rendered Content" (what you actually have) or only the URL of the file ("URL to file"). This should only give you the file URL.

# Answer
> 1 votes
Assuming that you wish to override the default rendered content, you have some options.

One option is to use a `field--\[type|name\[--content-type\]|content-type\].tpl.php` file to override the theming of the particular field. Depending on the field type, you might want to take a look at the original `field.tpl.php` file in the field's module core or API documentation.

Another option is to take a glimpse of the field's properties with `debug($content['field_pdf']);` and use the appropriate code in place of the old `render()` to printout the field's content, essentially ignoring the field's theming function (which I wouldn't recommend because you have to build several variables yourself, for example the path to the filename).

---
Tags: nodes, theming, views
---


# Question
Title: Autocomplete ahah combo is not working in Drupal 6
I am using Drupal 6.
I have a form which uses autocomplete and ahah in form. It works fine in Firefox but not in Chrome. if its just ahah or autocomplete it works fine but the combo seems to be not working in Chrome. :(
Below is my form

```
$form['my_fieldset']['my_field'] = array(
      '#type' => 'textfield',
      '#title' => t('Something'),
      '#description' => $client_exists_text,
      '#autocomplete_path' => 'autocomplete/my_field',
      '#ahah' => array(
         'event' => 'change',
         'path' => ahah_helper_path(array('details_fields')),
         'wrapper' => 'details-fields',
         'method' => 'replace',
         'progress' => 'throbber',
      ),
      '#default_value' => ($form_state['values']['my_field']) ? ($form_state['values']['my_field']) : $client_data['my_field'],

```

Has anyone come accross such issue, please help! Thanks in advance!

# Answer
> 0 votes
you need delete 'event' =\> 'change' or change event value

---
Tags: forms, ajax
---


# Question
Title: How do I set the node title as breadcrumb?
How can I set the breadcrumbs for a node? I have a node which is in the menu and also the head menu with the id 2 which contains the imprint.

If I open my page `http://my.page.tld/imprint` (I'm using the SEO stuff) I can see my text with the correct title but with no useful breadcrumbs. It's *Home* instead of *Home » Imprint*.

How can I fix that?

# Answer
> 7 votes
You can use Menu Breadcrumb. It allows you to Append the page title to the breadcrumb (either as a clickable url or not) . Or you can edit your theme's page.tpl.php - simply add $title after the $breadcrumb variable.

There are also a ton of other breadcrumb modules if you want to get fancy:

1. Crumbs
2. Custom Breadcrumbs
3. Hansel

See an older comparison chart.

# Answer
> 4 votes
A simple custom solution would be to add a function like this in your theme's `template.php` file:

```
function MYTHEME_preprocess_node(&$variables) {
  //Retrieve current breadcrumb
  $breadcrumbs = drupal_get_breadcrumb();
  //Add the title without link
  $breadcrumbs[] = $variables['node']->title;
  //OR add the title with a link
  $breadcrumbs[] = l($variables['node']->title, 'node/'.$variables['node']->nid);

  //Set the new breadcrumb
  drupal_set_breadcrumb($breadcrumbs);
}

```

# Answer
> 3 votes
Breadcrumbs do not include the name of the current page. The thought behind this is that you are on the page and do not need a link to get there. Breadcrumbs are a link menu that is always one step back, so you can back up quickly.

# Answer
> 0 votes
Put this code in template.php (and change MYTHEME to your theme name)

```
function MYTHEME_breadcrumb($variables) {
  $variables['breadcrumb'][] = drupal_get_title();
  return theme_breadcrumb($variables);
}

```

---
Tags: 7, breadcrumbs
---


# Question
Title: Display edit and delete button using content view
i am using blog entry content type and i am displaying blog entry using content view .But their is no any edit and delete button how to add it while using content.Edit and delete button is working only when we use field view.Any idea how to make edit and delete button working when using content view

# Answer
> 1 votes
Node Full Content is displayed using node.tpl.php. If you would like to override tpl you can copy node.tpl.php and rename it to node--blog.tpl.php in your theme templates folder. For more information refer Drupal 7 Template Suggestions.

You can add Edit and Delete buttons using below code to the overrided template..

```
<?php
   if (drupal_valid_path('node/' . $node->nid . '/edit')) {
     print l('Edit', 'node/' . $node->nid . '/edit');
   }
?>
<?php
   if (drupal_valid_path('node/' . $node->nid . '/delete')) {
     print l('Delete', 'node/' . $node->nid . '/delete');
   }
?>

```

---
Tags: views
---


# Question
Title: SQL queries in theme functions - is it a bad practise?
I know, that calling SQL queries in template files is bad practise. But is it bad practise also for theme functions?

For example when my form is rendering with my custom theme function:

```
<?php
$form['#theme'] = '_my_custom_theme_form_method';
?>

```

My custom method \*_my\_custom\_theme\_form\_method\* is placed in .module file. Is it the same bad practise as it is for template files?

Is it any serious performance issue, calling SQL queries form theme method?

thanks Tomas

# Answer
> 1 votes
Any theming function only format variables passed inside them to specified format. If you want to get some additional variables from database you should use `hook_preprocess_HOOK` https://api.drupal.org/api/drupal/modules!system!theme.api.php/function/hook\_preprocess\_HOOK/7.

So, in your case you should implement:

* hook\_theme() in module to register new theme-function;
* hook\_form\_alter() in module to modify form theme (as showed in your example);
* template\_preprocess\_HOOK() in module, to get aditional info from database;
* \[theme\]\_hook() in template.php of theme to format variables as you wish.

There is no any performance issues, it is "must do" practice. If you have version control system, and you need to change some output, it's no required to change module files.

---
Tags: 7, theming, database
---


# Question
Title: I can't translate description of front page in my multilingual site
I have a multilingual drupal 7 site.

I want to translate my description metatag of my English frontpage version of my site. Any other page show ok in site Greek and English.

The problem is it only show the Greek version.

I have i18n and metatag module.

What i have try is to navigate to en/admin/config/search/metatags/context and add my English url (www.mysite.gr/en) so i can add manually the description there. But it didn't worked.

# Answer
> 4 votes
All major translation issues for metatag module are now fixed (see: https://drupal.org/node/1282620, https://drupal.org/node/1688286)

All you have to do is:

1. Go to metatag settings page: /admin/config/search/metatags
2. Override your frontpage (/admin/config/search/metatags/config/global:frontpage) and write your infos in default language
3. Save your modifications
4. Go to your homepage
5. Flush site cache
6. Switch site language for every other language (this way all strings can be generated for translations)
7. Go to /admin/config/regional/translate/translate and search (in default language) all strings you have to translate and translate them

This should be enough.

If you are using metatag submodules like Context be aware that translations issues are not still full fixed (see: https://drupal.org/node/1986032)

Hope this help

---
Tags: i18n-l10n, meta-tags
---


title: How to update image title and alt tags

text:
# Question
Title: How to update image title and alt tags
I am using Drupal Commerce. Images are in product entities. I have imported my products and nodes with feeds, but now I am working on SEO of my website, I have realised that my 'title' and 'alt' tags are empty. I am looking for a process to update these tags with the image title :

This issue sounds common and trivial but I can't find a solution. Am I missing something ? Is there an other way to automatically replace title and alt image tags with image field title ?

Thank you for your help

# Answer
The way I deal with this issue is to use the ImageField Tokens module:

> The ImageField Tokens module extends the default functionality of Image fields adding the ability to specify default values and use node tokens in the Alt and Title text.

The module Token is required. After you install and enable the modules, you configure its settings in the field properties for each individual content type.
> 2 votes

---
Tags: media, feeds, importing-exporting, views
---


# Question
Title: Does using modules Metatags and Metatags Quick together cause SEO problems?
I am checking the SEO of my Drupal 7 site, where I installed the Metatag and the Metatag Quick modules.

Does using both the modules together on a site cause SEO problems?

# Answer
You have to be careful so that the output of each module won't overlap. For instance, the same meta should not be present twice and even worse with even slightly different values. I am not aware of the exact SEO penalty depending on the engine, but it is common sense.

You can examine the output of the modules for the `<head>` tag with the browser's inspector, or Firebug.
> 1 votes

---
Tags: meta-tags
---


# Question
Title: Facebook "like" button fetch wrong data on views
I am using Drupal 7 with views and Addthis module for facebook "like" and "share" .

I have add a "like" field to views, so every piece of content has a "like" button. when a user click on the "Like" button, facebook fetch the wrong data. It can be the picture of different content (e.g. content from the sidebar), it can the user picture instead of the content picture, etc.

How can I fix this?
Should I use different social module that is more suitable for working with views?

**Update (2/28/2014):<br>** I spoke with addthis support, and they say I need to add the open-graph for the image. The problem is that I have many images in all the views.
Anyway, I also have the metatag module installed and inside I can define open-graph. When I atried to define the Open Graph image as the image token (\[node:field\_image\]) of the node - nothing change, meaning it doesn't work. When I tried to add image token to the "views open-graph" - I didn't find one.
Can someone help me define image open graph to the views output?

# Answer
Read about og (open-graph) meta tags. As I know, metatag module supports this kind of meta-tags.
> 0 votes

---
Tags: views, social-network
---


# Question
Title: How to set the facet block title to the currently applied filter?
I have a faceted block for the taxonomy reference field.

The faceted block displays the parent terms. When I click on a term in the faceted block then its childs displays in the faceted block. It is fine but the facet block title should be changed to its parent term name.

How will I do this?

# Answer
I'm not sure about faceted, bacause i've never used it before. But if page are reloads on click you can use `hook_block_view_alter` hook the common workflow of using this - get param from url and replace title depends on it.

If page doesn't reloads you can use ajax command, or something similar to achieve what's you need.
> 1 votes

---
Tags: 7, search
---


# Question
Title: Administer Users permission too vague. How can I restrict functionality for this permission?
Is there a way to allow some admin users (with administer role) to create other users but limit their access to 'people' related admin area? It seems there's only one option under permissions - Administer users - which seems to dictate either full package (create all different profile2 users, access admin people list view etc) or nothing.

I have a 'sales person' role on the system. This user has to be able to create other profile2 based users but not to access user configuration or even general listing (not to mention that depending on number of profile2 profiles, multiple Add People links appear)

# Answer
I believe the Role Delegation module does what you need to do. Here is a quote about it (from the module's project page):

> ... allows site administrators to grant some roles the authority to assign selected roles to users, without them needing the administer permissions permission.
>
> For each role, Role Delegation provides a new assign ROLE role permission to allow the assignment of that role.
>
> The module also adds an assign all roles permission. Enabling this permission for a role is a convenient way to allow the assignment of any other role without having to check all the assign ROLE role permissions in the Permissions page.
>
> If an administrator has the administer users permission, a role assignment widget gets displayed in the account creation or editing form, and bulk add/remove role operations become available on the user administration page. Otherwise, if s/he has at least the access user profiles permission, the module adds its own Roles tab to the user profile so that roles can be assigned.
> 0 votes

---
Tags: users
---


title: Problem with multiple domains

text:
# Question
Title: Problem with multiple domains
First of all, let me apologize in advance as this may be a poorly worded question. My knowledge of Drupal is limited so I'm not even sure of the exact area where my problem is. I'm looking for pointers in the right direction so I can do more research on my own for an answer.

**The Original Situation**

I have two domains - let's call them `example.com` and `example.net`. The site was originally built for `example.net` and it is hosted at BlueHost with the following folder structure:

```
/root
    /public_html
        /drupal
            ... standard Drupal folders
            /sites
                /all (this is where all my site files are)

```

So basically, the entire Drupal installation is in a subdirectory of `public_html`. I can access URL's such as `http://example.net/contact` with no problem. So far, so good.

**The Wrinkle**

Where it starts to get complicated is when we bought `example.com`. As the primary domain, it points towards `/root/public_html`. So, I dusted off my Apache skills and fashioned an **.htaccess** file to redirect .com to .net, like so:

```
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/drupal/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /rings/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ drupal/index.php [L]

```

**The Problem**

Now, if I go to `http://example.com/contact`, it does come up with a Drupal page, so I know that the rewrite rules are working. However, I get a page that says that `The requested page "/contact" could not be found.`

I want users to be able to use either domain. That is, `http://example.com/contact` and `http://example.net/contact` should go to the same page. So this is where I'm stuck. I'm not even sure where the general area of the problem is. Do I need to set up a multi-site configuration? That doesn't sound right because I'm only running one site. Is it something to do with the domain access module? That sounds more like something to run multiple sites of one Drupal installation. Any pointers at all will be greatly appreciated. Thanks in advance!

# Answer
If you're on Cpanel just point both domains to same siteroot folder.

Otherwise create a symbolic link of folder2 to folder1 where folder1 and folder2 and siteroots of each domain.
> 0 votes

# Answer
Your rewrite may be overly complicated. Try this:

```
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.net$ [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [R=301,L]

```

This should happen before any of the Drupal code in .htaccess

Ideally, this should go in your apache config file.
> 0 votes

---
Tags: 7, multi-sites, domain-access
---


title: Getting data into a template

text:
# Question
Title: Getting data into a template
How do I add data into a table into my node--course.tpl.php?

I would like to mimic the table on this page where it has course ID and info: http://cie.austin.utexas.edu/uex-cm/courses/acc-310f-foundations-accounting-online

to look like this: http://uex.webhost.utexas.edu/coursedetails.cfm?OutID=3040

Should I use a view or a block?

# Answer
Install DisplaySuite (DS). Views are for "lists of things" and Blocks are for rendering various pieces of content on parts of a page -- not necessarily fields of a content type.

I would also recommend FieldGroup and FieldGroupTable which are 3rd party additions to DS. FieldGroup allows you to *group* fields in your content type into various visual outputs -- out of the box:

> * Fieldsets
> * Horizontal tabs
> * Vertical tabs
> * Accordions
> * Divs
> * Multipage steps: Note: This is only client side.
> * HTML5 elements
> * Html elements

By also having field\_group\_table installed you may group the desired fields of your content type into a small table on the page as well. The field\_group\_table page says:

> This module extends the Field Group module and provides a "Table" group format, which renders the fields it contains in a table. The first column of the table contains the field labels and the second column contains the rendered fields.

With DS you should be able to create a layout of you content type as desired in your 2nd picture. Maybe you may need to tweak the CSS for the table output, I'm not sure.

There are many online video demos for DS online, and there are Documentation pages linked in the Resources sidebar for each of these modules.
> 0 votes

# Answer
For the first image if its content type you can create a view of that content type with fields as shown in the table.
> 0 votes

---
Tags: nodes
---