# Question
Title: When removing a file it still is present on the machine
When deleting a node the files attached to that node are removed from the server just fine. However if I edit the node and remove the file there, it stays on the server even after deleting the node.

Is this normal? Is there a way to fix that?

# Answer
> 3 votes
Permanent files have a status `FILE_STATUS_PERMANENT`.

> Indicates that the file is permanent and should not be deleted.
>
> Temporary files older than `DRUPAL_MAXIMUM_TEMP_FILE_AGE` will be removed during cron runs, but permanent files will not be removed during the file garbage collection process.

When you remove a file from a node, the file\_managed record may simply be marked as `status = 0` or anything other than `FILE_PERMANENT`, in which case, it's deleted during `system_cron` (if no entry in the `file_usage` table).

Basically, if you have cron running, it should be fine.

---
Tags: nodes, files
---


# Question
Title: Fatal error: Call to a member function raw() on a non-object in
I am getting this error

> Fatal error: Call to a member function raw() on a non-object in one of my custom modules.

Following is my function:

```
function _gocoop_services_get_app_instance($wrapper)
{
  $instance_id = $wrapper->field_seller->field_application_instance->raw();
  if (!$instance_id)
  {
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'application_instance')
        ->entityCondition('bundle', 'application_instance')
        ->fieldCondition('field_internal', 'value', 1);
    $result = $query->execute();
    if ($result['application_instance'])
    {
      $instance_id = reset(array_keys($result['application_instance']));
    }
  }
  return $instance_id;
}

```

Have used the above function at couple of places like shown below:

```
$wrapper = entity_metadata_wrapper('commerce_product', $entity);
$instance_id = _gocoop_services_get_app_instance($wrapper);

```

Can anyone help me whats wrong as this has occurred all of a sudden.

# Answer
You could try something like this instead, checking if the field value is set first and catching the exception.

```
function _gocoop_services_get_app_instance($wrapper) {
  $instance_id = FALSE;
  try {
    // Check if wrapper field set first
    if (isset($wrapper->field_seller) && isset($wrapper->field_seller->field_application_instance)) {
      $instance_id = $wrapper->field_seller->field_application_instance->raw();
    }
    if (!$instance_id) {
      $query = new EntityFieldQuery();
      $query->entityCondition('entity_type', 'application_instance')
          ->entityCondition('bundle', 'application_instance')
          ->fieldCondition('field_internal', 'value', 1);
      $result = $query->execute();
      if ($result['application_instance']) {
        $instance_id = reset(array_keys($result['application_instance']));
      }
    }
  } catch (EntityMetadataWrapperException $e) {
    watchdog_exception('gocoop', $e);
  }
  return $instance_id;
}

```

You might also want to use a static cache for `$instance_id`, but that would need to vary based on your `$wrapper` id value.
> 0 votes

---
Tags: entities
---


# Question
Title: What is the D6 equivalent of D7's hook_filter_info?
I am backporting a module from D7 to D6, and I am not familiar with Drupal 6.

The following three lines runs a chunk of text in the variable `$input` through the **Markdown filter** to produce `$output`.

```
$filters = module_invoke('markdown', 'filter_info');
$info = $filters['filter_markdown'];
$output = $info['process callback']($input, NULL);

```

Provided the **Markdown filter** module is enabled, it works fine on Drupal 7. On D6, the call to `module_invoke` returns NULL (so the rest fails).

The cause is obvious, `hook_filter_info` did not exist for Drupal 6, so this is invoking a non-existing hook.

It looks like `hook_filter` is supposed to do the same thing in D6, so I try:

```
$filters = module_invoke('markdown', 'filter', 'list');

```

This results in the following array `filters[0]['Markdown']`. I don't know how this helps, or - if it is the right start - where to proceed.

Can anyone tell me how to run a chunk of text through a text filter in Drupal 6?

# Answer
> 1 votes
In Drupal 6, filter modules just implement `hook_filter()`. In particular, to process text from a filter, you should use code similar to the following one.

```
$result = module_invoke('markdown', 'filter', 'prepare', 0, -1, $input);
$result = module_invoke('markdown', 'filter', 'process', 0, -1, $result);

```

I assume the delta for the input filter is 0, which means selecting the first input filter implemented by the module.
The first call to `module_invoke()` could be not necessary, but most input filter prepare the text that is going to be preprocessed, mostly to avoid conflicts with other filters, including the ones implemented by Drupal core. In fact, `check_markup()` uses the following code.

```
// Give filters the chance to escape HTML-like data such as code or formulas.
foreach ($filters as $filter) {
  $text = module_invoke($filter->module, 'filter', 'prepare', $filter->delta, $format, $text, $cache_id);
}

// Perform filtering.
foreach ($filters as $filter) {
  $text = module_invoke($filter->module, 'filter', 'process', $filter->delta, $format, $text, $cache_id);
}

```

---
Tags: 6, input-formats
---


# Question
Title: how to create a taxonomy Views combining terms from 2 different vocabulary
I have content types tagged from two different vocabularies (destination and category).

i.e. destination (main vocabulary, content must be tagged with of one of them)
\- dest1
\- dest2
\- dest3
\- dest4

category (content is tagged with at least 1 but could be more)
\- cat1
-- subcat1.1
-- subcat1.2
\- cat2
-- subcat2.1
-- subcat2.2

How can I create a view from these 2 different vocabularies?

i.e. dest1(term)/category(voc)/cat1(term)/subcat1.1(term)

# Answer
By default, Views Taxonomy page allows you to select multiple terms. If you click on the Contextual Filter "Content: Has taxonomy term ID (with depth)", one of the first choices you see is whether to allow multiple values.

Let's say that these categories have the following term IDs:

> Destination Vocab:
>
> * dest1 \[25\],
> * dest2 \[26\],
> * dest3 \[27\],
> * dest4 \[28\]
>
> Category Vocab:
>
> * cat1 \[35\] -- subcat1.1 \[37\] -- subcat1.2 \[38\]
> * cat2 \[36\] -- subcat2.1 \[39\] -- subcat2.2 \[40\]

If you want a page to show you all items in category 2 for destination 3, you'd have a url like this: `http://www.example.com/taxonomy/term/27+36`.

To limit the allowed Vocabularies, open that same Contextual Filter "Content: Has taxonomy term ID (with depth)" and scroll down to the section "WHEN THE FILTER VALUE IS IN THE URL OR A DEFAULT IS PROVIDED". There is a validation section where you can check off the vocabularies that you want included:

> taxonomy validation http://www.emijayne.com/sites/default/files/linked/taxonomy.jpg
> 0 votes

# Answer
Unfortunately this does not seem to truly work. Maybe you CAN allow multiple values, but Drupal does not really DO anything with it, except for the first. In fact Drupal self says: "If selected, users can enter multiple values in the form of 1+2+3. Due to the number of JOINs it would require, AND will be treated as OR with this filter." In other words contextual filter does NOT filter down (reduce) with consecutive arguments. You don't get /destination/category1 OR /destination/category2 etc. You only get /destination/further-arguments-don't-matter. I am now trying some workaround by exposing the second filter, pre-selected for the value I actually would have liked Drupal to use as second argument. It's quite clumsy, because you have to make a view and build a path for each 2nd argument (categories in this case: say hotels, apartments, restaurants), but at least you avoid having to do it for the first argument (destinations: Sevilla, Madrid, Barcelona...) as well. Also I guess that means argument1 cannot have more than one (or a fixed number of) level(s) or else Drupal gets confused again.
> 0 votes

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


title: How to disable a taxonomy term?

text:
# Question
Title: How to disable a taxonomy term?
I am interested in disabling-turning off taxonomy terms.I don't want to delete them so as to enable them later. How is this possible to do? thanks

# Answer
You may use Taxonomy Term Status module.

Project page says

> This module adds a status-flag to taxonomy terms. Using this flag it is possible to specify whether terms should be published or not. Users with the appropriate permission may access unpublished terms.
> 0 votes

# Answer
I think I found the answer:With the use of Taxonomy manager module,I can move the term to another vocabulary(selecting Double Tree),and when I need the term I can again move to the original voacabulary. cheers
> 0 votes

---
Tags: taxonomy-terms
---


# Question
Title: Seeking an approach to maintain a drupal site from a mobile platform
I have a client who needs to update their drupal site almost exclusively from their iPhone and iPad. They need to be able to upload images from iOS Photos. I have some ideas on how to approach, but I'm wondering if anybody in the community has encountered this situation and can suggest a combination of theme & modules that will help me get most of the way there. thanks

# Answer
I don't know about the qualitiy of this app, but could

Drupad - Drupal on the go (iPhone/iPad App)

help you?

**App description:**

Features for webmaster

* Manage any number of websites
* Create and edit content (CCK, Fields API support)
* Search and edit user accounts
* Read, post, moderate comments
* Moderate your content
* Mollom™ support
* Promote, sticky, publish, unpublish nodes
* Manage your users, send them email etc.
* Gravatar™ fallback for User's picture
* Drag to refresh and to load more content
* Built-in web browser
* Optimized to be fast in 3G or Wifi
> 0 votes

# Answer
Consider Adminimal Responsive Admin Theme. Integrated with Adminimal Administration Menu
> 0 votes

# Answer
So after a quick run through of the Admiminal Theme and its co-module Adminimal Administration Menu, I think out of the box its the going to be the right choice for our project. Its working pretty good out of the box, I can upload images from my iPhone 6+ w/ relative ease. I was initially interested in the Drupad app, but it looks like its not being maintained and is challenging to set up. As I'm doing this work for a client, we need to have an experience that is easy and as painless as possible.

I think Adminimal will get us most of the way there, w/ some modifications and the reasonable amount of customizing and coaxing. Thanks for all that weighed in.
> 0 votes

---
Tags: theming
---


# Question
Title: Last-Modified header is changed, even if the resource hasn't changed
Unless I'm mistaken, Drupal is changing the "Last-Modified" HTTP header for a page any time the page cache is regenerated - even if the raw content remains identical. This means that clients end up having to re-download exactly the same information any time the page cache is regenerated even for pages that have not changed at all.

I realize that I can improve this situation by trying to engineer things such that the page caches are not regenerated unless the resource has changed, but is there any way I can set things up such that the Last-Modified header genuinely reflects whether or not the content has changed? This would seem to me to be a more robust solution.

# Answer
The code that is causing the issues you're describing lives in drupal\_serve\_page\_from\_cache(). Instead of using a hash of the contents of the cache; Drupal uses the `$cache->created` value. Looking over everything hacking core is the only option at the moment. I'll see if there can be a way of not hacking core if one has total control of the cache backend; if there is a way look for an update inside of https://www.drupal.org/project/apdqc
> 2 votes

# Answer
You can add headers which will be delivered for newly rendered as well as responses retrieved from the page cache from within `hook_boot`. However, it might end up being rather challenging to determine the true modification date of any resource at this point in the request/response cycle (think of changes in other regions than the main content, e.g. blocks, panel panes, ...).

Also keep in mind that `Last-Modified` and `ETag` headers are only useful for *bandwith optimization*. This is extremely important for large static assets (images, CSS, JavaScript) but its generally not worth the hassle when delivering markup.

While I do not recommend it, you actually can override those headers from within a `hook_boot()` implementation in a custom module.

```
/**
 * Implements hook_boot()
 */
function MYMODULE_boot() {
  drupal_add_http_header('Last-Modified', 'Thu, 1 Jan 1970 00:00:00 GMT');
  drupal_add_http_header('ETag', 'abcdefg');
}

```
> 1 votes

---
Tags: 7, caching
---


# Question
Title: How to find node that a file is attached to
There is a file that I want to find the node it is attached to, or at least the user that submitted it.

I was able to create a view that finds the file itself but when I a field for node id, it displays nothing.

# Answer
> 1 votes
Create a view of files.

Add a relationship 'File Usage: Content'

Add a field 'title' and set the relationship on it to the one you created above.

Adjust the rest of the view as needed, ie add contextual filter Content: Image:fid

---
Tags: views, nodes, files
---


# Question
Title: Present users with form to create new node
I have created a content type called "member" in my project. Logged in Users have permissions to create nodes of type "member".

I want to my users to be able to create the nodes without having to click "create member"

I simply want to present them with the form when they log in and all they have to do is 1. Enter the values and 2. Click save.

Thank you.

# Answer
You could redirect the user upon login to the create form. A good module for this (and a lot of other stuff) is: logintoboggan
> 0 votes

# Answer
Here you can create a page of node form as well as you can edit the page with user wise permission,

```
function yourmodule_changes_menu() {
  $items = array();
  $items['member_page'] = array(
    'title' => 'Create member',
    'page callback' => 'yourmodule_member_page',
    'access callback' => 'user_is_logged_in',
    'type' => MENU_CALLBACK,
    'file path' => drupal_get_path('module', 'node'),
    'file' => 'node.pages.inc',
  );

  $items['member_page/edit/%node'] = array(
    'title' => 'Edit member',
    'page callback' => 'yourmodule_member_page',
    'page arguments' => array(2),
    'access callback' => 'member_node_access',
    'access arguments' => array('update', 2),
    'type' => MENU_CALLBACK,
    'file path' => drupal_get_path('module', 'node'),
    'file' => 'node.pages.inc',
  );
  return $items;
}

function member_node_access($op, $node, $account = NULL) {
    $rights = &drupal_static(__FUNCTION__, array());
    if((!$node) || ($op != "update")){
        return FALSE;
    }
    // If no user object is supplied, the access check is for the current user.
    if (empty($account)) {
        $account = $GLOBALS['user'];
    }

    $can_user_edit = node_access('update', $node, $account);
    if(($can_user_edit) || ($node->uid == $account->uid)){
        return TRUE;
    }
    return FALSE;
}

function yourmodule_member_page($node = NULL) {
  global $user;
  module_load_include('inc', 'node', 'node.pages');

  if ($node && $node->nid) {
    // Load the node edit form
    drupal_set_title(check_plain($node->title));
    $form = drupal_get_form('member_node_form', $node);
  }
  else {
    // Create new blog post
    $node = (object) array(
      'uid' => $user->uid,
      'name' => $user->name,
      'type' => 'member',
      'language' => LANGUAGE_NONE,
    );
    $form = drupal_get_form('member_node_form', $node);

      $variables['element'] = $form;

      // here render your content type fields
      $output  = drupal_render($form['title']);
      $output .= drupal_render($form['body']);
      $output .= drupal_render($form['field_category']);
      $output .= drupal_render($form['actions']);
      $variables['element']['#children'] = $output;
  }

  return theme_form($variables);
}

```

To redirect user to member page after login, there are many ways:

```
using [logintoboggan][1] or
using rule module or
using hook_user_login function

```
> 0 votes

---
Tags: nodes
---


title: Cannot see page content?

text:
# Question
Title: Cannot see page content?
I'm building a custom theme for Drupal 7.xx, which is part of my internship. I've been developing this theme for quite a while now, but I still consider myself an absolute beginner when it comes to theming for Drupal.

During the process, I've ran into quite a few problems which (luckily) I've been able to solve with the help of google (including Drupal Answers) so first of all thanks for that!

One of the problems I seem to be unable to solve, is that I cannot see the page content anywhere. So far I've added all content of the pages in blocks, which I've assigned to be rendered out by a region called 'cont\_page\_block', and which I have declared in my .info document.

To clarify: When I add a new page, I fill in the page title and body, but it doesn't appear on the page. Also, when I add a news article, I can see the teaser on my 'news summary' but when I try to click on it (which works though) it redirects me to a new page (URL states ?q=node/xx) which is, ofcourse, empty.

Here's the code I use in my page.tpl.php file to render the region:

```
   <div class="cont_page_block">    <?php print render($page['cont_page_block']); ?>
                                    <?php print render($content); ?>               </div>

```

And here's the declaration of my regions in my .info file:

```
regions[cont_page_block] = content-page-block
regions[content] = content

```

Am I missing a line of PHP code in my page.tpl.php file? Any help would be greatly appreciated!

# Answer
Try using:

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

```

Edit: To further the above, if you want to see the action links/titles/tabs you can print those by:

```
<?php if ($title): ?>
      <h1 class="title" id="page-title"> <?php print $title; ?> </h1>
      <?php endif; ?>
      <?php print render($title_suffix); ?>
      <?php if ($tabs): ?>
      <div class="tabs"> <?php print render($tabs); ?> </div>
      <?php endif; ?>
      <?php print render($page['help']); ?>
      <?php if ($action_links): ?>
      <ul class="action-links">
        <?php print render($action_links); ?>
      </ul>
      <?php endif; ?>
      <?php print render($page['content']); ?>
      <?php /*?><?php print $feed_icons; ?><?php */?>

```
> 0 votes

# Answer
Somebody slap me please.

I was about to take a smoke break to empty my head about the issue, and I suddenly realized I forgot to add the 'Site-Content' to the deisgnated region in the 'Block Management' area.

Problem solved!

Now please excuse me while I quietly sit ashamed in a corner.
> 0 votes

---
Tags: 7
---


# Question
Title: Views : List all user who didn't publish anything
Is it possible to create a list of all the user that didn't create a certain kind of content? I'm making a school graduated student album and each student have to creates a personnel node about there final projet and I need to verify who didn't create is node.

I try to create a list of all user of the student role but when I create a link whit the node with "Content authored" and I add the node Title the users without a Final Project Node hare removed from the list and this is excly the opposite that I need.

Thanks for you help.

# Answer
1. Create a view showing `Users`
2. In *Relationships* add:
    * `User: Content authored`
3. In *Filter criteria* add:
    * `User: The user ID`:
        + operator: `is not equal to` value: `0` (it excludes the anonymous user)
    * `Content: Nid`:
        + operator: `Is empty (NULL)` \[this gives you a list of users who have authored any content (excluding the anonymous user as mentioned above\])

---

The exported view:

```
$view = new view();
$view->name = 'users_with_no_content';
$view->description = 'Displays a list of users who have added any content yet.';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'Users with no content';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = TRUE; /* Edit this to false to make a default view enabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'access user profiles';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '50';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['quantity'] = '9';
$handler->display->display_options['style_plugin'] = 'list';
$handler->display->display_options['style_options']['row_class'] = 'user';
$handler->display->display_options['style_options']['default_row_class'] = FALSE;
$handler->display->display_options['style_options']['row_class_special'] = FALSE;
$handler->display->display_options['style_options']['type'] = 'ol';
$handler->display->display_options['style_options']['class'] = 'user-with-no-content';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: User: Content authored */
$handler->display->display_options['relationships']['uid']['id'] = 'uid';
$handler->display->display_options['relationships']['uid']['table'] = 'users';
$handler->display->display_options['relationships']['uid']['field'] = 'uid';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['name']['element_type'] = '0';
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['name']['element_wrapper_type'] = '0';
$handler->display->display_options['fields']['name']['element_default_classes'] = FALSE;
/* Filter criterion: User: The user ID */
$handler->display->display_options['filters']['uid_raw']['id'] = 'uid_raw';
$handler->display->display_options['filters']['uid_raw']['table'] = 'users';
$handler->display->display_options['filters']['uid_raw']['field'] = 'uid_raw';
$handler->display->display_options['filters']['uid_raw']['operator'] = '!=';
$handler->display->display_options['filters']['uid_raw']['value']['value'] = '0';
$handler->display->display_options['filters']['uid_raw']['group'] = 1;
/* Filter criterion: Content: Nid */
$handler->display->display_options['filters']['nid']['id'] = 'nid';
$handler->display->display_options['filters']['nid']['table'] = 'node';
$handler->display->display_options['filters']['nid']['field'] = 'nid';
$handler->display->display_options['filters']['nid']['relationship'] = 'uid';
$handler->display->display_options['filters']['nid']['operator'] = 'empty';
$handler->display->display_options['filters']['nid']['group'] = 1;
$translatables['users_with_no_content'] = array(
  t('Master'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Items per page'),
  t('- All -'),
  t('Offset'),
  t('« first'),
  t('‹ previous'),
  t('next ›'),
  t('last »'),
  t('nodes'),
);

```
> 1 votes

# Answer
If there is any required field in the content, then you `add that field in filter criteria and choose Operator as Is empty'`. Do not forget to \`add a relationship of 'user:content authored'.

Hope this will help you.
> 0 votes

---
Tags: views, users
---


# Question
Title: How to hide selected term values in Views?
I have a content type with a taxonomy field called Price. Authors create content based on this content type. While doing so they select from a Price list (two options). Either they can select 'Costs Money' or 'Free'.

In Views, I want to show the value (a rendered image) if it's set to "*costs money*" and NOT display the field if it's set to "*free*".

Is there an easy way to accomplish this in Views?

I'm using Views 3 and Drupal 7.

# Answer
Use the views feature "rewrite result", combined with a logic similar to the pseudo code that is below to implement the desired functionality:

```
if Price Term = 'Costs Money' then write the image tag related to 'Costs Money'
else write

```

Not sure if you'd actually need the else clause ...

**Note**: This requires the Views PHP module , as described in https://www.drupal.org/node/482752#comment-4841554 also. Attention: this module only has an alfa version as of today, but it's used in over 71K sites anyway.
> 1 votes

---
Tags: 7, views
---


# Question
Title: Show a discount field in the Product display page
I want to apply some discounts on products. I know the Commerce discount module and its UI. However,it would be much simpler for the site admin to have a second field on the product display for the discount-new lower price. Is this possible to do?If so how? thanks

# Answer
I found the answer,with the use of this module https://www.drupal.org/project/commerce\_saleprice
> 0 votes

---
Tags: commerce
---


# Question
Title: Node.tpl.php file: Check is several fields are empty
On my node, I have three `location` fields (primary, secondary, code) and three `object` fields (food, fuel, accommodation).

I want my node.tp.php to check if all the `location` fields are empty or if all the `object` fields are empty and then print a message.

How can I do this?

---

### Steps I have tried

**1. Checking if the fields are empty.**

This post says you can check if a single field is empty with the following code:

```
$field = field_get_items('node', $node, 'field_post_image');
if ($field) {
//Do something with the field
}
else{
//There are no results
}

```

I have adapted the code by adding the fields to an array and then testing to see if the array is empty:

```
<?php $empty_message = "No items here, click edit to add some.";?>

<?php
$field = array();
$field[]= field_get_items('node', $node, 'field_primary');
$field[]= field_get_items('node', $node, 'field_secondary');
$field[]= field_get_items('node', $node, 'field_code');

if (empty($field)) {
print $empty_message;
}
?>

<?php
$field = array();
$field[]= field_get_items('node', $node, 'field_food');
$field[]= field_get_items('node', $node, 'field_fuel');
$field[]= field_get_items('node', $node, 'field_accomodation');

if (empty($field)) {
print $empty_message;
}
?>

```

But it doesn't seem to work. The original post actually says this is the wrong way to check if fields are empty, but I'm not sure how to adapt the suggested code.

**2. Using Field Group**

I would prefer not use this module, as it adds too much complexity for my needs.

# Answer
> 1 votes
Put all the logic in your template.php (or wherever your preprocess functions go) with `THEME_preprocess_node()`:

```
function THEME_preprocess_node(&$variables) {
  // Grab the node
  $node = $variables['node'];

  // Only run for your content type
  if ($node->type == 'your_content_type') {

    // Grab your fields with field_get_items so that it is translation friendly
    $location_field1 = field_get_items('node', $node, 'location_field1');
    $location_field2 = field_get_items('node', $node, 'location_field2');
    $location_field3 = field_get_items('node', $node, 'location_field3');
    $object_field1 = field_get_items('node', $node, 'object_field1');
    $object_field2 = field_get_items('node', $node, 'object_field2');
    $object_field3 = field_get_items('node', $node, 'object_field3');

    // Check if all location fields are set or not
    if (isset($location_field1[0]['value']) && isset($location_field2[0]['value'] && isset($location_field3[0]['value'])) {
      // Create a variable that can be used in your node.tpl.php
      $variables['messages']['location_message'] = 'All location fields are set...';
    } else {
      // Create a variable that can be used in your node.tpl.php
      $variables['messages']['location_message'] = 'All location fields are not set...';
    }

    // Check if all object fields are set or not
    if (isset($object_field1[0]['value']) && isset($object_field2[0]['value'] && isset($object_field3[0]['value'])) {
      // Create a variable that can be used in your node.tpl.php
      $variables['messages']['object_message'] = 'All object fields are set...';
    } else {
      // Create a variable that can be used in your node.tpl.php
      $variables['messages']['object_message'] = 'All object fields are not set...';
    }
  }
}

```

Then, in your `node.tpl.php` you will have access to the message and you can print it anywhere with:

`print $messages['location_message'];`

and

`print $messages['object_message'];`

---
Tags: entities, theming
---


title: Drupal Colorbox with Prezi iframe

text:
# Question
Title: Drupal Colorbox with Prezi iframe
I have a Prezi file and the embedded code is like this:

```
<iframe src="http://prezi.com/embed/id-of-the-file/?bgcolor=ffffff&lock_to_path=1&autoplay=0&autohide_ctrls=0&features=undefined&disabled_features=undefined&html5=1" width="550" height="400" frameBorder="0" webkitAllowFullScreen mozAllowFullscreen allowfullscreen></iframe>

```

I have installed Colorbox and activated Colorbox load and Colorbox inline in the module settings.

How can I open this file with Colorbox?

I've created a link and tried like this:

```
<a class="colorbox-load" href="http://prezi.com/embed/id-of-the-file/?bgcolor=ffffff&lock_to_path=1&autoplay=0&autohide_ctrls=0&features=undefined&disabled_features=undefined&html5=1?width=500&height=500&iframe=true">open in Colorbox (iframe)</a>

```

The colorbox is opening, but it shows "This content failed to load".

# Answer
You created your link by concatenating `width=500&height=500&iframe=true` with an `?` instead with another `&` So the working link would be:

```
<a class="colorbox-load" href="http://prezi.com/embed/id-of-the-file/?bgcolor=ffffff&lock_to_path=1&autoplay=0&autohide_ctrls=0&features=undefined&disabled_features=undefined&html5=1&width=500&height=500&iframe=true">open in Colorbox (iframe)</a>

```
> 1 votes

---
Tags: javascript
---


title: what does 'admin/build/modules' mean?

text:
# Question
Title: what does 'admin/build/modules' mean?
I'm a total newbie to Drupal so I'm starting by trying to follow some tutorials. One says to enable a module at **admin/build/modules** but I have no idea what this means. I assume this is a path through menus, but my admin menu item has no build submenu.

Which is the correct path?

# Answer
> 0 votes
In Drupal 7 modules are enabled at the path 'admin/modules'.
In Drupal 6 the path is 'admin/build/modules'.

# Answer
> 0 votes
To enable a module go to `admin/modules`, then it show you list of enabled/disabled modules and you can enable any of them. what else do you want to know?

---
Tags: routes
---


# Question
Title: Installling fails with no error messages
I installed Drupal 7 on linuxMint 17.1 localhost using the install wizard. Submitting the database configuration page leads to a white screen and nothing else happens.

Looking at the database I could see some data though.

Can anyone help me to fix it?

# Answer
This is a typical white screen of death issue, ways to debug it are described here on drupal.org
> 0 votes

# Answer
Try deleting the Drupal folder and download it again. Don't forget to drop and create or truncate the DB.
> 0 votes

---
Tags: 7
---


# Question
Title: How to create and send an HTML formatted eMail using CSS?
I am going crazy in making a welcome eMail in Drupal.

What I want is sending a nicely formatted eMail using HTML and CSS. I do not need to send an eMail to user except a welcome eMail after user registration, that's all.

I've tested my code in eMail field in the "**Home » Administration » Configuration » People**" page, but it does not accept CSS code.

HTML email and mail system modules are so sophisticated that I could not use theme.

Anybody a solution for this?

# Answer
With some experience in that field I must say designing 'nice' html mail templates can be difficult – no matter what system you use to actually send your mail. The reason for this is that there are quite many different email clients – from full blown local desktop computer programms to mobile apps on smart phones and feature phones – and a virtally countless number of online services –– all behaving slightly different. Some email clients do accept css3, some don't interprete css at all, some only accept inline css.

So I suppose you probably either have to start digging into that – or use the methods that are rather 'safe' to use as offered by various services and/or modules.
> 2 votes

# Answer
The MimeMail module is pretty good with this. Try that and use the table here to reference what syntax/tags are available for the best cross-client support.
> 0 votes

# Answer
thanks all I used mime mail and display suit module and it worked fine for me. that was what I need
> 0 votes

---
Tags: users, emails, theming
---


title: how to make fewer http requests

text:
# Question
Title: how to make fewer http requests
I'm use YSlow to optimize my web pages it says: This page has 34 external Javascript scripts. Try combining them into one. This page has 5 external stylesheets. Try combining them into one. but all I have in this page is some blocks and menus and a nivo slider which I think is the main reason of this issue!! so I think nivo slider sends all this requests!! How can I improve it?

# Answer
There are couple of things you can do,

1. install labjs module: it is a JavaScript loader, used by Twitter, Vimeo, examiner.com... which loads (and executes) all scripts in parallel as fast as the browser will allow.
2. Enable gzip compression: It reduces the size of files sent from server to increase the speed. You have to enable it in `.htaccess` file, for more information visit this page.
3. As @2pha said `Advanced CSS/JS Aggregation` is very effective effort.
4. Install optimize\_db module: it handles the issue with fast-growing table cache\_form.

Anyway, gtmetrix suggests many techniques to improve your website performance.
> 3 votes

# Answer
What have you tried already?
I use the Advanced CSS/JS Aggregation module which combines js and css file together making for fewer http requests. It also has some other features including moving js and css to the footer.
> 1 votes

---
Tags: javascript, files, performance
---


# Question
Title: Responsive Views-Slideshow Json Cycle working good in Chrome not in IE or mozilla
In drupal I AT themes, views with slideshow of json2 and cycle plugin. I set the options for the plugin like this : Make views slideshow responsive - remove inline styles

* height auto , width auto , containerResize 0 , slideResize 0 , fit 0

Result: \- In chrome works perfect \- IE and firefox not responsive

Probably something to do with the html but how to find out where en how. Can it be sold with some CSS? Any suggestions?

# Answer
> 1 votes
I use this code

```
     $(window).resize(function () {
          $('.views_slideshow_cycle_main').each(function(){
                var cycleMain = $(this);
                var img_width = 0,
                    img_height = 0;
                var clearCSS = {width: "auto", height: "auto"};
                var cycle = cycleMain.children('.views-slideshow-cycle-main-frame');
                cycleElements = cycle.data("cycle.opts");
                cycle.css(clearCSS);
                cycleMain.find('.views-slideshow-cycle-main-frame-row').each(function(i){
                  $(this).css(clearCSS);
                  var tmp_img_width = $(this).width();
                  var tmp_img_height = $(this).height();
                  if(tmp_img_width > img_width)
                    img_width = tmp_img_width;
                  if(tmp_img_height > img_height)
                    img_height = tmp_img_height;
                  cycleElements.elements[i].cycleW = tmp_img_width;
                  cycleElements.elements[i].cycleH = tmp_img_height;
                  $(this).css({width: tmp_img_width, height: tmp_img_height});
                });
                cycleMain.height(img_height);
                cycle.css({width: img_width, height: img_height});
                cycle.data("cycle.opts.elements", cycleElements);
              });

        });

```

and it works perfectly. you can also add some css to avoid too much high height like:

```
@media screen and (min-width: 980px){
 .al-slideshow img{
       height: 650px !important;
   }
}

```

The following css code is also needed

```
.views_slideshow_cycle_main { width: 100% !important; }
.views_slideshow_cycle_main .views-slideshow-cycle-main-frame { width: 100% !important; height: auto; }
.views_slideshow_cycle_main .views-slideshow-cycle-main-frame-row { width: 100% !important; height: auto; }
.views_slideshow_cycle_main .field-content { max-width: 100%; width: 100%; }
.views_slideshow_cycle_main .field-content img { max-width: 100%; width: 100%; height: auto; margin: 0; padding: 0; }

```

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


title: translate string

text:
# Question
Title: translate string
On the site: http://whayme.com/cleantheme/welkome-bij-whayme#

if you push the button for "Meld me aan" (Subscribe btn) WITHOUT a email address then a message will appear.

E-mail field is required.

I would like to change this message into "foo another message txt" but cannot find out how to do it. I already installed the stringoverrides module, but somehow this string is not matched. This modules works with other strings. Installed i18n but I don't want a second language. I just want a small adjustment.

Other suggestions?

# Answer
> 0 votes
I think string overrides is not working because the error string is using a token of some kind.
Maybe try replacing "!name field is required." in string overrides.
I have not tested this btw.

---
Tags: i18n-l10n
---


# Question
Title: Add body class to Node Display (to distinguish it from Node/Edit or Node/add view)
I want to add a body class that will only appear on the *actual node display* (e.g. `mysite.com/node/1`). I don't want this body class to appear on the node/edit page (e.g. (`mysite.com/node/1/edit`) or the node/add page.

The reason for this is that I am making custom node form templates. At the moment, the css gets wrongly applied to the node Display.

I know I could just add a wrapper DIV to my templates, but I would rather use the body class, as it will be more efficient for my theming work flow.

I have successfully applied body classes to the *edit* and *add* displays with the following code in template.php

```
function MYTHEME_preprocess_html(&$variables) {
  if ((arg(0)=='node' && arg(2)=='edit') || (arg(0) == 'node') && (arg(1) == 'add')) {
    $variables['classes_array'][] = 'node-edit-page';
  }
}

```

Is there something similar I could use to target the actual node display? I tried doing a KPR dump of the page, node and HTML hooks with theme\_devel, but I could not find anything useful.

# Answer
arg(2) will return NULL on node pages (like node/1).

```
  if (arg(0)=='node' && is_numeric(arg(1)) && !arg(2)) {
    $variables['classes_array'][] = 'node-view-page';
  }

```
> 1 votes

---
Tags: theming
---


# Question
Title: Ajax Framework Using Dynamically Generated Links
I know, for links to be **ajaxified** they need to have a class: "use-ajax" and a proper url which has its own callback. For example:

```
<a href="ajax-reader/nojs/1/2015-03-05" class="use-ajax ajax-processed">Ajax Link</a>

```

If the link was statically created on the server, it works perfectly fine. But whenever I add a new link with the same properties, ajax seems not to work anymore. For instance, if I remove existing link and add a new one with new url parameters:

```
var ajaxRightUrl = 'ajax-reader/nojs/1/' + lastNextDate;
arrowLinkLeft.find('a').remove();
arrowLinkLeft.append('<a href="' + ajaxRightUrl + '"class="use-ajax"></a>');

```

It stops being an ajax link. Any ideas why?

# Answer
you are probably missing the part to add behaviors to your new elements:

```
Drupal.attachBehaviors('.use-ajax');

```
> 1 votes

---
Tags: ajax, navigation
---


title: How to set up html email from rules?

text:
# Question
Title: How to set up html email from rules?
I want to send a HTML email from rules but I cannot get it correct.

Installed mime, html, mail. Created rule. only a trigger and action send html email. In the rule: no message key defined, subject is something like \[node:nid\], body is \[node:body\]

Made a template at campain monitor, now i have foo.html. Renamed foo.html to mimemail-message.tpl.php in default theme directory and put \[node:id\] and \[node:body\] on the correct place. Soo, the css is in the tpl file.

1) When testing I get an html email (logo is visible) but no colors. Installed and configured: sites/all/libraries/emogrifier/emogrifier.php Mailsystem is using mime, mime is using full html filter including emogrifier. No change in the result. I read the message with gmail. Adblockes disabled.

Any suggestion what to do ?

2) How to get replacement of the tokens. Which tokens are available for this tpl file?

# Answer
> 5 votes
I forgot to enable the module mimemail\_compress. After enabling this it was solved.

---
Tags: theming, emails
---


# Question
Title: How does one add a new base field to a content entity?
I'm currently porting my contributed module to Drupal 8, and sometimes I realize I've chosen the wrong field type. I also know that I will need to add additional fields later on, and it would be nice to avoid having to uninstall and reinstall the module every time I do this.

I looked at Add field to existing content entity, but it did not seem to be the actual question.

My question is basically: what's the equivalent of similar D7 `update.php` code with D8 and entities?

```
<?php
function MYMODULE_update_7101() {
  db_add_field('mymodule_table', 'some_new_field', $field_schema);
}
?>

```

# Answer
> 2 votes
Adding fields just works. Define the new field, run update.php, it will compare the new and existing definitions and figure out that there's a new field to create.

Renaming/deleting fields works too, but only when you have no data. When you have data, then you will still need to write an update hook, or a migration. We're missing documentation on how that will look exactly, but basically, you use the same schema functions as in 7.x and then update the last installed field definitions.

---
Tags: entities, 8
---


title: Upgrade Drupal Core from 7.9 to 7.35?

text:
# Question
Title: Upgrade Drupal Core from 7.9 to 7.35?
I've just moved my Drupal site from one host to another, as a complete backup and restore. I've got a few issues left (images not showing, search not working), but the main thing is, on my status reports, it shows my Drupal Core installed version being 7.9, but the recommended version being 7.35.

As a Drupal novice, can anyone explain how I Have version 7.9 when the latest core is 7.35, AND, if I "upgrade" to 7.35, am I likely to encounter any significant problems?

Thanks Carlton

# Answer
> can anyone explain how I Have version 7.9 when the latest core is 7.35

Drupal core need to be updated a regular intervals. This does not happen automatically. If Drupal 7.9 was the version you installed, it will stay at that version until you update. Moving hosts does not update anything. *All* Drupal versions prior to ver. 7.32 suffered from a critical security vulnerability (see SA-CORE-2014-005 for details). I would strongly recommend that you take your site offline *until* it is properly upgraded from 7.9 to the latest version (currently 7.35).

Upgrading Drupal core is usually painless if you've got *drush* installed, even if going over several generations. The command to use (you do this in the CLI) is:

```
drush up drupal -y

```

Sit back and watch *drush* sort out all the interdependencies.

Best of luck!
> 1 votes

---
Tags: updating
---


title: Content Type Content Theme Template

text:
# Question
Title: Content Type Content Theme Template
Is it possible to make a template based on node content? For instance, is it possible to *page--\[node-type\]--%.tpl.php* or *block--\[content-type\].tpl.php* or *page--\[content-type\]--%*. I tried *node--\[content-type\].tpl.php* but to no avail. When I use the theme developer module, it shows me that my content is being created as a *'block.tpl.php'* template.

What I want to do is theme the content of node name 'vehicle'. I want to put custom headings, styles and classes for divs in, and display suite is not giving me these options. Any other suggestions would be awesome.

Thanks

# Answer
> 0 votes
You are right node--\[content-type\].tpl.php is what you are looking for ,, but you need to get the fields values which can be done with `print_r($node)` inside the tpl file.

clear your cache to be sure to see the result.

---
Tags: theming, nodes
---


# Question
Title: How to Include an ATTACHMENT to a Drupal's Entityform Submission Email?
I am using the Entityform module and the Rules module for its notification . I noticed that the email sent out when the form is submitted does not attach the PDF file as part of the email's body.

I have one field in the form that allows a user to attach a PDF file. The email body is fine with the exception that any file attachment is not part of the email.

I also added the Mime Mail module with no success.

Does anyone know how to include an attached file as part of the email notification?

# Answer
> 1 votes
Here is some more detailed guidance on how to solve this:

As mixerowsky states you will need to download and set up Mime Mail.

The latest version of Entity Form (7.x-2.0-rc1) comes with it's own preconfigured rules. You'll need the Entity Rules module for these. You can clone or edit these.

Alternatively you can set up your own fresh rules in the 'normal' way by using the 'After saving a new entityform submission' event.

Whichever method you go for you will need to add the 'Send HTML e-mail' element to the Actions stage of the rule (you can remove the existing actions if you cloned the packaged entity rules).

Edit the action and within the attachments section you can add a file path token, e.g.

`[ENTITY_NAME:FILE_FIELD_NAME:file:path]`

Check the Replacement Patterns for the correct ENTITY\_NAME and FILE\_FIELD\_NAME and make sure you append ':file:path' as above and you will get an attachment on the HTML email.

Other file tokens include:

```
[ENTITY_NAME:FILE_FIELD_NAME:file]
[ENTITY_NAME:FILE_FIELD_NAME:file:url]
[ENTITY_NAME:FILE_FIELD_NAME:file:size]

```

You may wish to use these in the email body for example.

Here is a list of file tokens. There are other useful tokens listed on there too.

---

**Trouble Shooting & Testing**

Make sure you are using the correct token. Check the replacement patterns for the correct entity name and file field, e.g.

`[ENTITY_NAME:FILE_FIELD_NAME:file:path]`

Then try adding the file tokens to the email BODY to make sure that it is working correctly, e.g. Add this to the body:

```
Filename: [ENTITY_NAME:FILE_FIELD_NAME:file]
Filepath: [ENTITY_NAME:FILE_FIELD_NAME:file:path]
FileURL:  [ENTITY_NAME:FILE_FIELD_NAME:file:url]
Filesize: [ENTITY_NAME:FILE_FIELD_NAME:file:size]

```

This should output something like this in the BODY of the email:-

```
Filename: filename.pdf
Filepath: public://filename.pdf
FileURL:  http://website.local/system/files/filename.pdf
Filesize: 16.59 KB

```

If the 'filepath' is not present then there will be no attachment.

Make sure that the Drupal file system is set up correctly and files are getting saved when the entity form is submitted.

Double check your System Stream Wrappers and Token installs.

Make sure you have set up Mimemail correctly and you are receiving emails OK. Maybe set up a test using a different system (e.g. Webform) to check that file attachments are working in the first place.

If you use the correct token then it will work - however if there is an problem with the set up of the email sending or other modules then you may not get an attachment. The chain from 'entity form' to 'email with attachment' is quite long and complex so make you test every step of the journey.

# Answer
> 0 votes
Here the two modules which can help you sending HTML mails

1. Mimemail

> Provides simple system actions and Rules actions to send HTML email with embedded images and attachments.

2 Rules

It will allow you to send html mail as action on event of your entityform submission.

---
Tags: 7, rules, entities, emails
---


# Question
Title: How can I send html email notifications with entityforms?
There must be a way to do this, but I'm having trouble turning it up. Has anyone successfully sent HTML email notifications following an entityform submission?

# Answer
Here some more detailed guidance on how to solve this:

**HTML EMAILS**

You will need to download and set up Mime Mail.

The latest version of Entity Form (currently 7.x-2.0-rc1) comes with it's own preconfigured rules. You'll need the Entity Rules module for these. You can clone or edit these.

Alternatively you can set up your own fresh rules in the 'normal' way by using the 'After saving a new entityform submission' event.

Whichever method you go for you will need to add the 'Send HTML e-mail' element to the Actions stage of the rule (you can remove the existing actions if you cloned the packaged entity rules).

You can configure KEY, TO, CC, BCC, SENDER NAME, SENDER E-MAIL ADDRESS, REPLY E-MAIL ADDRESS, SUBJECT, BODY, PLAIN TEXT BODY, ATTACHMENTS, LANGUAGE.

**EMAIL FILE ATTACHMENTS:**

A lot of people have trouble getting file attachments to work with Entity Forms.

To do this:

Edit the action and within the attachments section you can add a file path token, e.g.

`[entity:THE_FILE_FIELD_NAME:file:path]`

Check the Replacement Patterns for the field name and make sure you use 'file:path' as above and you will get an attachment on the HTML email.

Other file tokens include:

```
[entity:THE_FILE_FIELD_NAME:file]

[entity:THE_FILE_FIELD_NAME:file:url]

[entity:THE_FILE_FIELD_NAME:file:size]

```

You may wish to use these in the email body for example.

Here is a list of file tokens. There are other useful tokens listed on there too.
> 1 votes

# Answer
If you do not want to do it with custom codes, here the two modules which can help you sending html mails

1. mimemail

> Provides simple system actions and Rules actions to send HTML email with embedded images and attachments.

2 rules

It will allow you to send html mail as action on event of your entityform submission.
> 0 votes

---
Tags: 7, emails
---


# Question
Title: Drupal Commerce - creating a product catalog
I've downloaded Drupal Commerce and created my 3 products. Everything else I've kept as the default. Then I wanted to created a catalog so users could buy items. Note: I've also installed and input API credentials for Drupal Paypal already. So then I went to create a view of type 'product display' as seen here:

```
https://drupalcommerce.org/user-guide/setting-product-catalog

```

But when I create a new view 'product display' is not one of the 'type' options.

So my question is, how do I get something to show as a product display item? somehow it seems I have to map the products I created to 'content types'...but shouldn't the module already do that?

I looked back through the documentation on that site, and undoubtedly I missed something, but I'm not seeing how this is done.

Note #2: I tried to install commerce kickstart, but I'm using WAMP and couldn't get it to work, so I have to trudge through on my own.

# Answer
> 1 votes
In the link you reference, when they say "product display", they are speaking of a Content Type (when a content type has a field type of "product reference", the content type then becomes a product display). If you have a content type set up that references products, that is the content type you would choose in "of type" in your view set up.

If you don't have a content type that references products, it's very easy to set up.

1. Go to Structure \> Content Type \> Add Content Type \> Name it Product Display (or any name) \> Select Save and add fields
2. You will then be able to manage your fields \> Add New Field \> Name it Product Reference(or anything similar) \> Choose field type: Product Reference. \> Widget Type: Use any default option or look into inline entity form \- You'll find that very useful.
3. Set up your field how you see fit for referencing products \> Save
4. Go set up your view and you'll then see "Product Display" as an option.

> somehow it seems I have to map the products I created to 'content types'...but shouldn't the module already do that?

Yes, it does create a content type for you, but not out of the box. In order for this to happen, you create a brand new Product Variation Type:

Store \> Configuration \> Product Variation Types \> Add Product Variation Type

This is where you choose to have a matching product display type set up automatically. This option sets up a new product variation type and a content type.

Its important to remember: A product display is another name for a content type. It becomes a product display because it references products.

# Answer
> 1 votes
You need to have the `Product Reference` module enabled and create your `Product Display` content type manually and add a product reference field to it. Then you can use this content type in Views.

Source: Creating Product Display Content Type

---
Tags: commerce
---


title: How to use the youtube module?

text:
# Question
Title: How to use the youtube module?
I've added and enabled the YouTube module and I'd like to put a YouTube video on my page but I can't figure out how.

I think there is a youtube widget somewhere but I can't find it or get it onto my site.

# Answer
I assume you mean this module? https://www.drupal.org/project/youtube

If so this module provides a field for your content type of choice where you need to display the video. The most basic content type to start with is "Basic Page".

Once you add this field, when you "add content" for this youtube field you can specify it's URL. When you view this node/entity the video player should show up. This module does have the ability to render the Youtube player, but there's a chance you may have to configure your content type view mode.

This Youtube video has more details on the setup for the Youtube Field module - Youtube Field Setup Video
> 1 votes

# Answer
You might want to try media and media\_oembed or media\_youtube
> 0 votes

---
Tags: entities, files
---


# Question
Title: Website encountered unexpected error - how to avoid?
I'm having that typical problem of `Website encountered unexpected error` popping up sometimes and then after repairing `watchdog` MySQL table it all works find again.

My question is if there is a module that would do this automatically? Or any script that I could run from cron or from drupal?

I installed `db maintenance` module and thought it does that, but apparently no.

Thank you!

# Answer
Does MySQL crash after that error? Either way your watchdog table is being corrupted. Are you running out of disk space? Make sure you are using InnoDB tables; MyISAM is prone to corruption.

You can check your table type by running this from a MySQL command prompt and looking for the Engine= parameter.

```
mysql> show create table watchdog;

```

You can also disable dblog and enable syslog instead. Syslog writes to your system logs and is much more scalable for higher traffic sites. See if that solves your problem.
> 0 votes

---
Tags: 7, database, cron
---


title: Manager for all Organic Groups

text:
# Question
Title: Manager for all Organic Groups
I am working in a project that requires the use of organic groups and I was wondering is there is a way to setup a "global" drupal role that will give the users with that role access to all groups as managers.

Note: This managers might not be the user that created the group.

# Answer
> 1 votes
extending the answer from Essam Al-Qaie on og\_role\_override

implementing a custom permission in a new module will help to separate this from the rest of your site.

```
function mymodule_permission() {
  return array(
    'global og manager' => array(
      'title' => t('Global OG manager'),
      'description' => t('Be a manager for all og groups, globally.'),
    ),
  );
}

```

# Answer
> 2 votes
I received the same request once .. and what I need is this module og\_role\_override

> This module provides Core permissions to act as particular OG roles in specific group types.
>
> In other words, it creates permissions of the form 'Act as ROLE in GROUP-TYPE' for each role and each OG group type. Granting this permission to a Core role gives it the same permissions as that OG role, in all groups of that type.
>
> For example, you might want users with your 'site editor' role to be able to act as a 'board member' in all OG groups, without having to add them to each group, and without having to replicate all the OG permissions as Core permissions.

Hope it helps ..

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


title: Filtered html ignores extra line breaks

text:
# Question
Title: Filtered html ignores extra line breaks
I'm using the Filtered HTML input format without a WYSIWYG editor.

When editing text, if I put some text onto a new line by hitting `return`, when I save its fine.

However if I add another line (so there is a space between the 2 lines of text) by hitting `return` twice, when I save this extra line disappears. How can I stop this from happening? Thanks

So I can do this:

```
1
2

```

But I can't do this:

```
1

2

```

# Answer
> 0 votes
Ive found a solution but its not perfect.

Ive turned on the 'Limit allowed HTML tags' filter for safety but turned all other filters off. This means the spaces appear in the code but do nothing as they arn't p or br tags.

Then I apply white-space: pre; to the element. Now all the spaces and new lines are preserved.

The issue with this is that a user could enter 100 new lines as there is no validation at all. Another problem is if this field is aggregated or used elsewhere on the site you would need to apply the css again to see the spaces.

Ill be very happy to accept a better solution.

# Answer
> 1 votes
Consider using the Markdown Filter. It not only solves your problem, but gives a more intuitive input option.

If your users are used to using Markdown on StackOverflow, then they will love it ;) In fact, StackOverflow was one of the first sites to integrate the Markdown format.

# Answer
> 0 votes
Add the "P" tag (\< p \>) and "BR" tag (\< br \>) to the list of allowed tags on your filter HTML tags settings. You don't have to worry about security because since it is a filter HTML all the extra code like style inside the p tag will be remove.

**Note:** Make sure to check the option to Convert line breaks into HTML (i.e. \< br \> and \< p \>)

**Note 2:** if using a WYSIWYG editor like ckeditor make sure you have a set a condition like in note 1.

# Answer
> 0 votes
Another solution is to use a wysiwyg editor. If you add a blank line then Ckeditor will create a p tag containing a html space.

I was however hoping to avoid using an wysiwyg as it needlessly increases the page size. I also dont know what its performance is link on mobile devices as its javascript based.

# Answer
> 0 votes
I don't know a perfect solution either. You can limit the number of consecutive newlines at any stage you like with regex - client-side presave, server-side presave, server-side pre-output, client-side output.

Here's an example for server-side pre-output modification in your theme's template.php file. The plain\_text format can be any text filter of your choice and the null case covers plain text (when filter not set). I'm limiting the max newlines to 2 (using `{3,}` for 3 instances and above). My generalised regex covers \r newlines as well but this wouldn't be necessary in this use case.

```
function YOURSUBTHEME_preprocess_field(&$variables, $hook) {
  if ($variables['element']['#field_type'] == 'text_long' &&  // Makes sure this is a text_long field type.
    isset($variables['element']['#items'][0]) &&
    (!isset($variables['element']['#items'][0]['format']) ||
    $variables['element']['#items'][0]['format'] === 'plain_text')
  ) {
    foreach ($variables['items'] as $index => $value) {
      $markup = isset($variables['items'][$index]['#markup']) ? $variables['items'][$index]['#markup'] : '';
      $markup = preg_replace("/[\r\n]{3,}/", "\n\n", $markup);
      $variables['items'][$index]['#markup'] = nl2br($markup);
    }
  }
}

```

---
Tags: 7, input-formats
---


title: Views pager in a panel page

text:
# Question
Title: Views pager in a panel page
I created a view to show a nodes image field (unlimited values) and placed that views block into a panel page region. For some reason the pager doesn't show up. I googled around but cant see any others having these issues. All the associated images are shown on the page instead of the 6 i set up in views.

# Answer
> 1 votes
Well, just after posting here i went back to the problem. Turns out i only had to check off the "Display all values in the same row" in the "Multiple field settings" section of the field in the view. Pager showed up now.

---
Tags: views, panels
---


# Question
Title: Not possible to drush sql-sync sqlite to mysql pragma
I have a local testing setup where I can create drupal sites easily, all running with a sqlite DB.

I want to (firstly) publish the site to a remote server using a script that calls

```
drush sql-sync @blah.livesite.local @blah.livesite.com --create-db

```

The problem i ran into is that `drush sql-sync` does not like to migrate a sqlite DB to a mysql DB as some structural deficites block the transfer. The error message is:

```
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for
the right syntax to use near 'PRAGMA foreign_keys=OFF' at line 1

```

I know I maybe can do a sql-dump first, edit some of the lines manually and import that filt into the remote db then. But I need this procedure quite often and have an automation script for the transfer - it should work fast with no manual editing involved.

Is it not possible to sql-sync from sqlite to mysql generally?

Yes, and I tried dbtng-migrate as well, with help of there. It did not work, I ran into all kind of errors, and I don't want to create another mysql db locally and sync then.

All I want is a simple way to sync my local sqlite drupal install to a remote mysql one.

# Answer
> 2 votes
Drush sql-sync cannot convert and sync databases in one step; however, you can use drush dbtng migrator to convert the database locally into mysql format, and then use sql-sync to copy it to the final destination.

---
Tags: drush, database
---


title: Double content paths ubercart D7

text:
# Question
Title: Double content paths ubercart D7
I'm using Drupal 7 and Ubercart 3. Using pathauto I generate clean url's. However there are two paths to my catalog pages.

product\_main\_category/category

product\_main\_category/category-0

I think it has something to do with the fact that there is a catalog path and a taxonomy path, but i don't know why. My installation is very basic so i would assume a lot of people should have seen this problem before.

# Answer
> 1 votes
This problem arises because the Ubercart Catalog takes over the display of the taxonomy term pages for the Catalog vocabulary, as well as creating its own set of URL aliases for the Catalog terms.

I solved this problem quite simply, by disabling Ubercart's Catalog module and deleting all the aliases for the Catalog terms (as opposed to the Catalog taxonomy terms).

To achieve this, I had to:

* create a new view that mimicked the the Catalog
* ensure that the Catalog term pages used my new view. There are various ways to do this in Drupal including overriding the taxonomy default view, enabling a module like TVI, and Panels. I prefer Panels, so that's the route I took.
* Optional - replace the Catalog block (which is useful as a sidebar menu for your Ubercart store). I did this using Taxonomy Menu and Menu Block.
* Deleting all the aliases for the Catalog and Catalog Taxonomy, and bulk regenerating the Catalog Taxonomy aliases.

In the end, my site looked the same as it did before, but I no longer have the duplicate URL problem, and I'm no longer tied to the rather awkward Catalog module in Ubercart.

# Answer
> 0 votes
Pathauto will not create duplicate paths. If the patterm defined for your catalog page and for your taxonomy path are the same, pathauto will append a '-0' to prevent duplication. Whatever your patterns are, you will always have two url's for each page; one based on the pattern for the entity type, and one based on the taxonomy pattern.

---
Tags: taxonomy-terms, ubercart, path-aliases
---


title: Change line item titles

text:
# Question
Title: Change line item titles
I'm building a shop with many promotions. Some articles in the shopping cart have a linked promotion I want to show in the shopping cart summary, before the order completion.

It's a shop without any visible prices. The total amount of the order is calculated on the servers. There is nothing to worry about that.

How can I display the pink text in a proper way? Would it be best to get this data from the database and place it as a field in a table (since the shopping cart summary is a view)? Or what other options do I have?

>

# Answer
> 1 votes
Please note that items in the cart are not products, but line\_items (referenced to the product of course)

I think this hook can fit your needs, but I haven't tested it (in my situation, I added the line item directly using custom functions in my module)

# Answer
> 0 votes
There are sevetal methods for this:

1. You can set the product title as you want on /admin/commerce/products page. Edit product and set your title.
2. You can set the product title in a moment you add it. To view this field the option 'Auto generate the product title' should be turned off on product display content type settings.
3. You can use the hook\_commerce\_cart\_product\_add() to set the product title automatically and (for example) depending on product type.

# Answer
> 0 votes
The answer depends on the nature of your 'linked promotions'. It might be that you should add an entity reference field to your line item type, then add the field to the shopping cart view. If your promotions are based on tagging products with taxonomy terms, it's as simple as adding the field to the cart view.

Or, as @Strae said, you could alter the line item's title via hook\_commerce\_cart\_product\_add. Yet another way would be to alter the line item's 'label' via Rules and show that in the cart instead.

---
Tags: 7, commerce
---


# Question
Title: Enable users to edit user profile and nodes in same page
In my project I would like my users to be able to edit their profile from the same page they view their profile.

In order words when they click on the fields or an edit button beside the fields, they will be able to enter a new value.

What I want to achieve is pretty much how users edit their profile on LinkedIn.

Please is there a module that can help me achieve this?

(Please note that I am displaying the user profile with "views").

# Answer
> 0 votes
Try these modules https://www.drupal.org/project/quickedit https://www.drupal.org/project/jeditable

And for views, use editableviews

---
Tags: nodes, users
---


# Question
Title: How to get the name of the month in local language in Drupal?
I want to display in a tpl.php file:

> 30 maart 2015, 11: 34

Currently i'm using below code

```
    <?php print  date("j-F-Y H:i") ?>

```

1) How to get the name of the month in dutch instead of english?

2) How to add the comma easily ?

# Answer
> 3 votes
Don't use the PHP `date` function, use the Drupal API: `format_date`. To add the comma, make it part of the pattern. To match your example `30 maart 2015, 11: 34`, the pattern is `j F Y, H: i`:

```
$timestamp = strtotime('2015-03-30 11:34');
print format_date($timestamp, 'custom', 'j F Y, H: i', NULL, 'nl');

```

For this to work, you need to have the core **locale** module enabled and Dutch translations on your site should be up to date (check that the names of months are translated inthe translation UI). The module **Localization Update** will help you with updating translations if you need to.

You can skip the last argument (`'nl'`) if the default language of your site is dutch.

---
Tags: datetime, i18n-l10n
---


# Question
Title: Keeping the <body> part in the CKEditor and removing everything else
I've naive customers who will need to copy the HTML part of email in Outlook. So I want them to copy and paste the HTML source of the email which includes \<html\> \<body\> \</body\> \</html\>.

Is there any filter which will remove all but keep only the content within the \<body\> part?

# Answer
> 0 votes
Oh it automatically filters out if we copy the whole html starting from \<html\> tag. So we don't need to do anything

# Answer
> 0 votes
Drupal's text format has an option for "Limit allowed HTML tags," in which you can specify which tags you would like to keep. You could always create a list of tags you use in your emails. If you exclude the html and body tags, that might work for you.

Another option is you can simply write your own text filter. You'll need to implement hook\_filter\_info.

Basiclly you would want something like:

```
function my_module_filter_info() {
  $filters['filter_name'] = array(
    'title' => t('Some Nice Filter Name'),
    'description' => t('Filter out stuff'),
    'process callback' => "your_filter_function",
    'cache' => FALSE,
   );
   return $filters;
  }

```

Then it's just a issue of writing your filter function.

```
function your_filter_function($body_text){
   //do stuff to your body_text to remove the tags you want to remove
   return $body_text
}

```

---
Tags: 7, wysiwyg
---


# Question
Title: How to create a new custom content type record when a user registers
My client's Drupal 7 website has a custom content type which is currently being used as a user profile. Now we need to incorporate this custom content type with the Drupal registration process. That is to create a user profile(a new record in custom content type) when a user registers. The User profile content type has many fields which asks for personal details and there are many views that are based on this content type. Therefore, I need to have this content type as it is but to incorporate this somehow with the Drupal registration process.

Is this doable?

# Answer
Since you are deeply in your project I see two possibilities right now:

1. **Site builder**

Add all the required fields to your user profile, and use something like complete\_profile to force completion. Maybe profile2 might help as well. Once you gathered a complete profile use rules to create a node of the content type you strive to create. Upon creation, you might want to drop the profile field contents etc., I think profil2 might be the better solution, so you don't have the to use drupals core profile, and can drop that filled profile once you don't need it, or even disallow changes after creation / hide fields of it etc.

2. **Developer**

try to get the node fields of the node add form for your specific content type and merge them with the registration form.

```
function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_register') {
     dpm($form);
     module_load_include('inc', 'node', 'node.pages');
     $node_form = node_add('nodetype');
     // $output = drupal_render($form);

     // this copying probably has to be done in a better way, e.g. by only the fields you need.
     $form['node'] = $node_form;

     // register a submit handler, so you can create the node/ do validation whatsoever
     $form['#validate'][] = 'mymodule_user_register_validate';
     $form['#submit'][] = 'mymodule_user_register_create_node';
   }
}

```

If your node form has a file upload widget, you should add the following lines to the menu array:

```
'file path' => drupal_get_path('module', 'node'),
'file' => 'node.pages.inc',

```

submit handler:

There are probably better ways to do this, e.g. reuse the existing node submit handler, instead of mimicking it's behavior.

```
// validation option 1: do it manually
function mymodule_user_register_validate($form, &$form_state) {
  // Extract the submitted data
  $name = $form_state['values']['node_title'];
  // Check it according to your own logic
  $is_valid_name = your_check_for_valid_name();
  // File error, when not valid
  if (!$is_valid) {
    form_set_error('name', t('Name already taken, please choose a different one'));
  }
}

// validation option2: forward it to node_submit
// this way you will have to mock a node object before though.
// node_validate($node, $form, &$form_state);

function mymodule_user_register_create_node($form, &$form_state) {
  $node = new stdClass();
  $node->type = 'nodetype';
  $node->title = $form_state['values']['node']['title'];
  $node->language = LANGUAGE_NONE;
  $node->uid = 0; // you probably have to somehow find out the created uid from the registration and link this here
  node_object_prepare($node);
  $node->field_something[LANG_NONE][0]['value'] = $form_state['values']['node']['sometextfield'];
  node_save($node);
}

```

This code is far from being ready to use (I just drafted it straight from my head, you will have to dpm() some values and see how it fits together, but the logic/ workflow is there.

extra: look at how `entity_form_submit_build_entity();` is used to see how core get's the form, form state values and creates an entity with the given input, instead of doing this by hand. Be aware that at that stage you probably have to make sure that everything required is available, which might be harder than doing that stuff in custom code in the first place.

extra2: to link this created node with the user created, you might want to put the created node id in global space and retrieve it in a hook that is called after user save.

```
  // mymodule_user_register_create_node() ...
  node_save($node);
  $GLOBALS['user_register_linked_nid'] = $node->nid;
  // ...

  function mymodule_user_insert(&$edit, $account, $category) {
    //maybe the submitted values are in $edit as well, than we dont have to do the node creation stuff in the user submit handler and we could do it here.
    // else you can still fetch the global variable
    if (isset($GLOBALS['user_register_linked_nid'])) {
    $account['field_node_reference'][LANG_NONE][0]['target_id'] = GLOBALS['user_register_linked_nid'];
    field_attach_insert('user', $account);
    }
  }

```
> 1 votes

# Answer
Rules module can be used here. 1. ON "After saving a new user account" - Perform actions like create entity of type node. set field values etc. Using rules interface. You don't have to write code for that. 3. ON "After updating an existing user account" - update the user profile fields. 4. ON "After a user account has been deleted" - delete the node entity. check this https://www.drupal.org/project/rules
> 0 votes

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


# Question
Title: How do I allow editors to select a template with CkEditor?
I am using CkEeditor to edit the node body field. I want to add a *Select template* option in CkEditor.

# Answer
> 1 votes
I suggest you have a closer look at the widget API / the widget plugin for CKEditor. The widget API enables you to have something like 'templates' meaning predefined groups of elements inside the editor window.

> "*Widgets are **special rich content units** in that they are **groups of elements** which are **treated as a single entity** inside the editor.*"

http://docs.ckeditor.com/#!/guide/dev\_widgets

At the end of that page there are links to further info about the Widget SDK and a step-by-step tutorial for creating your own widget ('mini-template').

I use the widgets plugin myself together with the SCALD module family and I must say I am still quite excited how very well these two play together.

If you 'just' want to add *content templates* however, you should probably download and install the Content Templates plugin for CKEditor.

From the download dialog window:

> *Extract the downloaded plugin .zip into the plugins folder of your CKEditor installation. Example:*
>
> *http://example.com/ckeditor/plugins/templates*
>
> *Enable the plugin by using the extraPlugins configuration setting. Example:*
>
> *config.extraPlugins = 'templates';*
>
> *Download and configure all its dependencies, too.*
>
> *Add-on Dependencies: Dialog*

The configuration setting can be found/added in config.js inside the ckeditor directory.

---
Tags: 7, wysiwyg
---


# Question
Title: How to allow users to create groups with Organic Groups
How do I allow users on my site to create groups. I've done the initial configuration of Organic Groups, there is no 'Create Group' button by default. I want users to be able to create groups under a Parent Group.

# Answer
> 0 votes
Groups are just a special kind of nodes, so you just need to go to Permissions and grant users the right to create nodes of that bundle. Users can create groups by going to `yourwebsite.com/node/add/nameofyourgroupnode`. There is also a menu link by default.

---
Tags: organic-groups
---


title: Problems with OG private groups

text:
# Question
Title: Problems with OG private groups
I've installed a drupal commons site (7.x-3.23). I'm trying to give ability to choose on group creation if the group content will be visible or not from non-members of the group. So i've activated organic group access control, rebuilt permissions, added in OG the field 'group content visibility' to the commons group bundle. When i go to the group content type i see the field so it must be OK. But when i create or edit a group, i never see the option for privacy content. I opened the fields settings in group content type for the content visibility, and all seems fine in spite of the default value which is not displayed.

Can you help me?

# Answer
There are two different fields:

* *Group visibility.* It only exists for Groups. It controls whether all group content is visible to non-members by default.
* *Group content access.* It only exists for Group content. It controls whether a particular node in the group is visible or invisible to non-members, or whether it should leave that decision to the default setting of the group.

Check whether your group has a group visibility field and whether you have the permissions to edit it, and if not, add that field via `/admin/config/group/fields` and grant the right permissions to edit it.
> 0 votes

---
Tags: organic-groups
---


# Question
Title: How to show "field-image" in search page?
I want make a photo gallery with Drupal. I have a problem with showing article images (that shows in homepage in a div classed "field-image"), I want show this image is search page. After searching for something just title and text shows, how to show images there? Thanks a lot :) look at this shots:

# Answer
> 0 votes
If you're using default core search, you can modify "Search result" display there.

# Answer
> 0 votes
You can override the search-result.tpl.php file and add some logic in your form pre-processing page (template.php), but all of this is quite a bit of work when you could rather just use the Display Suite Module.

1. Install the module.
2. Enable "Display Suite", "Display Suite Search" and "Display Suite UI".
3. Enable "Display Suite Search" on the search settings page: /admin/config/search/settings
4. Go to a searched term page: search/content/SEARCH\_STRING
5. You should now see a lot more info. As a final step, you can edit what is shown here by going to the settings page here: admin/structure/ds/list/search

---
Tags: entities, media, search
---


# Question
Title: How to loop over a list of Organic Group users using Rules
When a user requests to join an Organic Group, I want to send an email to the group's admins. I've found this answer (https://stackoverflow.com/questions/16742925/how-to-send-an-email-to-drupal-7-organic-groups-role-members/23301910) which helps with selecting users with the appropriate role, but I can't for the life of me get a list of just the users from the current group.

# Answer
You don't need any of that php stuff tenken is saying. Just install Rules, create a new rule reacting on a user joining a group and use the action "Get group members from group audience". For this to work, you'll have to add to the conditions in the rule that the node is in fact a group.
> 2 votes

# Answer
Sounds like you need to:

* define a new variable in your Rule called `$users_in_group`.
* use a `php script` step to use an `EntityFieldQuery` or Organic Groups API call to list the users in a Group.
* Assign `$users_in_group` to the result of your php-script business logic.
* Use a `Rules Loop` to loop over the result array of `$users_in_group`
* use a final `php-script` rules step to do the logic you describe in your link for the appropriate user.
> 0 votes

---
Tags: rules, organic-groups
---


# Question
Title: Farbtastic color picker to change the background color of text field input?
I have taken this JS from the field\_example module. I am attaching it to a form textfield element so that when a user brings focus to it the Farbtastic color picker widget pops up and allows the user to populate the field with the chosen hexadecimal color code. It works as expected. I was also expecting the background of the field to dynamically match the chosen color like this. However, it does not. In the linked example the text also turns black/white depending on the chosen color. This feature is also present in the color module.

I've tried adding to the code below, but nothing I try works. How can I adapt the JS below to achieve this? Thanks.

JS

```
/**
 * @file
 * Farbtastic color picker.
 */

/**
 * Show farbtastic colorpicker widget.
 */
(function ($) {
  Drupal.behaviors.my_color_picker = {
    attach: function(context) {

      $(".edit-my-color-picker").live("focus", function(event) {
        var edit_field = this;
        var picker = $(this).closest('div').parent().find(".my-color-picker");

        // Hide all color pickers except this one.
        $(".my-color-picker").hide();
        $(picker).show();
        $.farbtastic(picker, function(color) {
          edit_field.value = color;
        }).setColor(edit_field.value);
      });

    }
  }
})(jQuery);

```

Form element

```
'color' => array(
  '#type' => 'textfield',
  '#title' => t('Color'),
  '#size' => 8,
  '#suffix' => '<div class="my-color-picker"></div>',
  '#attributes' => array(
    'class' => array(
      'edit-my-color-picker',
    ),
  ),
  '#attached' => array(
    'library' => array(
      array(
        'system',
        'farbtastic',
      ),
    ),
    'js' => array(
      drupal_get_path('module', 'my_module ') . '/color-picker.js',
    ),
  ),
),

```

# Answer
> 1 votes
Something like this?

```
/**
 * Show farbtastic colorpicker widget.
 */
(function ($) {
  Drupal.behaviors.my_color_picker = {
    attach: function(context) {

      $(".edit-my-color-picker", context).on("focus", function(event) {
        var edit_field = $(this);
        var picker = edit_field.closest('div').parent().find(".my-color-picker");

        // Hide all color pickers except this one.
        $(".my-color-picker").hide();
        $(picker).show();
        $.farbtastic(picker, function(color) {
          edit_field.val(color);
          // background color, may need to add # to color.
          $(edit_field).css("background-color", color);
        }).setColor(edit_field.value);
      });

    }
  }
})(jQuery);

```

Notice I added 'context' to the original selector and changed 'live' to 'on'. Live function is deprecated as of jquery 1.7.
I also changed it so the edit\_field variable stores the jquery object.

Drupal does already have a couple of color fields, on of which is HERE

# Answer
> 0 votes
Here's my solution:

```
/**
 * @file
 * Farbtastic color picker.
 */

/**
 * Show farbtastic colorpicker widget.
 */
(function ($) {
  Drupal.behaviors.my_color_picker = {
    attach: function(context) {

      $(".edit-my-color-picker").live("focus", function(event) {
        var edit_field = this;
        var picker = $(this).closest('div').parent().find(".my-color-picker");

        // Hide all color pickers except this one.
        $(".my-color-picker").hide();
        $(picker).show();
        $.farbtastic(picker, function(color) {
          edit_field.value = color;
          $(edit_field).css("background-color", color);
          $(edit_field).css("color", $.farbtastic(picker).hsl[2] > 0.5 ? "#000" : "#fff");
        }).setColor(edit_field.value);
      });

    }
  }
})(jQuery);

```

---
Tags: javascript
---


title: getting form title

text:
# Question
Title: getting form title
I have a form created by using custom module, I can get all the fields but now how should I get the form title? below is the code to get the specific field in `.module` file.

```
$form['name'] = array(
 '#title' => 'NAME',
'#type' => 'textfield',
);

```

# Answer
> 0 votes
You can either create a fieldset and use the #title property to create a legend tag, you'll need to prefix the form element with the fieldset, e.g.

```
$form['group'] = array(
  '#title' => t('TITLE'),
  '#type' => 'fieldset',
);

$form['group']['name'] = array(
  '#title' => t('NAME'),
  '#type' => 'textfield',
);

```

Alternatively, you can use markup to include any HTML you want.

# Answer
> 0 votes
The title of a form is not a form element - you set it depending on where the form is used - e.g. as a `'title'` set in `hook_menu` (docs) or `'info'` in `hook_block_view` (docs).

You can use drupal\_get\_title and drupal\_set\_title to get/set it.

---
Tags: forms
---


title: Verify an entity is translated

text:
# Question
Title: Verify an entity is translated
I want to add a "add translation now" button on nodes and other entities too. I'm using the Entity translation module, and I added two languages to the site.

I thought about getting the original translation and then loop through the translation data, checking if there is more than just the original language inside.

Is there a better way to do this?

# Answer
> 1 votes
Actually if you are doing field translation then there is no point of having translate now link at Node level. For this there is always translate primary tab for this. see in screenshot.

Still if you want to achieve this functionality, loop through this array within node object.

```
$node->translations->data

```

Do this in module file in `hook_preprocess_HOOK` here it will be `hook_preprocess_node` and pass a variable to `node.tpl.php`

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


# Question
Title: unable to see drupal home page when configured live site into in my local system?
> I need to configured my live site into local system, I had configured database, settings.php and enable module rewrite and .htaccess file also there in my root folder etc.
>
> But I'm unable to see the my site home page it's showing blank page, please help me I'm new to drupal.

# Answer
> 0 votes
Try adding

```
error_reporting(E_ALL);
ini_set('display_errors', TRUE);

```

in index.php file, that will be showing the actual error on front page.

# Answer
> 0 votes
I think your local apache might need configuration.

The best way to avoid these type of errors is to set up a virtual host for your local site so that your URL is like this: http://sitename.dev (That's what I do for all my local sites).

I can see in your screenshot you have http://192.168.1.98/sitename so maybe apache is pointing to the wrong place.

Also check your apache error log to see what error you are getting.

---
Tags: theming
---


# Question
Title: How to display an overlay image in modal window (Colorbox) upon hover
I have a series of images set up to display in modal lightbox-type windows – specifically, using the Colorbox module.

* The goal is for each image to be paired with a companion graphic overlay which is displayed upon hover over the Colorbox display.
* Think of it as (1) the photo, and (2) the "circles and arrows" overlay (maybe .gif or .png with transparent whites).

**Can anyone verify its feasibility and suggest a path to this result?**

# Answer
> 0 votes
You would probably have to write some custom javascript / jquery in your theme's JS file and call the colorbox function on hover. For example:

```
$('.img-1').hover(function(){
  $('.img-2').colorbox();
});

```

That's only the starting point. Once it is working with just 2 images, the next step would be to dynamically pair all the images so the javascript knows which image to show on hover.

---
Tags: javascript, modal-dialogs
---


# Question
Title: How to override formatting for a CCK field?
I have a CCK field called "stock". I dont want visitors of the website to see the value of "stock". I want them to see either "In Stock" if the value is more than 0, or out of stock if the value is less than zero.

Any idea how I can do that without actually editing the node display template?

# Answer
> 3 votes
Depending on the type of the field you are using, there are template files for those as well e.g. a number field (field--number-decimal.tpl.php). that way you would only have to override the field template, rather than the node template.

# Answer
> 2 votes
Have you looked at Display Suite? You can create custom fields based upon different scenarios, etc.

---
Tags: entities
---


# Question
Title: How to Add Previous/Next Navigation on Teaser based on Views?
I have created a teaser based on views but don't know how to add a previous/next navigation. I have tried Views Navigation but it is for node only. The one that I am looking for is similar to the previous/next navigation with numbers in the front page.

Any help is greatly appreciated.

# Answer
I think you're looking for a Pager, there are standard paging options in Views or you might need something more complicated like Pagerer or perhaps Views Simple Pager
> 1 votes

---
Tags: 7, navigation
---


title: Change user ID of existing users

text:
# Question
Title: Change user ID of existing users
When I check my users list via by ID, I get IDs like these:

* User: admin
Id: 1
* User: second user
ID: 11
* User: another user
ID: 21

I want them to be consecutive numbers from 1 to N.

What's my problem? How can I fix it?

# Answer
> 4 votes
While updating the user id is **not recommended**, for arguments sake, you could reset the user id column in the database.

**This is with the caveat that you must also update all referencing tables that use that user id so that those tables also use the new user id value - to maintain "referential integrity". Otherwise, if you do not update all the related user ids, you will corrupt and mixup private user data**

For example, the `users_roles, file_managed, node, node_revision` and other tables...

To match the users with the new uid, you could make an export first of user id to email address. Then you can make another export later and cross-reference the uid from the mail address - to check the new user id match. Keep in mind email address isn't strictly unique in drupal by default.

```
SELECT uid, mail FROM users;

```

Backup the users table first.

Then you could do something terrible like:

```
ALTER TABLE users DROP COLUMN uid;
ALTER TABLE users ADD uid INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;

```

That will obliterate and regenerate the users uid column.

UPDATE: As clarified by Berdir, curiously the user id field is *not* an autoincrement field in Drupal 7 by default. So, you may need to remove the autoincrement property after the UID sequence is recreated and convert to normal int with:

```
ALTER TABLE users MODIFY uid int(10) unsigned;

```

Note: you will need to regenerate the anonymous user account with:

```
INSERT INTO users (name, pass, mail, theme, signature, language, init, timezone) values ('', '', '', '', '', '', '', '');
UPDATE users SET uid = 0 WHERE name = '';

```

If you just want to hide the uid field value, you could instead try a user alias module like:

https://www.drupal.org/project/me

# Answer
> 4 votes
The user ID in Drupal 7 and 8 is *not* an autoincrement, it is based on db\_next\_id(). That means it is shared with e.g. batch ID's and is the reason it does not count up like node IDs.

Changing this is close to impossible, you would not only have to manually update the users, the users\_roles, all user field tables, all references to users (like node and comment author, entity reference fields, and so on) but you would also have to reset the global sequences table for db\_next\_id(), which could break other places in Drupal if they've been using db\_next\_id() and are relying on it to be unique.

So, no, you can't.

# Answer
> 2 votes
No, you can't, or you should not. The user id is an autoincremental value of the users table in the database. And every information about the user (nodes, field values and any other thing) is related to the user with the UID.

# Answer
> 1 votes
It always amuses me when some people arrogantly state that "it cannot be done" and "should not be done" without fully understanding what they are talking about.

Changing a user's UID CAN be done and sometimes SHOULD be done. In my case, while migrating a database, its state became inconsistent because of a user's UID not matching its content. And instead of changing UIDs in thousands of nodes, it was much easier to change it on a users table.

Fixing it with drush was pretty easy:

```
drush sqlq "update users set uid=4 where uid=6"

```

Might have to do the same with the `users_roles` table as well, and other tables depending on modules that impact the users tables (eg. access control, etc.)

If you're not fixing consistency issues, you should have a very good reason for changing an UID and know what you are doing, or you may leave your database in an inconsistent state.

# Answer
> 0 votes
The fact that UID auto-increments and Batch API auto-increments are shared is a shortcoming. For one project I am developing, I am considering adding a serial field and attach it to the User profile. This way I will have logical incremental & consecutive reference to site's users.

I have just had a jump from user id 14 to 1123 without deleting any user, only due to the shared auto-increments.

---
Tags: 7, users
---


# Question
Title: How to change the order of date module fields on edit by language?
By default, when editing a date field that includes day, month, and year, there are dropdowns displayed in day-month-year order. This is good for English, but for users whose language is set to Japanese, I would like to show the edit dropdowns in year-month-day order. Is this possible?

I'm on Drupal 7.

EDIT: I attempted to edit the locale format but I wasn't able to get it working.

Under localize, I set the following values for Japanese:

I then confirmed that the field was set to display dates using the short format:

I then cleared my cache twice and reloaded. However, the edit widget (a date field on the user profile registration page) still displays dates in day/month/year format for both languages.

# Answer
I came across the issue today. Found there is an option to change the date format for Date field.

FYI: It is under "More Settings". Cheers
> 3 votes

# Answer
Yes, Edit locale format in

```
admin/config/regional/date-time/locale

```

for different languages.

The widget is smart enough to adjust for you base on your time format settings.

Before:

Adjustment:

After:
> 2 votes

# Answer
You also can easily change it if you don't depend on site-wide date settings. If so - just go and change "short" date format (just an order of days and months) at admin/config/regional/date-time. Webform (and other #type = 'date' fields) will use the same order for its date fields.
> 1 votes

---
Tags: datetime
---


# Question
Title: Panels - Style region to become a drop down/expandable menu
Please see: http://drupal.org/project/tableofcontents

I am using Panels and would like to style a panels region so I am able to hide/show just like the TOC module above.

I have looked on Drupal downloads for a module, but none work the way I want.

Any suggestions? Thanks for your time!

# Answer
I solved this by using the following module & some code:

http://drupal.org/project/panels\_extra\_styles

Panels region \> Change style \> Wrapper: raw.

**Content prefix:**

```
<script type="text/javascript" src="/misc/form.js"></script>
<script type="text/javascript" src="/misc/collapse.js"></script>
<form>
  <div>
    <fieldset class="collapsible form-wrapper">
      <legend>
        <span class="fieldset-legend">Attachments</span>
      </legend>
        <div class="fieldset-wrapper">

```

**Content suffix:**

```
        </div>
    </fieldset>
  </div>
</form>

```

Save and update. Voila!

References: Supplied if needed.
> 1 votes

# Answer
Now there is a module for that: https://www.drupal.org/project/panels\_style\_collapsible
> 0 votes

---
Tags: panels, theming, navigation
---