# Question
Title: Drupal Form in Block will NOT call Submit or Validate handlers
Let me start by saying I have seen quite a few similar threads, and I have tried everything I've found so far, with none of them working.

My brother wanted a contact form to be in the footer of his site, so it gets rendered on every page. I didn't think this would be an issue, so I created a custom form and rendered it in a block. It looks great, but when I went to add in the validation and submit handlers, none of them work.

Here is what I currently have.

```
function opal_contact_form() {
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => 'name',
    '#required' => true,
    '#default_value' => '',
    '#attributes' => array('placeholder' => 'Name'),
  );
  $form['email'] = array(
    '#type' => 'textfield',
    '#title' => 'Email',
    '#required' => true,
    '#default_value' => '',
    '#attributes' => array('placeholder' => 'Email'),
  );
  $form['phone'] = array(
    '#type' => 'textfield',
    '#title' => 'Phone',
    '#attributes' => array('placeholder' => 'Phone'),
    '#default_value' => '',
  );
  $form['company'] = array(
    '#type' => 'textfield',
    '#title' => 'Company',
    '#attributes' => array('placeholder' => 'Company'),
  );
  $form['topic'] = array(
    '#type' => 'textfield',
    '#title' => 'Topic',
    '#attributes' => array('placeholder' => 'Topic'),
    '#default_value' => '',
  );
  $form['message'] = array(
    '#type' => 'textarea',
    '#title' => 'Message',
    '#required' => true,
    '#default_value' => '',
    '#rows' => 3,
    '#attributes' => array('placeholder' => 'Your message...'),
  );
   $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );

  //$form['#submit'][] = 'opal_contact_form_submit';
  //$form['actions']['submit']["#submit"][] = "opal_contact_form_submit";
  kpr($form);
  return $form;
}

function opal_contact_form_validate($form, &$form_state) {
  kpr($form);
  dd('this is from the validate');
  exit();
}

function opal_contact_form_submit($form, &$form_state) {
  kpr($form);
  dd('this is from the submit');
  exit();
}

```

I don't think this is relevant, but here is the block rendering part.

```
function opal_blocks_block_view($delta) {
  $block = array();

  switch ($delta) {
    case 'contact_form':
      $block['subject'] = t('');
      $block['content'] = build_contact_form();
      break;
  }

  return $block;
 }

 function build_contact_form() {
   $form = drupal_get_form('opal_contact_form');
   $html = drupal_render($form);

   return $html;
 }

```

The parts commented out in the form definition are suggestions I found elsewhere and tried. I've never had to do anything special for a standard page form, except add \_validate and \_submit to the name of the form in order to get a validation and submit handler to work. Perhaps things work differently when rendered in a block?

Any suggestions would be appreciated.

**EDIT**

I found the problem in a theme function that I didn't include in the initial post cause i didn't think it would have anything to do with it, but I obvious was wrong. I am still not sure why this is causing the problem, but when I comment it out, it works fine. I just wanted my form to be displayed in 2 columns.

```
function opal_blocks_theme() {
  return array (
    'opal_contact_form' => array(
      'render element' => 'form'
    ),
  );
}

function theme_opal_contact_form($variables) {
  $form = $variables['form'];
  $output = '';
  $output .= '<h2>We would love to hear from you:</h2>';
  $output .= '<div class="form-left col-sm-6">';
  $output .= drupal_render($form['name']);
  $output .= drupal_render($form['email']);
  $output .= drupal_render($form['phone']);
  $output .= drupal_render($form['company']);
  $output .= '</div>';

  $output .= '<div class="form-right col-sm-6">';
  $output .= drupal_render($form['topic']);
  $output .= drupal_render($form['message']);
  $output .= drupal_render($form['submit']);
  $output .= '</div>';

  return $output;
}

```

# Answer
> 1 votes
You forget to render technical form fields: `form_id, form_build_id, etc.` As fix I suggest you to add the following to your theme function:

```
$output .= '<div class="element-hidden">' . drupal_render_children($form) . '</div>';

```

# Answer
> 0 votes
Those are the only 3 differences I can see between (working) block forms I have written in the past and your code.

1) What are the `exit();` lines there for? Maybe try removing those?

2) I usually also define `$form` and `$form_state` in the original form function.

3) I do usually add the render array straight to the block content, maybe prerendering that as html causes some interference? (bit unlikely but worth a try)

```
function opal_blocks_block_view($delta) {
  $block = array();

  switch ($delta) {
    case 'contact_form':
      $block['subject'] = t('');
      $block['content']['form'] = drupal_get_form('opal_contact_form'); // Block content can handle renderable arrays, saves you a couple of lines of coding
      break;
  }

  return $block;
 }

```

---
Tags: 7, forms
---


# Question
Title: OG: Only allow certain Drupal roles to join a group
I think this might be a very simple setting I am missing somewhere, but I want to prevent people from joining an 'Organic Groups' group unless they have a particular Drupal role. The 'subscribe to group' permission in the group obviously only applies to OG roles, not Drupal's core roles.

I can't see any permission in Drupal's core for 'join group type', which I would have expected.

Any ideas?

# Answer
I don't think that functionality is packaged with OG on its own.

Are you looking to map certain Drupal roles to certain groups or only have the ability to apply to a group available to certain roles?

I would think this hook is a place to start: http://www.drupalcontrib.org/api/drupal/contributions%21og%21og.api.php/function/hook\_og\_permission/7

But here is a list of all hooks you can use with OG: http://www.drupalcontrib.org/api/drupal/contributions!og!og.api.php/7
> 0 votes

---
Tags: organic-groups
---


# Question
Title: How can I properly duplicate Fields on entities?
I have an entity that has an image field attached to it. This field can hold multiple images. I would like to be able to display a single/first image with one field formatter from this field at one place and all images with another formatter from this field in another place.

~~So I need to somehow clone this field, most likely via custom configuration to store some basic data and attaching it via hook\_entity\_base\_field\_info().

What I am not sure about is how to use the proper field type for this "computed" field so I can use proper field formatters, how to set proper source of data(the original field) and how to properly use isEmpty() method on that field so this field won't show up if the original field is empty without using my own field class to do that(since I would lose the compatiblity with proprr formatters).~~

---

Sorry, that was a bit misleading. I only need to be able to display the field with different formatter which means I only need another instance of that field in the entity\_view\_display.

---

hook\_entity\_extra\_field\_info() seems like the best solution, but it does not allow formatter settings.

# Answer
> 1 votes
One way of doing this is in the theme layer. In this approach you don't need to have two fields. You could have a single Images field, and in a node template preprocess function you can break it up into two separate variables that are provided to the \*.tpl.php file. So you could take the rendered output of the first image, put that in one place, and the rendered output of the rest of them could go somewhere else.

# Answer
> 0 votes
You can try to use the `view()` method directly, with two different view modes or custom settings.

Getting rid of all field items except the first is a bit complicated, but it's probably easier than trying to create a new field item list object from scratch.

Something like this:

```
$first_field = clone $entity->field_name;
// The list enforces a strict numeric list, so keep unsetting index 1 until it no longer exists.
while (isset($first_field[1])) {
  unset($first_field[1]);
}

$first_image = $first_field->view($view_mode_or_settings);

$other_items = clone $entity->field_name;
unset($other_items[0]);
$remaining_images = $other_items->view($view_mode_or_settings);

```

Alternatively, depending on what you want to achieve, you can also try to alter the render array structure. Like almost all field formatters, you get a render array back, keyed by the numeric field data (use Element::children() to loop over them). Inspect it and for example switch out the used image style.

---
Tags: entities, 8
---


# Question
Title: Is it possible to show views exposed filters in the facet current search block?
I have a facet search with Facet API, Search API, and a Solr backend with the Search API Views integration. I am using the Current Search block (part of the Facet API module) to display the currently selected facet options.

However, I am also using Views, and I have two exposed filters with the autosubmit button on the page. **The problem is that users can select one of the views exposed filters and it will not appear in the Current Search block, so it is not obvious to the user that the results are being further filtered.**

I am also using Facet API Pretty Paths, so I have a path that looks like this:

> myexample.com/s/n/1/b/2&items\_per\_page=8&jp=1&d=-

`n/1` and `b/2` are facets, `&items_per_page=8` is the views pager, and `&jp=1` and `&d=-` are the views exposed filters.

My goal is to somehow make it clear to the user that Views exposed filters are affecting the results. If it's possible to modify the Current Search block, I would like to do that, but if not, creating a separate block/ctools content type to notify the user that the exposed filters are applied would also be acceptable.

I'm not aware of any modules that show the applied exposed filters, so I'm thinking about writing code to check the query string for `jp` and `d` and then printing messages based on the results. If there is an easier approach, I would be glad to hear it.

# Answer
This wouldn't add it into the Facet block, but you could just do the exposed filters in a block and put the exposed filters block near the Facet block (screenshot from the Advanced section of the View):
> 0 votes

---
Tags: views, search
---


title: Unable to Get Image to Un-Cache

text:
# Question
Title: Unable to Get Image to Un-Cache
I've replaced an image on my home page with another image. I've verified that the new image is there (with the same name as the old image). And it's the only copy. I've run cron and cleared caches multiple times but the old image is still showing!

I'm using the following modules: Advagg Global Redirect Cache Expiration (File update set under File Actions) Elysia Cron Boost Boost Crawler HTTPRL Metatag Metatag: Views XML Sitemap

Anyone know what might be causing the problem?

# Answer
Ok, well, I don't know what the problem was. I tried everything I could think of (see above). So I just changed the name of the image in 'default/files' and changed the name of the file in the link to it in the block. Now it's showing correctly.
> 0 votes

---
Tags: caching
---


title: Multilanguage Website

text:
# Question
Title: Multilanguage Website
I'm trying to run some script from Pinterest, to validate my site.

What's happenning is I need to write in Pinterest the url of my site, but my site redirects always like this : "XXX.com/es". How can I avoid that for this test made it by Pinterest.

I also can include on HTML file given by Pinterest but that would be the same, since again my website **adds the language** (=es) at the end of the path.

# Answer
I'm pretty sure your question is about a "multilingual" site, and not really about "multi sites". Consider editing your question (title, tags, etc) accordingly.

Moreover, your question is a variation of these types of questions, and that your issue is actually caused by a language detection issue (something you have not yet configured correctly in your site. Consider updating your question as appropriate. After doing so, I can also update my answer here, to actually pinpoint what kind of admin changes you might have to apply to achieve the desired result.

Based on the info provided in your question for now, I wonder what the DEFAULT language is that you specified within /admin/config/regional/language of your site. Could it be that it is "es"? If so, and if you also have enabled the "en" language, then change that default to "en" and retry again. Eventually, change the default language back afterwards, to whatever it was before (whenever your Pinterest script no longer requires you to (temporary) change that default language).

You may also want to check your configuration at *Configuration -\> Languages -\> detection and selection*: the order should be 'URL, Default, User', and not something like 'Default, URL, User'.
> 1 votes

---
Tags: i18n-l10n, external-scripts
---


# Question
Title: Getting WSOD after attempting to upload an images from desktop
I am unable to upload an image from my desktop in Drupal 7. I am trying to upload an image to a blog without using Ckeditor. I have created a field for the image and assigned it as image. All looks good. The problem happens when I go to create a new blog, I see the field for the image. I click on the "Choose file". It brings me to my desktop. I select the image and then click onto "Upload". The small blue wheel begins to spin. Then I get the WSOD. I see, in Firefox, at the bottom of the page "Transfering data from XXX.com..."

# Answer
> 0 votes
If you are trying to upload some bigger images, it is possible that you are out of memory.

Processing large photos requires lots of power and memory. Set the RAM with php\_value memory\_limit 128M or 256M if your hosting allows.

# Answer
> 0 votes
Found my answer. It was not a PHP issue but rather a JQuery issue. I did not install the JQuery module originally. Once uploaded and enabled, all of my JS, JQ, and so on,were cleaned up and updated.

---
Tags: media, wsod
---


# Question
Title: How can I make web scraping of a field more difficult?
I have a text field that I get with `<?php print render ($content['field'][0]['#markup']); ?>` in node.tpl. I'd like to somehow make loading the markup require a click, and deselecting it to put the placeholder markup back. It's a select dropdown if it matters.

I thought javascript might work, to test if scripts worked in node.tpl I tried

```
var test ="<?php print render ($content['field'][0]['#markup']);?>";
document.write(test);

```

but it loaded the markup for every node on the page in one line. My php/js skills are weak so I'm hoping there's a module that might help me. I'm open to any suggestions though.

# Answer
> 0 votes
You can try to do something like this:

```
<div class="hidden-text">
<span class="text-change">Your Placeholder</span>
</div>

<script>
jQuery.noConflict();
(function ($) {
$(function(){
$(".hidden-text").click(function () {
    ($(".text-change").text() === "Your Placeholder") ? $(".text-change").text("<?php print render ($content['field'][0]['#markup']);?>") : $(".text-change").text("Your Placeholder");
});
});
})(jQuery);
</script>

```

---
Tags: 7, javascript, entities
---


# Question
Title: How can I override the fivestar title attribute without hacking the module?
It's line 4 of this part of fivestar.module:

```
$options = array('-' => t('Select rating'));
for ($i = 1; $i <= $element['#stars']; $i++) {
$this_value = ceil($i * 100/$element['#stars']);
$options[$this_value] = t('Give @title @star/@count', array('@title' => $title, '@star' => $i, '@count' => $element['#stars']));}

```

It creates a verbose title on every star. I tried this javascript

```
var elements = document.getElementsByTagName('a');

for (var i = 0, len = elements.length; i < len; i++)
{
  elements[i].removeAttribute('title');
}

```

but it doesn't affect these links. I even tried doing it inline at the bottom of html.tpl. Is there a function I can use in template.php? Full file if it helps.

# Answer
> 0 votes
The reason your javascript didn't work is simple. If you disable Javascript and load the page with the fivestar widget, it's just a simple `<select>` list. It's turned into a clickable star widget using Javascript as well. So your js was most probably being overridden by fivestar.

You can do this without hacking the module and without using javascript by creating another custom module, but there's a small issue explained at the end. Lets call the module **myfivestar** for example.

You would then need to implement `hook_element_info_alter()` to change the fivestar element's process callback to your own custom one:

```
function myfivestar_element_info_alter(&$type) {
  // Change the process callback of fivestar to myfivestar_expand
  if (isset($type ['fivestar']['#process'])) {
    $type ['fivestar']['#process'] = array('myfivestar_expand');
  }
}

```

Now you just need to copy the function fivestar\_expand from the fivestar.module to your own module, rename it to myfivestar\_expand, and change the line:

```
$options[$this_value] = t('Give @title @star/@count', array('@title' => $title, '@star' => $i, '@count' => $element['#stars']));

```

to:

```
$options[$this_value] = ''

```

which will effectively make the `<select>` list useless for visitors browsing with Javascript off as it removes the option labels which are then turned into the title attribute using fivestar's javascript.

---
Tags: 7, rating
---


title: Phonegap user login

text:
# Question
Title: Phonegap user login
I am trying to login from a PhoneGap application. For that purpose, I've got the below code:

```
$('#submit').click(function () {
    $.ajax({
        url: 'http://dev-7.webcinizim.com/services/system/connect.json',
        type: 'POST',
        dataType: 'json',
        data: $('#form').serialize(),
        success: function () {
            alert('Login successful');
        },
        error: function (e) {
            alert('err');
        }
    });
});

```

I also followed this tutorial and created a service. I am always getting **Login successful** even if I feed wrong credentials on purpose.

Any ideas what I am doing wrong?

# Answer
> 1 votes
I'd recommend utilizing jDrupal or DrupalGap, they'll make your life so much easier if you're building a mobile application for Drupal with PhoneGap. Otherwise, to login via Services do a **POST** to **?q=\[my-endpoint\]/user/login.json** and set the header **Content-type** to `application/x-www-form-urlencoded` and send along the following data.

```
{
  username: 'bob',
  password: 'secret'
}

```

Note, you *may* have to instead append the credentials to the path that you are POSTing to, and not send along a JSON object, for example:

```
?q=[my-endpoint]/user/login.json&username=bob&password=secret

```

The code that you have is just doing a System Connect, which returns information about the current session, and whether or not the user is logged in, it does *not* have anything to do with actually logging in.

# Answer
> 2 votes
You're not doing anything wrong. When your success callback function is called, it only means ***it was successful POSTing the data*** to your endpoint `http://dev-7.webcinizim.com/services/system/connect.json`, not that you were successful logging in.

You need to add an argument to your success callback (i.e. `success: function(data) {`) and process that data to see whether login was successful.

---
Tags: 7, services
---


# Question
Title: How to provide link to styled image in a services feed
On our Drupal 7 site, we use the the services module to provide a feed for our internal news to pick up. With services, you create a view for all the data to provide. It is current giving the location of the original image for our images field (File: Path) that comes out http://oursite.com/sites/default/files/post.jpg. We want to provide a link to the styled image (already resized) that should look like https://oursite.com/sites/default/files/styles/downpage\_art/public/field/image/solar\_panels700x425.jpg?itok=P4VrgCIH. I don't see this as an option in the view we have for our feed.

# Answer
> 1 votes
I think the Image URL Formatter module will help.

> Image URL formatter module offers 3 options that are not contained by views:
>
> * support Image styles
> * support multivalues, there is a "Multiple field settings" when image field is multivalue.

# Answer
> 1 votes
I'd recommend utilizing the Views Datasource module or the Services Views module. Both will allow you to set up a View to be consumed over a RESTful API. You can then use the View to easily select your image field(s), and the image style(s) to use.

Otherwise you'll need to implement hook\_menu(), and create a custom item with a `page_callback`. That page callback can then programmatically generate an image style URL, and output it with drupal\_json\_output.

---
Tags: views, media, services
---


# Question
Title: Hide an entire View Block when query returns no data
I have a view block and - because of the filters being applied - it may show data or may not. If the view's query returns no results, I need to hide the entire block - the `.block` \- not just the `.view` or `.view-content`. I've seen several other questions and pages that offer solutions but all either don't hide the entire `.block` or just flat out don't work.

The solution that appears to be most discussed uses the `Global: Null` contextual filter, but that **always** hides the entire block regardless of any other condition. In fact, it doesn't even run the query when this filter is active. I need the block to be hidden if and only if the query returns no results.

I have the default, barebones Drupal 7 installed with only Bartik, CTools and Views so I am sure there aren't any other conflicts coming in from the theme or other modules.

# Answer
**One of the solution is:**

Under *FIELDS:* click each field and in the *"No results text"* area, check the *"hide if empty"* box.

This will allow the field not to show if there is nothing actually there to show. But will not affect how the block itself displays on the page.

**Another solution for this is :**

> 1. Go to the advanced tab of you view
> 2. Add contextual filters
> 3. Select Global: Null
> 4. When the filter value is NOT available: Select 'Hide view'
> -1 votes

---
Tags: views
---


# Question
Title: How to let site member to access vertical tab?
How to let site member access the picture above?

# Answer
It depends on which tab you're talking about. The highlighted one, **Menu settings**, is controlled by the *Administer menus and menu items* permission. Many of the vertical tab items is granted by the *Administer content* permission.
> 1 votes

---
Tags: 7, users
---


# Question
Title: How to display fields horizontally in a node?
A node lists all its field vertically one after the other by default. Does anyone know of a way to display at least some of the fields horizontally?

Like so:

```
FIELD 1               FIELD 2              FIELD 3

```

# Answer
You can use the css for that.You can aligned them horizontally using the float:left css property or may be you can use the display suite module for this.
> 1 votes

# Answer
The default behavior of Drupal's field display is to wrap the content in DIVs, which are displayed as block-level elements by default, hence, one per line.

There are a number of different ways to solve for your display needs.

As Sidharth mentioned, displaying fields can be done via custom CSS. Typically you'd want to create a custom node.tpl.php for your theme and apply your CSS rules to those elements in your template.

Another solution, if you're not looking for custom templates for different node types, is the Field Group Inline module.
> 2 votes

---
Tags: entities, nodes
---


title: Cron running by itself?

text:
# Question
Title: Cron running by itself?
My Drupal 7 instance was getting slow. I realised that the problem was a cron job running. However, why is cron running when I'm browing the site? It shouldn't be, surely? It should only run when I run cron.php.

I don't have poormanscron running or anything else that I am aware of that could be kicking off cron. Any ideas of what could be causing this on Drupal 7?

# Answer
In Drupal 7 cron is run by Drupal by default.

You can configure it at: admin/config/system/cron

It is preferable to disable that cron and run it automatically from the server in some way. That method is really only preferable if for any reason you have no other choice.

That said, you really should be automatically running cron regularly. Not necessarily every hour but at least once a day.
> 2 votes

---
Tags: cron
---


# Question
Title: Changing the From Address with the Printer, email, and PDF versions module
I'm using the Printer, email, and PDF versions module. On all my 'resource' nodes (resource content type) I have a link now that says 'Send by Email'. Great. But when it sends the email it's sending it with a'from' address as MY email (the site admin). I'd rather it be the email of the person who's sending the resource. There is an email field on that form they have to fill out to send the resource to someone else.

Anyone know how to make the email they use for THEIR email in the form be the 'from' email to whomever they are sending this resource?

# Answer
It's in **Administration » Configuration » User interface » Printer, email and PDF versions**, as the **Use Reply-To Header** option.
> 0 votes

---
Tags: 7, emails
---


# Question
Title: Add html to wrap custom panels layout programaticly
How to add html to wrap custom panels layout programaticly? I know that i can change html in \*.tpl.php but i want to avoid it. Also i want to know, how to add class to panals programaticly too.

UPD: I create custom panels layout and want to add html with custom class to wrapp regions of custom panel layout. I found good decision to use module Semantic panels, but it add markup to field, not to whole region.

This is part of my html

```
 <?php if ($content['left'] || $content['middle'] || $content['middle_two'] || $content['right']): ?>
    <div class="row">
         <div class="col-xs-12 col-md-3 col-lg-3">
            <?php print $content['left']; ?>
         </div>
    </div>
  <?php endif ?>

```

I want to make it like that

```
 <?php if ($content['left'] || $content['middle'] || $content['middle_two'] || $content['right']): ?>
    <div class="row">
         <div class="col-xs-12 col-md-3 col-lg-3">
           <article class="$custom_class">
            <?php print $content['left']; ?>
           </article>
         </div>

    </div>
  <?php endif ?>

```

UPD2: I try to add variable through themenaame\_preprocess\_panels\_pane, but it doesn't appear in .tpl.php file.

Code

```
function dmits_preprocess_panels_pane(&$vars){

```

$vars\['custom\_article\_class'\] = 'seriveces-wrapp'; kpr($vars);

}

# Answer
The module suggested (in a comment) by Danny Englander helps me (thank you!).

I.e. module drupal.org/project/panels\_extra\_styles

Since Dany only posted it as a comment, I'm adding it as a "real" answer (so that I will also be abe to "mark it as accepted".
> -2 votes

---
Tags: 7, theming, panels
---


# Question
Title: Receiving two subscriptions emails when run cron using rules
I need to send subscriptions immediately to users upon updating content. It is sending one subscriptions email when I run cron manually. But, when I run cron using rules, it send two subscriptions emails.

I have checked and found that I get one email only when I use rule to send test email.

Subscriptions setting: Users are not subscribed to content type...they are subscribed to taxonomy terms only.

Using modules for mail setup: 1. Mail system. 2. Mimemail. 3. Subscriptions. 4. Mail templates.

How can I send one subscriptions email only to each users upon updating content?

# Answer
> 1 votes
I finally solved this. I noticed that it was rules who was getting trigger two times. This link help me. I thetrigger me to disable another rule on same event condition.

---
Tags: rules, notifications
---


title: Currency module step by step guide

text:
# Question
Title: Currency module step by step guide
I want to provide a block where user can convert the currencies as desired and get the latest conversion rate.

I'm using Currency module. But there is no any set up guide for it, so I'm unable to use it. Can somebody tell me how to set it up?

If it is not possible in this module, is there any other module?

# Answer
> 1 votes
You can also use below modules :

1. Yahoo! Finance currency converter

> This module provides Currency with currency exchange rates through Yahoo! Finance, which are updated continually throughout the trading day.

2. Currency Converter

> Currency converter module was created for quick currency convertation. It contains 10 currensies.
>
> It is flexibly configurable block. The currency undertakes from several banks (on a choice).

3. Open Exchange Rate Money.js

> This module provides support for the money.js currency conversion script from http://josscrowcroft.github.io/money.js/ along with support for the Open Exchange Rate currency conversion data.

4. Exchange Rate

> Exchange Rate API is an extensible module that allow users to display and manage the exchange rate in countries from around the world.
>
> Is common to see tools that present the official exchange rate, the problem is that each bank has his own rate, for this reason it is important to have a tool that can show the different variations across multiple financial institutions.

---
Tags: 7
---


title: Use GMaps with just one country

text:
# Question
Title: Use GMaps with just one country
I would like to have a map on my website displaying all my stores. That worked out pretty well except for the fact the map is displaying more then just my country.
Is there a way to just show one country?

I made the map undraggable and users are not able to zoom, so the map is pretty much fixed but still, I would like to just show my country.

Is this possible with macro's? And if so, how do I create them?

**EDIT:**

So my country is Belgium and I would like to hide France and Germany (and if possible highlight Belgium...)

# Answer
You can not do it through macro's but alternatively you can set the zoom option for the map.

Go to Gmap Setting and set the Default zoom option to your requirement.

Hope it works for you!
> 1 votes

# Answer
I don't think it's possible with Google Maps. But you can try to use Google GeoMap to render a specific country map: GeoMap.

As an example, go to this link and copy paste the code below to render a map of Belgium with only Gent and Brussels with some values.

Javascript code to put in "Edit Code" textarea, then press "Run Code":

```
function drawVisualization() {
      var data = google.visualization.arrayToDataTable([
        ['City', 'Popularity'],
        ['Gent', 200],
        ['Brussels', 300]
      ]);

      var options = {};
      options['region'] = 'BE';
      options['colors'] = [0xFF8747, 0xFFB581, 0xc06000]; //orange colors
      options['dataMode'] = 'markers';

      var container = document.getElementById('visualization');
      var geomap = new google.visualization.GeoMap(container);
      geomap.draw(data, options);
}

```

GeoMap is usually used to display charts and datas, but it could answer your needs, it's just a suggestion.
> 0 votes

# Answer
Very near to what @Bala has answered you can opt the following:

1. Use OpenLayers instead of GMap if your requirements suite and cater to it.
2. Set zoom level for default map in OpenLayer settings.
3. Use KML overlay for OpenLayer to highlight the country of your liking.

A sample of what you are looking for from my website: http://indiansnakes.org/content/rat-snake
> -1 votes

---
Tags: 7, location, google-maps
---


# Question
Title: Dynamically populate one select based on another
I'm new to Drupal and well aware this question has been asked before, but I couldn't find a situation similar to mine, or maybe I didn't understand it.

I have three content types:

1. *Team* with fields *Team Name*.
2. *Game* with fields *Team 1* and *Team 2*, an entity reference to the *Team* content.
3. *Vid* content type which has a select box for games (entity reference) which I'm able to populate.

On selection of game, the teams (*Team 1* and *Team 2*) should be populated in the select box of another field say *Pass*.

One game can have two teams, several teams exist and each team can be involved in different games.

I've tried the hierarchical select module, conditional select, entity reference limit option, creating views and populating the entity reference, and tried Rules as well, but either I couldn't work through it or couldn't find the right setup.

Can someone point me in the right direction to solve this problem?

# Answer
Try conditional\_fields

Update multiple fields with ajax callback in form
> 0 votes

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


# Question
Title: Add Location CCK field and instance programmatically to content type in Drupal 7
How does one add a Location CCK field and instance programmatically to a content type in a Drupal 7 module install? I am mainly concerned with what params need to be given to the `field_create_field` and `field_create_instance` functions, assuming it is created in the same way as core fields? I've put some examples of the params I give to these functions in creating core fields (in case this helps):

An example of the params given to `field_create_field`:

```
'field_property_price' => [
    'field_name' => 'field_property_price',
    'label' => $t('Price'),
    'cardinality' => 1,
    'type' => 'text',
    'module' => 'text',
    'length' => '20'
];

```

An example of the params given to `field_create_instance`:

```
'field_property_price' => [
    'field_name' => 'field_property_price',
    'label' => $t('Price'),
    'cardinality' => 1,
    'required' => true,
    'widget' => [
        'weight' => '0',
        'type' => 'text_textfield',
        'module' => 'text',
        'active' => 1,
        'settings' => [
            'size' => '20',
        ],
    ],
],

```

Thanks for reading.

# Answer
> 0 votes
Never mind I figured it out. The following params work (note that the entity type and bundle params are also needed, but for my own usage I add these later).

For `field_create_field`:

```
'field_property_location' => [
    'field_name' => 'field_property_location',
    'label' => $t('Location'),
    'type' => 'location',
    'module' => 'location_cck',
    'settings' => [
        'location_settings' => [
            'form' => [
                'fields' => [
                    'name' => [
                        'collect' => 1,
                        'default' => '',
                        'weight' => 1,
                    ],
                    'street' => [
                        'collect' => 1,
                        'default' => '',
                        'weight' => 2,
                    ],
                    'additional' => [
                        'collect' => 1,
                        'default' => '',
                        'weight' => 3,
                    ],
                    'city' => [
                        'collect' => 1,
                        'default' => '',
                        'weight' => 4,
                    ],
                    'province' => [
                        'collect' => 1,
                        'widget' => 'autocomplete',
                        'default' => '',
                        'weight' => 5,
                    ],
                    'postal_code' => [
                        'collect' => 1,
                        'default' => '',
                        'weight' => 6,
                    ],
                    'country' => [
                        'collect' => 1,
                        'default' => 'gb',
                        'weight' => 7,
                    ],
                    'locpick' => [
                        'collect' => 0,
                        'weight' => 20,
                    ],
                ]
            ],
        ]
    ],
],

```

For `field_create_instance`:

```
'field_property_location' => [
    'field_name' => 'field_property_location',
    'label' => $t('Location'),
    'required' => true,
    'widget' => [
        'weight' => '0',
        'type' => 'location',
        'module' => 'location_cck',
        'active' => 1,
    ],
     display' => [
        'default' => [
            'label' => 'above',
            'type' => 'location_default',
            'weight' => 0,
        ],
    ],
],

```

There are more params you can fiddle with but these are the ones that suited my needs. To figure the params (and to figure out params for other fields like this in future), first add the fields manually to the content type with the desired settings in the Drupal backend. Then in the command line go to the projects root directory and used `drush eval "print_r(field_info_fields())"` to see all the fields added and `drush eval "print_r(field_info_instances())"` to see all the field instances added.

Mirror the data and structure from the print out to use in the `field_create_field` and `field_create_instance` functions as I've done above.

---
Tags: 7, entities, location, installation
---


# Question
Title: Dashboard like module that works with Panels
Dashboard module lets users change the dashboard according to their preferences. IS there a similar module which does the same for panels.

For example.

1. An admin user decides which blocks should be available on a particular page.
2. Each user can decide the order in which these blocks should be shown for him and whether they should be shown at all.

# Answer
> 1 votes
Dashboardify

> Dashboardify is a module for creating complex dashboards.
>
> Each user with proper permissions can add any block to dashboard and rearrange blocks order on his or her dashboard page. There is one dashboard with predefined regions available for each user. User can add unlimited instances of the same block which can be useful for views blocks with different contextual filters applied. Along with block information module stores data what contextual filters were used while adding block to dashboard. Block order is autosave via AJAX.

Panel Dashboard

> Allows users to locally rearrange and roll up panes on the panel and save the state per account. Global state of the panel is not modified in the process.

Total Control Admin Dashboard

> The Total Control Admin Dashboard creates a default panel page with useful administration tools. Its purpose is to create a central location from which a Drupal site can be properly cared for. Several overview panes are included for site stats and quick reference. Several administration panes are provided with quick links to content types, menus, taxonomy, and other scattered locations of important Drupal site administration. Several views panes are also provided as well as full-page comprehensive versions of the views with bulk operations. Each views panel pane is customizable via it's pane settings, or override the default views provided to suit your own needs.

---
Tags: panels, dashboard
---


title: Overwrite custom node view fail

text:
# Question
Title: Overwrite custom node view fail
I've created a function that have custom content type and all went well, but the problem is now I'm unable to overwrite the node view page:

Here are my functions:

```
function xxx_theme($existing, $type, $theme, $path) {
  return array(
    'xxx_print' => array(
      //'variables' => array('node' => NULL),
      'function' => 'theme_xxx_print',
    ),
  );
}

function theme_xxx_print($node) {
  return '<div>test</div>';
}

```

# Answer
If you are using panels node view template for your node view then your template file and node theme declarations would be overruled by panels.

If you want to verify, disable the panel node view. Make sure to flush your caches then visit a node you have and your theme override/addition will be there.
> 0 votes

---
Tags: 7, theming, nodes
---


title: Importing Commerce Orders and Users

text:
# Question
Title: Importing Commerce Orders and Users
I am revamping a website which is uses Drupal Commerce. I want to actually mirror the website and work on it offline before bringing it back onto the server as the newer version.

Obviously while I am doing this there is likely to be orders made and new users registered.

How can I import these or somehow bring the revamped website upto date with all users and orders?

Can anyone see any other issues with doing this also?

# Answer
> 1 votes
You can use the Commerce Migrate and import your orders, and Feeds to import users.

From Commerce Migrate project page:

> Commerce Migrate is a general-purpose migration framework extending Migrate Module for bringing store information into Drupal Commerce.

Also, there is a thread about this here.

---
Tags: commerce
---


# Question
Title: How is the views row plugin set? Can I use a views row plugin from a different module?
I'm writing a custom display plugin for views in Drupal 8, and I'm having a hard time figuring out how the view row plugin is decided.

I'm basing my plugin on the views Serializer style in the rest module. The serializer style is calling out to a row style, either DataEntityRow or DataFieldRow:

```
public function render() {
  $rows = array();
  // If the Data Entity row plugin is used, this will be an array of entities
  // which will pass through Serializer to one of the registered Normalizers,
  // which will transform it to arrays/scalars. If the Data field row plugin
  // is used, $rows will not contain objects and will pass directly to the
  // Encoder.
  foreach ($this->view->result as $row) {
    $rows[] = $this->view->rowPlugin->render($row);
  }

```

Somewhere along the line, the rowPlugin is being set to one of the aforementioned styles but I can't figure out whether it's set somewhere and I'm missing it, or if it's auto detected in some way. As far as I can tell, the row plugin is never directly instantiated anywhere.

If it *is* some sort of automatic detection, is there any way for me to hint or force the use in my own code? I could happily use the DataFieldRow plugin in my own class, but I don't know how.

# Answer
Row is just a plugin. You can write your own. See the core/modules/views/src/Plugin/views/row directory.
> 2 votes

# Answer
The row plugin is initialized in `\Drupal\views\Plugin\views\style\StylePluginBase::init()`
> 1 votes

---
Tags: 8, views
---


# Question
Title: Apache Solr 4.6.0 installation and compatibility with Drupal7
I'm having difficulties installing Apache Solr. The latest version that I downloaded was 4.6.0. But all Drupal documentation and tutorials (see http://www.youtube.com/watch?v=ori-VvvH1Aw) are talking about 3.5.0. While 3.5.0 is nowhere to be found on internet, 4.6.0 has a totally different directory structure, and there is no documentation on how to install this latest version on a server or on a local WAMP. There is no mentioning of which Apache Solr versions are most recommended to work with Drupal? Any help?

# Answer
You aren't alone I had to scour the internet and read several articles before I truly understand all of this. I tried about three different methods until I finally got it right!

If you are using Debian/Ubuntu (with Tomcat7) it's even easier then most outline. I preferred this over Lullabot since when you install it through Ubuntu it's actually a service and less fiddling :)

# Install Java

```
apt-get install java7-jdk

```

# Install Tomcat

```
apt-get install tomcat7 tomcat7-admin

```

Once this is done you can get to `http://localhost:8080` and see that's it is all running properly.

**Note:** It's recommended to push the port to another one since 8080 is pretty common. If you want to do that use this code for that!

```
sudo sed -i s/8080/8983/g /var/lib/tomcat7/conf/server.xml

```

# Configure Tomcat

1. You will want to actually create a users account for Tomcat so that other people have to log into the admin (it keeps it safer).

`nano /var/lib/tomcat7/conf/tomcat-users.xml`
2. Then add these xml arguments between the `<tomcat-users>` tags

`<role rolename="manager-gui"/>
 <role rolename="admin-gui"/>
 <user username="!!somename!!" password="!!somepassword!!" roles="manager-gui,admin-gui"/>`
3. Now you can restart tomcat again and view the admin page at `http://localhost:8983/manager/html`

`service tomcat7 restart`

# Install Solr

1. Download the latest ApacheSolr here (When I wrote this I got it working with 4.7)
2. Extract the files into a directory

## Copy Solr library files

Next we want to add the library files to Tomcat library directory. **Note:** You can also use symlinks if you prefer, but for the purpose of understand where everything goes I chose to place it directly in the directories

```
cp ~/solr-4.x.x/example/lib/ext/* /usr/share/tomcat7/lib/

```

It may be a good idea to also copy the java libraries from solr/dist/solrrj-lib/\*

```
cp ~/solr-4.x.x/dist/solrj-lib/* /usr/local/tomcat7/lib/

```

## Copy Solr WAR app file

```
cp ~/solr-4.x.x/dist/solr-4.x.x.war /var/lib/tomcat7/webapps/solr.war

```

# Setup Drupal ApacheSolr core

1. We first need to copy over the sample configuration files from ApacheSolr.

`mkdir -p /var/lib/tomcat7/solr
cp -r ~/solr-4.x.x/example/solr/collection1/conf /var/lib/tomcat7/solr/`
2. Next grab the latest version of the apachesolr module https://drupal.org/project/apachesolr and unzip it

`tar xvf apachesolr-*.tar.gz`
3. Syncronize the apachesolr configuration files (for Drupal) with your solr configuration

`rsync -av apachesolr/solr-conf/solr-4.x/ /var/lib/tomcat7/solr/conf/`

**Note:** I found an error in which ApacheSolr refused to start due to duplicate errors. I reported that here so you might want to look at the solution here as at the time of writing this I could not get it running without that!

4. Create a core definition file to tell Apache Solr which cores are available.

`nano /var/lib/tomcat7/solr/solr.xml`
5. Paste the following code inside that file

`<?xml version="1.0" encoding="UTF-8" ?>
 <solr persistent="false">
 <cores adminPath="/admin/cores">
 <core name="!!yourcorename!!" instanceDir="!!yourcoredir!!" />
 </cores>
 </solr>`

## Create Drupal core directory

This will create a new core in your system with that name. If you wish to add more you simply can repeat this step as well as the one above.

```
mkdir /var/lib/tomcat7/solr/!!yourcoredir!!
cp -r /var/lib/tomcat7/solr/conf /var/lib/tomcat7/solr/!!yourcoredir!!/

```

## Let's Make It Live

1. Your at the last stretch!! Let's put tomcat7 to sleep

`service tomcat7 stop`
2. Now change the permissions on the tomcat directory

`chown -R tomcat7:tomcat7 /var/lib/tomcat7`
3. Start it back up

`service tomcat7 start`

# It's Live

You should be able to go to `http://localhost:8983/solr` and see a new core instance available! Now you can go ahead and configure drupal to point to that.

**Note:** Your new core is located at `http://localhost:8983/solr/!!yourcorename!!` to be used in the Drupal ApacheSolr module.

Credit and props goes out to Pacoup
> 21 votes

# Answer
Changes to Solr 4 have been discussed in the issue queue: https://drupal.org/node/1676224

The issue contains a number of links to sandbox sites and tutorials.
> 1 votes

# Answer
All solr version should work with Drupal as long you've module which supports it.

For example Apachesolr module, has configuration files for: Solr: 3.x and 4.x.

For Search API Solr Search module, you can find the configuration files for Solr: 3.x, 4.x and 5.x, so it shouldn't be a problem.

How to install Solr, it's another thing. There are many ways of doing it. Few examples below.

## Installation

### OS X

Simplest way is to install latest Apache Solr using Homebrew, e.g.:

```
brew install solr
ln -sfv /usr/local/opt/solr/*.plist ~/Library/LaunchAgents
brew services start solr # Or just: solr start

```

Now installed Solr instance is accessible at: http://localhost:8983/

### Debian/Ubuntu

Simplest way is to install Solr via `apt`:

```
sudo apt-get install solr-tomcat

```

### via Puppet

Use Puppet manifest to install Solr. Here is one solr4-tomcat.pp example.

### Manually (4.x or 5.x)

```
$ VER=4.10.4 # Solr version.
$ TOMCAT_BASE=/var/lib/tomcat7
$ sudo apt-get install tomcat7 tomcat7-admin
$ sudo sed -i.org 's|port=\"8080\"|port=\"8983\"|g' /etc/tomcat?/server.xml
$ sudo mkdir -p /opt/solr/home/collection1/conf /opt/solr/data
$ cd /opt/solr
$ curl -s http://archive.apache.org/dist/lucene/solr/$VER/solr-$VER.tgz | sudo tar zxvf -
$ sudo cp -v /opt/solr/solr-$VER/dist/solr-$VER.war $TOMCAT_BASE/webapps/solr.war
$ sudo cp -v /opt/solr/solr-$VER/example/lib/ext/*.jar /opt/solr/solr-$VER/dist/solrj-lib/*.jar /opt/solr/solr-$VER/example/resources/log4j.properties $TOMCAT_BASE/webapps/solr/WEB-INF/lib
$ curl -s http://ftp.drupal.org/files/projects/search_api_solr-7.x-1.x-dev.tar.gz | sudo tar zxvf -
$ sudo cp -v search_api_solr/solr-conf/4.x/* home/collection1/conf/
$ sudo /etc/init.d/tomcat7 restart

```

Check if it is working at: http://localhost:8983

---

See also:
> 1 votes

# Answer
Here is how it's described in Drupal Community Documentation (Installing Solr on Tomcat):

### CentOS

> This walk-through assumes you already have Tomcat installed. If you don't it is probably easier to just use WHM and install it there and rebuild apache. Point and click is what I say.
>
> Once you have Tomcat installed you can verify its installation by going to:
>
> ```
> domain.com:8080
>
> ```
>
> You should see the default Tomcat page. If not, ask someone for help. If you don't, you are hurting the next person who comes along with the same issue. If we didn't want to help we wouldn't be Open Source.
>
> Download your a copy of Solr. If you don't know where to get it, google it.
>
> To make things easier now and in the future, find your Tomcat installation
>
> ```
> $ locate tomcat
>
> ```
>
> Create a soft link like so:
>
> ```
> ln -s /my/tomcat/location /tomcat
>
> ```
>
> If you did it right you should be able to just
>
> ```
> $ /tomcat
>
> ```
>
> in sshd and get to your directory.
>
> I will be using the `/lib` directory for my example. If you don't have one, create it with `mkdir /lib` command.
>
> 1. Extract Solr to temporary location, for my sake, I just get the zip file from Solr mirrors.
>
> ```
> $ unzip apache-solr-1.4.1.zip /lib/
>
> ```
>
> Build your Solr
>
> ```
> $ cd /lib/solr
> $ ant dist (you should see it building something.)
>
> ```
> 2. Rename your war file for ease of use.
>
> ```
> $ cd /lib/apache-solr-1.4.1
> $ cd dist
> $ mv apache-solr-1.4.1.war solr.war  (this just renames it without asking you)
> $ dir  (check to make sure it worked. you should see solr.war)
>
> ```
> 3. Copy `solr.war` to `/lib/solr/example`
>
> ```
> $ cp solr.war /lib/solr/example
> $ cd /lib/solr/example
> $ dir  (verify that the solr.war is in the directory, you should also see the familiar start.jar file there)
>
> ```
> 4. Copy the xml files from your apachesolr location. Usually it will be:
>
> ```
> $ cp /home/YOUR_NAME/www/modules/apachesolr/*.xml /lib/solr/example/solr/conf</code>
>
> ```
> 5. Create an xml file in Tomcat to tell it to run Solr at Tomcat start-up
>
> ```
> $ cd /tomcat
> $ cd /conf/Catalina/localhost
> $ vi solr.xml
>
> ```
>
> Paste this into your new file:
>
> ```
> <code>
> <?xml version="1.0" encoding="utf-8"?>
> <Context docBase="/solr/example/solr.war" debug="0" crossContext="true" >
>    <Environment name="solr/home" type="java.lang.String" value="/solr/example/solr" override="true" />
> </Context>
> </code>
>
> ```
>
> The two values you should be customizing are Context::docBase (to point to your .war file) and Environment::value (to point to your solr directory). Note that in this example the .war file is in the solr directory, which is a fine pattern to follow.
>
> {Press `Escape` and then `:w`} and then {Press Escape Key and then `:q`}
> 6. Restart Tomcat using WHM for ease. It's under Restart Services. Then go here:
>
> ```
> yourdomainname.com:8080/solr/admin
>
> ```
>
> You may get this error:
>
> > false in null ------------------------------------------------------------- java.lang.RuntimeException: java.io.IOException: Cannot create directory: /usr/share/solr/data/index at org.apache.solr.core.SolrCore.initIndex(SolrCore.java:398) at org.apache.solr.core.SolrCore.(SolrCore.java:546) at ...
>
> Don't panic. I gatcha!
>
> Go to `solrconfig.xml` again
>
> ```
> $ cd /solr/example/solr/conf
> $ vi solrconfig.xml
>
> ```
>
> and modify this line:
>
> ```
> <!--<dataDir>${solr.data.dir:./solr/data}</dataDir>-->
>
> ```
>
> to
>
> ```
> <dataDir>${solr.data.dir:./solr/data}</dataDir>
>
> ```
>
> Restart Tomcat again and go here:
>
> ```
> yourdomainname.com:8080/solr/admin
>
> ```
>
> **DO THIS IF YOU HAVEN'T ALREADY:**
>
> Go to your schema.xml file in `/lib/solr/example/solr/conf`:
>
> ```
> $ vi schema.xml
>
> ```
>
> Add this in the section just after `<field>`:
>
> ```
>   <field dest="host" source="host"/>
>   <field dest="segment" source="segment"/>
>   <field dest="boost" source="boost"/>
>   <field dest="digest" source="digest"/>
>   <field dest="tstamp" source="tstamp"/>
>
> ```
>
> Save it and exit {Press `Escape` Button) `:w` (Press `Enter`) then (Press `Escape` Button) `:q` (Press `Enter`)
>
> If you are using Nutch then go here and install/configure nutch.

For Apachesolr in Drupal 6.x, see: Setup Drupal 6.x with Apache Solr on Tomcat6 and Ubuntu.
> 1 votes

---
Tags: search
---


# Question
Title: yes/no rating with node reference target
I have a review content type that (node) references a product content type. I'm using fivestar ratings for overall rating and specific ratings. With fivestar I can make the product the "vote target".

One of the ratings is a "yes/no" type rating where I want to show the aggregate on the product node (x% of users rated yes).

I tried to use fivestar with a "1 point" rating where 1=yes, 0=no but the problem is that 0 votes are not saved at all, therefore always resulting in a 100% result.

I could probably use a "2 point" rating and then have a custom display formatter to do the math and translate it to the correct %.

Are there any other solutions? I can't use the rate module because I already use it for "thumbs up/down" ratings.

# Answer
The Rate module allows one to attach multiple rate widgets to a content type. Create one rate widget for thumbs up/down and second for yes/no.

Drupal Commons Distribution with Commons Q&A includes both a Like and Points system in this manner...

When you add a second widget, choose to attach it to the same content type(s).
> 1 votes

# Answer
In extends of Flags, you could use Rate. It should fit to your needs (Rate a node with Yes / No Flag and get its result into a percentage data)
> 1 votes

# Answer
I am working on a very similar issue and hit a brick wall with using Fivestar, Rate, Flag, etc. as well. I got here through google many months later because I was looking for the 'vote target' functionality of fivestar but the simplicity of a vote up / down widget for a Yelp style interface with a node and comments added as reviews.

I used the Vote Up/Down widget and followed the advice here from the module maintainer marvil07 on Drupal.org to render the widget in the comment form as opposed to within the node form:

* Enable comments for the node type you want.
* Add one vud\_field field to the node type you want.
* Set the vud\_field field formatter to hidden.
* Render the vote widget manually on the comment form(normally) and on the node type (with the readonly option).

This works well since the field is rendered as an AJAX widget and contains all the information it needs to record the vote against the correct node. My exact implementation of this worked like this with my Vote Up / Down field 'field\_rating':

```
function MYTHEME_form_comment_form_alter(&$form, &$form_state) {

  if ($form["#form_id"] == "comment_node_MY_YELP_KNOCKOFF_form") {

    $node = node_load($form["#entity"]->nid);
    $field = field_view_value('node', $node, 'field_rating', $node->field_rating[$node->language][0]);
    $vud_render = render($field);

    $form["voteupdown"] = array(
      '#markup' => $vud_render,
      '#weight' => 0,
    );

  }

}

```
> 0 votes

---
Tags: 7, rating
---


# Question
Title: Putting a watermark on image using Imagecache Actions
I would like to put a watermark on the images I'm uploading, but a bit differently than how imagecache does it. Since if a use imagecache for this task, the watermark is always on the image, I would like to put it below the image (t.i. if the height of the img is 500px, then the imagecache would keep it 500 + 40px for the watermark). Is there a way to do it?

Real life example: http://www.bildites.lv/images/5wbdmy4t3ezmtq3as8m.png right now it's like the image on the left, I would want it to be like the image on the right. Is there a way to do it? Keeping in mind I'm also scaling those images.

# Answer
You can use Imagecache Actions module.

> **Effects provided**
>
> * **Watermarking - a much requested addition that enables you to place any image anywhere over a source picture, with alpha transparency**
> * Overlays - Add photo-corners etc to the image
> * **Text overlay - add a short copyright notice to your image, using available system fonts**
> * Color-shifting - Colorize images. Also invert.
> * Brighten/Darken
> * Alpha blending - turn an image into a transparent mask, and back into a flat image against another color
> * **Canvas manipulation - add padding, either onto color or transparent backgrounds**
> * Background - Place your image onto another source background
> * File Format switcher - If you need tranparency in JPGs : make them PNG. If your PNG thumbnails are 30K each, save them as JPGs. (This is distributed as part of the color-actions submodule)
> * Rounded corners (transparent). With input from canaryMason, we can even set different radius for different corners, and round just one corner etc.
> * Aspect Switcher new 2009-08 - lets you perform different actions or use different dimensions based on whether the image is 'landscape' or 'portrait'
> * Custom Actions - Execute your own PHP/GD code in the middle of an imagecache generation process. Requires some familiarity with imageAPI internals.

I have bolded the ones that would interest you.
> 5 votes

# Answer
As mentioned, use ImageCache Actions to generate your actual image. You could also assign some CSS to the generated image to position your "overlay" below the image. Just give it a CSS position of absolute and a bottom of negative the height of the image overlay.

For example, if your image is 40px tall, you could assign the wrapping class:

```
position: absolute;
bottom: -40px;

```

This'll position the generated image below your primary image with some simple CSS. You'll need to identify the selector / element which ImageCache Actions generates in order to assign the CSS to the wrapper. You'll also need to assign the wrapping element of both your generated ImageCache element and the original image position (position: relative;) so that the absolute positioning will work properly, relative to the container.
> 0 votes

---
Tags: media
---


# Question
Title: How to customize how field is displayed in view
UPDATE: Thanks to Molot I now see how I can edit the output of the view using the specific tpl file for that field. However I'm still not sure how to refer to that field and print it within that tpl file.

---

I have a file field in a custom content type that I'm displaying in a view. I want it to spit out the path to the file and nothing else in the view so I can do whatever I want with it. I have customized the views-view-unformatted-nameofview.tpl.php so it doesn't wrap the entire view with the default drupal divs and classes, like so:

```
<?php foreach ($rows as $id => $row):
    print $row;
endforeach; ?>

```

Which works but is there a way to customize how it spits out a specific field? Even though I customize the html style to none it still tries to do things like display a custom icon for my file which I don't want. I'm also rewriting the output of the field in the view like so

```
<img src="[field_front_page_icon]">

```

I want to embed it into an img tag but what I end up with is

```
<img src="<span class=" file"="">
<img class="file-icon" alt="" title="image/svg+xml"  src="/modules/file/icons/image-x-generic.png">
<a  href="https://url.com/sites/default/files/maps.svg" type="image/svg+xml;  length=5657">
    maps.svg
</a>

```

When all I want it to display is

```
<img src="https://url.com/sites/default/files/maps.svg">

```

I would normally use an image field but it doesn't seem to allow to add svg as an acceptable file type. I'm open to other ways to go about it, but even if that's the case it'd still be nice to know how to edit the field output in views. I'd rather not install a pre-existing module if at all possible. However I would understand if that is the only reasonable course of action.

# Answer
> 2 votes
If you just want to rewrite the file field in Views to something like

```
<img src="https://url.com/sites/default/files/maps.svg">

```

All you have to do is

1. add that File Field in Fields section
2. Inside the File Field configure, select "**URL to file**" on Formatter
3. Inside the File Field configure rewrite results section, check the "**Rewrite the output of this field**" and rewrite something like "`<img src="[field_file] ">`" on Text area. Then click Apply.

---
Tags: views, theming
---


# Question
Title: Apache Solr own grouping in autocomplete
The apache solr autocomplete module don't work for me.
I try to achive a relative complex autocomplete,
my target is to achive this on the autocomplete:

**Search for "searchword":**
-Facet for type/bundle
-Facets based on the results
Show all results for "searchword"

As example:
**Search for "test":**
Download (176)
Systems (100)
News (20)
Services (5)
**Systems**
System 1
System n
**Services**
Service 1
Service n
**Show all results for "test"**

Any suggestions how I could get this?

Edit: I use apache solr search for this so no search api hook here
(miss some functions in the search api based)

# Answer
> 0 votes
Found the Module Search Autocomplete will work on this base. So I just need to add a top Layer for the facet and group the results.

# Answer
> 1 votes
You can try to write your own query according to results you want to get. below link may help you in this.

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

---
Tags: 7, ajax, search
---


# Question
Title: How do you refer to the field in views-view--field-fieldname.tpl.php?
I'm using the views-view-field--field-fieldname.tpl.php to rewrite the output of a specific field in a view. However in this template I'm having trouble referring to the actual field.

I can produce the normal input with

```
print $output;

```

However this contains the classes and divs it is wrapped in. Including the default icon that is used to represent it. I'm having trouble producing the specific data of the field. Specifically the url to the file. (It is a file field). Is this possible? I made quite a number of attempts. Below are the attempts I've made that were unsuccessful.

```
print $fields['fields_field_fieldname']->content;

print $row['fieldname'];

print $view->results->{view->field['field_fieldname']->field_alias};

```

I understand that I could use string replace and regex to extract the data I need $output. If that's the only way to do it, I'll stick to that.

# Answer
> 2 votes
File field has formatter "URL to file", please see this screenshot:

So finally, in `$output` will be only url to file.

Also, if you don't want any views default wrappers, you can unselect checkbox in "STYLES" fieldset (see screenshot abowe).

---
Tags: views, theming
---


# Question
Title: How to add "publish content" to a node view tab
I'm developping a website where I'm asked to add a tab "Publish content" next to the Edit tab. I was told to use the hook\_menu, but so far i didn't succeed in showing the tab.

Here is what I have done so far :

```
function mij_bo_add_menu(){
    global $items;
    $items['node/%node/edit'] = array(
        'title' => t('Publish'),
        'page callback' => 'node_page_view',
        'page arguments' => $items['#primary'][1]['#link']['page_arguments'],
        'access callback' => 'node_access',
        'access arguments' => array(1),
        'weight' => 5,
        'type' => MENU_LOCAL_TASK,
    );
 }

```

Any suggestions?

PS : I am still a novice in Drupal programming.

# Answer
> 2 votes
There's already a module called Publish Content that does what you exactly describe. You can browse the source code if you want to see how it's implemented there.

# Answer
> 2 votes
Use the Flag module to create a GLOBAL flag to be used by authorized editors. For any node for which the flag is turned on, let the Rules module update the status to published. Done ... No coding needed/involved.

The actual implementation of such flag can either be:

* a link somewhere when viewing the node (click such link to toggle the flag on/off).
* a checkbox to be turned on/off while editing the node.

If you're not familiar with Rules, checkout the video tutorials Learn the Rules framework. And/or the similar set of 8 video tutorials about the Flag module. Especially the video tutorial about Triggering Rules with Flag is pretty close to what you want to do here: instead of changing the some of the node access permissions (as in the video), you just want to change the node status to published.

Note: The video How to add a Flag link to a Drupal View shows how to add a flag to a view.

---
Tags: nodes, routes
---


# Question
Title: user ability to hide one column only on view
What is the best way to give the user the ability to see or hide one column (only one) on a drupal 7 view? I want to give them a toggle box to be able to hide and unhide the column

# Answer
> 0 votes
Found the answer here http://siripong-computer-tips.blogspot.com/2011/12/hide-table-column-drupal-view-w-jquery.html

View 3 on drupal 7 produces html like this

```
<table class="views-table cols-4">
  <thead> <tr>
    <th class="views-field views-field-title">Example</th>
    <th class="views-field views-field-body">howto</th>
    <th class="views-field views-field-field-1">dynamically</th>
    <th class="views-field views-field-field-2">show/hide</th>
  </tr>
  </thead>
  <tbody>
    <tr class="odd views-row-first views-row-last">
      <td class="views-field views-field-title">table column</td>
      <td class="views-field views-field-body">Drupal</td>
      <td class="views-field views-field-3">Views</td>
      <td class="views-field views-field-4">jquery</td>
    </tr>
  </tbody>
</table>

```

go to view edit page Displays -\> Page Details -\> Page Settings -\> Footer add the following code

```
Show columns
<form>
<input onclick="toggleVis(this, '.views-field-title')" type="checkbox"> Title
<input onclick="toggleVis(this, '.views-field-body')" type="checkbox"> Body
</form>

<script type="text/javascript">
  function toggleVis(chkbox, col){
    if(chkbox.checked == true) {jQuery(col).show();}
    else {jQuery(col).hide();}
  }
</script>

```

using Jquery to toggle hide the column

---
Tags: views
---


title: print full url template

text:
# Question
Title: print full url template
I'm building a multi language site but I'm facing a problem with an url. In my template i have the following print rule for an url `<?php print $base_url.'/#project';?>` The base url only prints http://www.codedesign.be/#project withouth the language selector. url is normal url/nl/#project or www.codedesign.be/fr/#project

# Answer
You should use the url() function to create URLs.

> Generates an internal or external URL.

This functions handles all complexity of creating an URL, including language prefix. url() handles exernal URLs too.

You can also use the l() function to create anchor tags:

> Formats an internal or external URL link as an HTML anchor tag.
>
> This function correctly handles aliased paths and adds an 'active' class attribute to links that point to the current page (for theming), so all internal links output by modules should be generated by this function if possible.

In your case you can use:

```
<?php print url('<front>', array('absolute' => TRUE, 'fragment' => 'project'));?>

```
> 1 votes

# Answer
If `$base_url` doesn't append the language, you may use this code

```
global $base_url;
global $language;
$url = $base_url."/".$language->name."/#peoject";

```
> 0 votes

---
Tags: theming, i18n-l10n, uri
---


# Question
Title: update causing pagination to fail on comments in panel page template
I recently was alerted to an issue on a website I'm in charge of in which the correct comments were not being shown. I dug into the issue and noticed that it was actually an issue with pagination of the comment pages. Basically what is happening is the comment pages are not advancing when clicking on the next page (so mysite.com/blog/post?page=1 won't actually take show the second page of comments, rather just the first page).

I have a few different dev versions of this site, and when testing on one that had a few updates needed to it, I noticed the issue didn't exist on that site. Upon updating ctools and panels I noticed the issue started to show up on this dev site as well.

I'm not doing anything overly special in the panel pages node template, just using node being viewed comments that comes with panels (under add content, node, node comments). Not sure what would be causing the issue, or why it would fail after an update.

# Answer
> 0 votes
It turns out this was an issue with ctools that was introduced into version 7.x-1.6. The bug in question was introduced in the patch for Update node\_view.inc to execute the normal Drupal hooks.

Luckily, there is a patch of that patch, which can be found at Entity-related hooks can be redundantly invoked for same entity in certain situations causing errors.

---
Tags: panels, updating, chaos-tool-suite
---


# Question
Title: Commerce rule for total of product lines only (not shipping as well)
I have a requirement to add an amount to the total of all Commerce product lines items in a users cart and then add that amount to the shipping amount.

The rule I currently have uses the "**calculating a shipping rate**" event. The element on the rule uses "**Calculate a value**" with the input value as **commerce-line-item:order:commerce-order-total:amount**. However, this value also takes into account the shipping. I only want to apply the calculation to the ordered items in the cart - not shipping as well.

Does anyone know how I can access just the **sub**total for the cart?

Thanks!

# Answer
> -1 votes
Using `[site:current-cart-order:commerce-order-total:amount]` seems to do the trick.

---
Tags: commerce, workflows
---


# Question
Title: How do I find the default value or change state of a form element?
I'm putting together a fairly complex form with Drupal 8 (currently building on beta 7). In my validation function, I need to be able to detect whether a field, which was populated with default values, has changed.

In Drupal 7, this would have been pretty straightforward. I could dig into the form\_state array and find the appropriate default\_value entry and compare it to the submitted value.

But now that form\_state is an encapsulated object, I don't see an obvious way to get the default value.

I know I can kluge this if I need to, by including hidden fields in the form itself with the default values. But I know that the information is in the form\_state object: if I print\_r form\_state I can see both the old and new values--but not in any way I can figure out how to access using the methods listed in FormStateInterface.

Bottom line: in Drupal 8, how do I test whether the submitted value of a form element is the same as its default value?

# Answer
> 1 votes
```
public function validateForm(array $form, FormSateInterface $form_state) {
  $element = $form['elementname'];
  $default_value = isset($element['#default_value']) ? $element['#default_value'] : NULL;
  $value = $form_state->getValue($element['#parents']);
  $changed = $default_value == $value;
    if ($changed) {
    // This is stupid, it's just an example.
    $form_state->setError($element, $this->t("The value has changed."));
    }
}

```

# Answer
> 0 votes
Okay, think I figured it out, although it seems like a bit of a kluge still.

I used the getCompleteForm() method on FormStateInterface. This gives you, as far as I can tell, the array version of FormStateInterface, so you can handle it just like you did in 7. It seems like there should be a more elegant solution, but this way seems to be working for now.

# Answer
> 0 votes
Here's how I did it, pretty similar to Ivan's solution

```
public function validateForm(array $form, FormStateInterface $form_state) {
  if ($form[$elementName]['#value'] == $form[$elementName]['#default_value']) {
    // It changed
  } else {
    // it didn't
  }
}

```

Depending on what you are trying to do you can also do this on `save()`

---
Tags: 8, forms
---


# Question
Title: Can't log onto drupal with any email address
I am receiving "Account Approval" spam at one of my email addresses. I can't log onto to Drupal using that or any other email address I am using. When requesting new password using various email addresses, all are rejected as unknown. Will creating a new account allow me to install module(s) to kill spam?

# Answer
> 0 votes
Consider editing the eMailId currently stored in the Drupal database, using PhpMyAdmin. And this by replacing that eMail ID with some other eMail ID that is usable for you.

Then use the "request new pasword" feature for that account, which should be mailed now to the eMail Id that you can work with. Use the password reset link and you should be up and running.

Does this help?

---
Tags: users
---


# Question
Title: Need help finding source of CSS in Drupal code
I've added the share42 module, customized, downloaded it an installed it. It used to work fine. And it still works fine on my local development environment. But its not working on my production environment.

The steps to configure this module, are:

1. install the share42 module
2. customize the buttons: http://share42.com/
3. download and install the image and js script you created in step 2 in the all/libraries folder
4. put some code in the node.tpl.php file

I did all this, and like I said it looks fine on my development environment. However, when i push it to production it's all messed up and doesn't look right. I cleared caches and ran cron multiple times. I deleted my browser cache. Nothing.

So I did an inspect element on the that's outputting the share42 buttons on the production server. It's showing some inline styling that I didn't add. So I clicked the linked word 'inline' and it shows me the code for the entire page (just a random node). I don't see the inline styling anywhere on the page referenced in inspect element! It just shows the .js file I'm bringing in via . I've looked at that code though and copied and pasted the contents of my local .js file with the one on the production server and they are identical.

Note: I also deleted and replaced the entire /sites folder on the production server, and the bad styling is still there.

So now I'm a bit exasperated. Not sure what else to try to find out where the incorrect styling is coming from. Anyone have any other suggestions for places to look?

# Answer
> 1 votes
This sounds like a file permission problem on your production server for the library you added to your all/libraries folder. I.e. that some read access to those files in that folder is not granted.

Another reason MIGHT be that your library folder name (within all/libraries) is NOT named `share42` (case sensitive, so Share42 would NOT be ok). Variation of that could be that "share42.js" and/or "icons.png" cannot be found in that folder (eg beause it got renamed to something else).

# Answer
> 0 votes
Do you have CSS aggregation enabled? Your note on deleting the /sites folder on production tells me that it could be an issue with the permissions for your directory where the CSS files are all aggregated.

For me, it's sites/\*/css. The web server needs write permissions to that folder in order for it to aggregate the CSS and write it there. It could be that you're not seeing the right CSS because it can't write to the directory.

Check the permissions. A quick way to test this is to turn off CSS aggregation on your site and flush the CSS cache. That won't be good for performance, so I wouldn't recommend it for a huge site.

---
Tags: theming, 7
---


# Question
Title: Unable to print menu links using menu_navigation_links
I'm using a custom template and attempting to customize the output of specific menu items. However when I attempt to output each link in the menu specified it outputs nothing. menu-it is the machine name of the menu.

```
<?php $menu = menu_navigation_links('menu-it', 1);
    foreach($menu as $item){
        print $item;
    }
?>

```

# Answer
> 1 votes
The normal way to print that menu would be:

```
<?php print theme('links', array('links' => $menu), 'attributes' => array('class'=> array('links', 'site-menu')) ));?>

```

or similar.

If you want to do something different for individual items then in template.php you could implement:

```
function THEME_preprocess_menu_link(&$variables) {
    // if certain menu item, do something different
}

```

---
Tags: theming, routes
---


# Question
Title: How do I get masonry to run again once twitter widgets have rendered?
I am using the Masonry API and Masonry Views modules to get a view to render nicely, it works well.

I'm using oEmbed Core to render the URL provided by the user into an embedded tweet for a specific node type. That also works fine.

When the tweet shows up in the view however, my blocks get overlapped because the twitter widget is rendering *after* masonry has run. How do I rerun masonry once the tweet has fully rendered?

# Answer
> 1 votes
I went through the twitter documentation and found a way to call functions on twitter widget events:

```
// Load the twitter widgets script
window.twttr = (function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0],
    t = window.twttr || {};
  if (d.getElementById(id)) return t;
  js = d.createElement(s);
  js.id = id;
  js.src = "https://platform.twitter.com/widgets.js";
  fjs.parentNode.insertBefore(js, fjs);

  t._e = [];
  t.ready = function(f) {
    t._e.push(f);
  };

  return t;
}(document, "script", "twitter-wjs"));

// Bind an event to rerun the masonry layout when a tweet is rendered
twttr.ready(
  function (twttr) {
    twttr.events.bind(
      'rendered',
      function (event) {
        jQuery(function($) {
          $('.view-content.masonry').masonry();
        });
      }
    );
  }
);

```

---
Tags: views
---


# Question
Title: Distribute configuration to several sites
There should be several sites, starting with something like a similar distribution, but over time, each site might get some individual modules. Yet, I'd like to keep the site updated with new versions and new configurations over time as well.

So I can't use the full import/export of configuration management, since this would delete my individual additions on some sites, if I understood it correctly. And I need to be very careful with single exports, since those don't care about dependencies.
Configuration Packager has been merged into Features, so it seems as I need to use features anyway.

So what do I put into a configuration? And what into a feature? And how would I distribute the preconfigured stuff to all sites? Use a feature server like in Drupal 7? (If the Github process is setup and I've got a dev and several production sites, how do I push configuration and feature updates to production?)

# Answer
> 0 votes
So .. found more details on it.

With `drush config-list | grep news` I can get all configurations that are named with news. Those can be exported into a Module / YAML file and moved to another installation, or rather copied and enabled.

More information on that: http://nuvole.org/blog/2014/jul/15/packaging-and-reusing-configuration-drupal-8

So that would make Features in D8 quite unnecessary - depending on the use case, very good.

It might be reasonable to use `config-merge` but I'm not sure about:
If I'd do a Full Export, I'd only be able to use this on Cloned sites (like Staging/Live). But in my case I'd do an initial clone or a profile and would only like to pass on functionality (like features) and that might not work with config-merge?

---
Tags: 8, features, configuration
---


# Question
Title: How to have one stylesheet for logged in users and another one for anonymous users?
Anyone know how to have one CSS stylesheet for logged in users and another for anonymous users?

# Answer
> 4 votes
The template\_preprocess\_html() preprocess function adds a 'logged-in' or 'not-logged-in' class to the classes array. These classes get printed in the html.tpl.php template on the body tag.

So you should be able to target anything in your css for logged in or logged out users by using those classes. For example:

```
.sharing-block {
  top: 0px;
}
.logged-in .sharing-block {
  top: 25px;
}

```

Something like that should work without needing to worry about conditionally applied stylesheets or anything like that.

---
Tags: theming
---


# Question
Title: Making the size of two fields in comment form the same programmatically
in my node comment form I have a 'your name' field and an 'email' field for users to fill out. They are different in length and like them both to be length '30'. How can I do this with hook\_form\_comment\_form\_alter?

I've tried this, with no success (in template.php):

```
$form['field_email']['#size'] = 30;
$form['author']['#size'] = 30;

```

I've tried just changing the size of the field for the email field in the content type comments manage fields area but it does nothing.

# Answer
In the core comment form the 'author' element is an array of form elements:

```
  $form['author']['name']['#size'] = 30;
  $form['author']['mail']['#size'] = 30;

```
> 1 votes

---
Tags: theming, forms
---


# Question
Title: Managed file: What is the proper way of setting #default_value?
```
$form['picture']['file'] = array(
  '#type' => 'managed_file',
  '#title' => t('picture'),
  '#description' => t('Allowed extensions: gif png jpg jpeg'),
  '#default_value' => (isset($foo->picture->fid) ? $foo->picture->fid : ''),
  '#upload_location' => variable_get('picture_upload_location'),
  '#upload_validators' => array(
    'file_validate_extensions' => array('gif png jpg jpeg'),
    // Pass the maximum file size in bytes
    'file_validate_size' => array(MAX_FILE_SIZE*1024*1024),
  ),
);

```

I have the above code snippet from here. It's very useful, however I'm having a hard time setting `#default_value`.

What is `$foo`? Where is it set and how can I change it? Will I use the image uploaded on the other pages (coded in the same module).

# Answer
Welcome to Drupal Answers. You just need to pass the fid integer value to the default value. To better understand what is fid see below description.

> fid is Unique File id that is stored in the database for each and every uploaded file using Drupal File System.

So, if you want to set default image then it should be uploaded via Drupal File System. Ideally, you need to store fid of the uploaded file in a variable using variable\_set in submit handler and do variable\_get in default value to set fid. That's it !!

Hope it answers :-)
> 6 votes

# Answer
User can use the $\_GET property if you are rendering file again without calling a submit function. If file is calling after submit function use the $form\_state\['values'\]\['file'\]

```

$form['file'] = array(
    '#type' => 'managed_file',
    '#upload_location' => 'private://',
    '#weight' => 5,
    '#upload_validators' => array(
      'file_validate_extensions' => array('gif png jpg jpeg doc docx pdf xls xlsx rtf odt tiff'),
    ),
  );

  if (isset($_GET['file'])) {
      $form['file']['#default_value'] = $_GET['file'];
  }

```
> 0 votes

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


# Question
Title: Disable Taxonomy Generated Teaser List Pages
I have a site that uses the Taxonomy module to categorize content. The vocabularies and terms are used as arguments and filters in various Views. I do not want the Taxonomy module to generate its own pages at URLs like "/taxonomy/term/1,2" . Is there an easy way to disable this functionality?

# Answer
Just install the Views module and enable the Taxonomy Term View. This will give the option to set the access permissions to *Authenticated* or *Administer* or any role or permission, preventing the page from being viewed by the public or robots.

PS: if you are not using Views, you have not yet discovered Drupal.
> 4 votes

# Answer
It's provided by the taxonomy module, so you can't disable it.

What you can do, is create a small module who override the path and redirect them to a drupal\_not\_found(), 15 lines and it's done.

Maybe there are some other ideas, I'm also curious to read them :)
> 3 votes

# Answer
This is a great use of the panels module. I do it on node /users and taxonomy terms i dont want to have a public face.

* Enable panels/ctools page manager
* Enable the "term template override
* Create a variant (using selection rules to limit to a vocabulary or term).
* When asked the type of panel variant specify http response code and pick from page not found or redirect.

How it works: panels takes over the renderig task from the taxonomy module and uses your selection criteria to serve up a variant of panels that simply emits a 403/301 error code. You can perform some pretty tricky redirects and selection magic with the use of contexts and selection rules. You should be using th emodules anyway because everything you have installed relies on ctools and panels is just the ctools page manager ui. ;)
> 1 votes

# Answer
This is how I did it in my own module called super\_security:

```
function super_security_init(){
  GLOBAL $user;
  if (!isset($user->roles[1])){// I want the admin to be able to see everything
    if (arg(0)=="taxonomy"){
      drupal_goto("somewhere_im_allowed_to_be");
      // OR drupal_not_found();
    }
  }
}

```
> 0 votes

# Answer
As you've discovered, the Taxonomy module's behaviour is to create a page for each term, on which teasers to all nodes tagged with that term are displayed as teasers.

To suppress the creation of these pages on a per-vocabulary basis use a module called Disable Term Node Listings.
> 0 votes

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


# Question
Title: How to show an alert when user navigates to another page without filling the form?
I have a form created by a custom module. Now I want to show an alert like ("`Please fil the complete form before navigating otherwise lost all the data`") if the user navigate to another page without filling all required fields.

How can I do so?

# Answer
> 2 votes
Below are a few modules to consider (quotes included are from the project pages of these modules), sorted by "my recommended one first". It'll depend on your specific requirements which one would fit best for you.

* Node Edit Protection (either for D6 or D7).

> A very simple JavaScript based protection that will alert a user if they are navigating away from a modified Node Edit form without saving. It uses a standard JavaScript confirm dialog that allows the user to either continue what they were doing, or cancel the move allowing them the opportunity to save. It marks the form as dirty by using the blur event of the node fields.
* SaveGuard (either for D6 or D7).

> ... adds javascript which detects if a form had been modified, and if it has, uses the onBeforeUnload event to pop up a warning to the user if they attempt to navigate away from the page without saving their changes. This works for Firefox, IE, and Safari, but not Opera.
* Dirty Forms (only an official release for D6, though for D7 there seems to be a trustworthy patch available also).

> ... provides a javascript behavior that checks forms before users leave the page, warning them if they are about to loose changes and providing an option to remain on the page.
>
> ... The module provides a configuration form that allows setting up a list of forms that should be excluded from the dirtyForms behavior.

---
Tags: forms
---


# Question
Title: Provide additional Status option for user_profile_form
I am writing the below code

```
     function mymodule_form_alter(&$form,&$form_state,$form_id){
      if($form_id == 'user_register_form' && $form_id == 'user_profile_form'){
        $form['account']['status']['#options'] = array(0 =>'Blocked', 1=>'Active', 2 => 'Closed', 3 => 'Ractive');
        }
     }

```

I am able to see the options at user register form but not in user profile form. How to add other option on user profile edit.

# Answer
> 1 votes
You have implemented `hook_form_FORM_ID_alter()`, which only fires for a single form (`user_register_form` in this case).

If you want to use multiple forms in a single function, you need `hook_form_alter()`:

```
function MY_MODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_register_form' || $form_id == 'user_profile_form') {
  ...
}

```

---
Tags: users
---


# Question
Title: How to change the currency symbol according to language in site?
I have enabled i10n, i18n, entity translation, title and variable modules and built a multilingual commerce site with language English as default language and $USD as default currency. And French and Poland as additional languages.

But I am unable to change the currency symbol in other languages.

How to translate currency symbol also?

# Answer
Have a look at the Currency module, here is a quote about it (from its project page):

> ... provides your website with currency conversion, currency information & metadata, and amount/price display functionality.

This module facilitates Localized price display. Here is an excerpt from that link also:

> ... displays prices/amounts based on users' locales, so they are formatted in a way that is familiar to them. The different formats can be configured at `Home » Administration » Configuration » Regional and language » Currency localization`. Locales consist of a language and a country, and formatting patterns are configured per locale.
> 1 votes

---
Tags: i18n-l10n
---


title: Trademark symbol in the site title?

text:
# Question
Title: Trademark symbol in the site title?
Do I need a module to put the trademark symbol in the site title? If I add `™` at the end of the title, it just gets output as is.

# Answer
> 1 votes
You can do this by using HTML TITLE module

> Drupal node titles are restrictive and do not support italicized text or superscript text (e.g., Book titles, trademark symbols). The HTML Title module allows a limited set of HTML markup (em, sub, sup, b, i, strong, cite, code, bdi, wbr) to be used in node titles. It filters all other markup from titles to prevent XSS vulnerabilities or irrational nesting (e.g., links within links).

---
Tags: 7
---


# Question
Title: How to add more information about authors with the Bibliography module?
We are setting up a **bibliography** for old and very rare resources with Drupal 7 and the Bibliography module. We need to have more information about authors (picture, biography, nationality). We have seen that we could link authors to users but in our case authors don't require to have a real user account (because most of the time authors are dead).

My questions:

* How can we add **more information** to authors?
* Is it possible to **create** some kind of **user account** without login, password and e-mail ?
* Would it be possible to **create** a specific **content type** for authors (with fields for picture, biography and nationality) and link it to the biblio author, and in that case how could we do this?

# Answer
Create another content type like "BookAuthor" with 1 node for each such Author. Then add fields to this content type for attributes such as picture, biography and nationality.

Assume you have a content type like "Ressources" (or just create one). Add a field in that content type using the Entity reference module for it (probably with multiple values allowed). That way you can add one or more "links" in each Ressources-node to relevant nodes of type BookAuthor.

PS: just to avoid possible surprises, I would not call the content type "Author" (which has a special meaning in Drupal, so better to not confuse Drupal with the same name for your extra content type).
> 0 votes

---
Tags: users
---


# Question
Title: Same drupal webform is showing error messages in two different way, on different palces in the same website
I am using drupal webform for my website, I am using single Contact Us form on multiple places in my website.

But the problem is on different places the way of showing error message is different, its not uniform through out the website.

Here is the image that shows the first way that how error messages comes-

and here is the image that shows the second way to show error messages-

I want first type of error messages which is in red box.

Please help me that how can I achieve this.

Thanks

# Answer
Try to use Webform Validation module. I hope through this you can solve your issue.

> This module adds an extra tab to each webform node, allowing you to specify validation rules for your webform components. You can create one or more of the predefined validation rules, and select which webform component(s) should be validated against those. By using the hooks provided by this module, you can also define your own validation rules in your own modules.
> 0 votes

---
Tags: webforms
---


# Question
Title: Restrict admin to search specific content types
1.Using search configuration module I have restricted the user role to search particular content type, this worked for me. But when I tried to apply the same approach to administrator this did work. I have unchecked the `Admin bypass (primary user with id 1)` the option too.

Is there a way to restrict the admin too to search specific content ?

2.And my second issue is about pagination, using the same module pagination is successfully applied, but for admin it is default set to 10 items per page, can I alter this?

# Answer
I don't think so; you would have to either:

1. Create a new role and then limit search configuration for that node.
2. Use Views to simply create another page for administrators where they can search the title/body, limited to a certain type.
3. Install Views Bulk Operations and Admin Views which will then allow you to change the *default* administration pages, and limit the displayed content types if you want.
4. If you need more complex search, look into Search API with Search API Database Search. These modules integrate with Views and you will be able to cover more complex scenarios.

Solutions 2, 3 and 4 use Views, so you will be able to change the number of items displayed per page.

Hope this helps.
> 0 votes

---
Tags: 7, search
---


# Question
Title: The drush command 'sql dump' could not be found
Im a trying to do a backup of my drupal site with:

```
drush -v sql dump --result-file=DrupalBackups/nameofsqldb5.sql

```

but it results in following error message:

```
The drush command 'sql dump' could not be found.  Run `drush cache-clear drush` to
[error] clear the commandfile cache if you have installed new extensions.

```

I ran drush cache-clear drush but without success.

Any ideas?

# Answer
> 3 votes
The actual command is `sql-dump` not `sql dump`

```
drush -v sql-dump --result-file=DrupalBackups/nameofsqldb5.sql

```

From `drush help`:

> sql-dump Exports the Drupal DB as SQL using mysqldump or equivalent.

---
Tags: drush
---


# Question
Title: A way/module to display a list of Blocks assigned to specific path?
OK, this is a bit tricky to explain, but I hope you understand what I'm looking for.

I have a lot of nodes created with the 'Basic page' content type, and at least 20 different blocks assigned to each Basic page. I'm wondering whether there is a way (or a module) the display a list of Blocks in the Drupal backend that are ONLY assigned to one node? There are 20 blocks assigned to each Basic page, and lots of Basic pages, therefore it is tricky to identify which Blocks are displayed on which page with the huge list I see in the Drupal Blocks page.

What would be good is if there was a way to filter Blocks on the admin page by path that they are set to, or something like that?

This is what I'm looking for, is there a module?

# Answer
> 0 votes
I not sure have I understand your question.

At the picture below you can set it two path. Exmaple:

Page\_1

Admin\_Block\_Page

Another one will be:

Page\_2

Admin\_Block\_Page

When you go to Admin\_Block\_Page, it will display block in Page one and Block in Page two.

Another Method: views
Module:https://www.drupal.org/project/views
You tube: https://www.youtube.com/watch?v=3L9JLZOb\_LQ

---
Tags: 7, blocks
---