# Question
Title: Drupal Views: Add Views signature to all SQL queries adding view name to Inner Join
When I preview my view, I get an error and notice that the view signature in the query was added twice. The one that's an issue is:

```
':default' AS view_name

```

Here is the full query.

```
SELECT DISTINCT taxonomy_term_data.tid AS tid, taxonomy_term_data.name AS taxonomy_term_data_name, taxonomy_term_data.vid AS taxonomy_term_data_vid, taxonomy_vocabulary.machine_name AS taxonomy_vocabulary_machine_name, 'video_categories:block' AS view_name
FROM {taxonomy_term_data} taxonomy_term_data
INNER JOIN {node} node_taxonomy_term_data ON (SELECT nodeINNER.nid AS nidINNER, ':default' AS view_name
FROM {node} nodeINNER
LEFT JOIN {taxonomy_index} taxonomy_indexINNER ON nodeINNER.nid = taxonomy_indexINNER.nid
LEFT JOIN {taxonomy_term_data} taxonomy_term_data_nodeINNER ON taxonomy_indexINNER.tid = taxonomy_term_data_nodeINNER.tid
WHERE (( (taxonomy_term_data_nodeINNER.tid = taxonomy_term_data.tid ) ))
ORDER BY nodeINNER.nid DESC
LIMIT 1 OFFSET 0) = node_taxonomy_term_data.nid
LEFT JOIN {taxonomy_vocabulary} taxonomy_vocabulary ON taxonomy_term_data.vid = taxonomy_vocabulary.vid
WHERE (( (taxonomy_vocabulary.machine_name IN  ('video_category')) ))

```

The error I get is:

```
SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 2 column(s)

```

Which makes sense since I am not expecting the second parameter to be in there for view\_name. Why does it do this and how do I stop this feature from adding the view\_name to the inner join on my query?

When I uncheck this box, the query works as expected, however, I use the signature in my reporting to quickly identify issues, slow queries etc.

# Answer
The issue was the relationship added to the view. I removed the relationship and this fixed my issue.
> 0 votes

---
Tags: views
---


# Question
Title: Is it possible to change all node assigned on TermA to TermB?
We are going to delete TermA, and there are a lot of pages under TermA. How can I assign those pages into TermB (already exist) without manually one by one?

# Answer
> 2 votes
The Views Bulk Operations module can achieve this in one fell swoop.

Build a page view that lists the titles of your nodes and is filtered to nodes of Term A. Add a field "bulk operations" (if on D7) and set it to modify entity values then select your term field that you want to bulk update. You'll then be able to mass update your nodes, and can replace Term A with Term B

---
Tags: taxonomy-terms
---


# Question
Title: Domain Access separate home page per domain does not work
I have 3 domains set up on my dev machine. 1)drupalx 2)drupaly 3)localhost

Hello, I am using:

Domain Access 7.x-3.11 (with at domain configuration and domain setting enabled) Internationalization 7.x-1.10.

I JUST enabled domain configuration/domain settings modules to try and get a separate home page per domain. Before I was using domain access without these 2 helper modules.

I am attempting to set my home page per domain. There appear to be 3 ways to do this and none of them are working correctly.

Option 1) setting the values in /config/system/site-information

With this approach and Domain Access there is a domain access section at the bottom of the site-information page. You are supposed to set the home page and then choose which domain it is for and then save. In this domain access section it is supposed to show all the domains you have created, but mine says "localhost" for all of them. Looking at domain access options for my content types (related side topic) shows that now the options for the other domains are missing there as well. It ONLY says "localhost". It used to say localhost, drupalx, drupaly, but as I saved the front page for each of those domains the save process changed the machine name for drupalx and drupaly to "localhost" I am able to go back to each domain individually and change back it's machine name (but weird that it changes that). After saving I get a message "The configuration options have been saved for localhost. These settings will be inherited unless overridden per domain." Meaning it is saving that front page for every domain available (checking confirms this)

Option 2) First setting section in "admin/structure/domain/view/2/config" Here you can set a separate home page per domain but when you go to the home page of those domains there is no front page defined (it just doesn't work).

Option 3) Second settings section in "admin/structure/domain/view/1/variables" Here you just set the front page per domain. Anytime I put any value in here after the page saves and reloads that value is gone, re-replaced by "node". This does not work either.

I only enabled domain configuration and domain setting modules to try and get some extra configuration options to set my front pages per domain. Didn't get me anywhere. I of course tried to set the home page before enabling domain configuration and domain setting modules, and that didn't get me anywhere either.

Anyone have any front page advice for any of these front page configuration settings I tried?

# Answer
If you are using panels, you can create one homepage, but with separate variants for each domain. We use this approach for ~12 sites running on one drupal instance.
> 3 votes

# Answer
I am using the technique you labeled "option 2" above; it works fine. I put "node/835" in for the site frontpage for one domain, and that node is in fact shown as the front page for that domain.

One striking thing that I notice in your screenshots above is that your URLs read `http://localhost/projects`. Domain access is designed to use the domain name from the http headers to select which subsite to use. You should add entries to your etc/hosts file for dev.subsite1.domain.com, dev.subsite2.domain.com, and so on, all pointing to localhost (127.0.0.1). You'll also need to set up a virtual host configuration file for each of your subsites. In the "aliases" tab for subsite1.domain.com, add an entry for "dev.subsite1.domain.com", and so on for each of your subsites.

If you do all of this, and if you have also added the requisite `include DRUPAL_ROOT . '/sites/all/modules/domain/settings.inc';` to the end of your settings.php file, then your domain access settings such as the front page configuration should work just fine.
> 0 votes

---
Tags: 7, domain-access
---


# Question
Title: Using search_api and search_api_views how do I display images?
Drupal-7. search\_api\_solr 7.x.1.4 search\_api\_views 7.x-1.11

I have an index of documents and associated commerce products. The commerce product has an image in it. I can get views to display an index of the image url, but not display the images.

The image is displayed fine with a sql backed (non-solr) view.

# Answer
> 0 votes
We updated ctools to 7.x-1.4 and it started working.

---
Tags: views, commerce, search
---


# Question
Title: Customizing the Tag page shown by default in Drupal 7
I made a field in one of my content types as Tags. On the site, they are shown as follows:-

**mytag\_1, mytag\_2, mytag\_3.**. When I click on either of them, they show me all the pages which are tagged with the clicked tag. How is it doing is beyond me, as I didn't even enable the view.

This is the URL it uses:- www.mysite.com/tags/mytag\_1

Now, my question is how can I customise it. Now it uses node.tpl.php and shows all the pages. I wanna change the layout but don't know how to, as I don't know how these pages are generated.

I also tried making pages as node--tags.tpl.php but to no avail.

Any help?

# Answer
The ideal way to customize the tags pages(www.mysite.com/tags/mytag\_1) is to enable the view "Taxonomy term" and then customize it the way you need it. As you might already know Views provides much more flexibility and easy to customize.

If you do not want to use Views and only want to update the template then refer to the link
> 1 votes

---
Tags: taxonomy-terms, meta-tags
---


# Question
Title: How to restrict download file for authentication in drupal
I have create one file field in my node create form , file is accepting (txt,pdf,xlx,docx) files only. but in node view page, i want to authenticate our file before download.

I have create one term and condition checkbox, if user check this term and condition checkbox , then he should be able to download the file..

This functionality i need to do, please suggest me any module is available for this..

or if this functionality is possible through conditional fields , so please suggest me, how can i do

# Answer
You can try Field Permission Module

> The Field Permissions module allows site administrators to set field-level permissions to edit, view and create fields on any entity.

Demo Video
> 3 votes

---
Tags: hooks, files
---


title: need a special image slider with views

text:
# Question
Title: need a special image slider with views
Is there any module that works with views and slide images like the following image?

so far I've found about 13 image slider in Drupal but non of them does such thing.

# Answer
you can achieve that by jCarousel module

> This module allows developers and themers to make use of the jCarousel jQuery plugin. It includes a developer API that other modules can use, as well as Views integration in the 2.0 version so that you can turn any list of content or images into a carousel.
> 1 votes

---
Tags: views, javascript
---


# Question
Title: How to populate DB values in content type field, drupal 7
I have created a content type with 4 field in Drupal 7. One field is of list type, say for listing countries. I have tables in DB for saving country\_id and country\_name. Is there any way to connect the DB table and content type field? I want to list all these countries in the content type's country field.

# Answer
> 1 votes
You have to install Content Construction Kit (CCK) module. After installing this module you get a text field for Allowed value function in field setting of desired field. Put the function name here to get country list. Also put following function in a module. You may have to modify query as per your requirement. After doing all these thing you will able to get country list in that field.

```
function _get_country_list(){
    $country = array();
    $query = db_select('country', 'c');
    $query->fields('c', array('country_name','country_id'));
    $result = $query->execute();
    if ($result) {
        while ($row = $result->fetchObject()) {
            $country[$row->country_id] = t($row->country_name);
        }
    }
    return $country;
}

```

# Answer
> -2 votes
You could make use of `views.api`

Implement views API

```
function MYMODULE_views_api() {
    return array(
        'api' => '3.0-alpha1', // Youre api version
        'path' => drupal_get_path('module','MYMODULE'). '/views',
    );
}

```

and create a file named `MYMODULE.views.inc` put it in `/views` folder

Read available functions here `views.api.php`

# Answer
> -2 votes
If I understood your question right, you was to show a list of countries in your content type field. There is a module for that. Take a look at the countries module.

You can also use the addressfield module if that fits your needs.

**Edit:**

you need to create a custom field widget in that case. Take a look at the examples module. Here's a tutorial for the same. Besides, there is a provision in countries module to disable specific countries.

---
Tags: 7, database
---


title: Sending yourself a copy of the email

text:
# Question
Title: Sending yourself a copy of the email
I m using Drupal 7 with the Webform module to send email. On a form I have checkbox to send yourself an email copy. When it is checked, there will be a field to enter the email of who sends the email. The email should be send to this address also.

# Answer
> 0 votes
I created a custom module for this functionality. This module file used for creating a send a copy of message to me functionality

```
function sendmail_webform_form_alter(&$form, &$form_state, $form_id) {
     error_reporting(E_ALL);
     ini_set('display_errors', 1);
     // webform_client_form_52  webform id
     if($form_id == 'webform_client_form_52') {
         $form['submitted']['send_a_mail_yourself'] = array(
         '#type' => checkbox,
         '#form_key' => 'send_a_mail_yourself',
         '#title'=> 'Send a copy of yourself',
         '#weight' => 4, // As your needed
         '#field_prefix' => '<div id=\'send_a_mail_yourself\'>',
         '#field_suffix' => '</div>',
         '#default_value' => array('yes' => t('send a copy of yourself')),
       );
       $form['#submit'][] = '_sendmail_webform_submit';

       }
     }

   function _sendmail_webform_submit($form, &$form_state) {
     $param = array();
     foreach($form_state['input']['submitted'] as $key => $values) {
        if(valid_email_address($values)) {
             $to = $values; //to email address
        }
        else if($key == 'send_a_mail_yourself' && $values == 1) {
              $send_a_mail = $values;  // Check send a mail to yourself checkbox

        } else {
          if($values) {
               $param[]  = $values;  // All remaining values to store to param array for use of email body
          }
        }
       }

          if($send_a_mail == 1) {
         $from = 'noreply@example.com';
                 foreach($param as $param_values) {
            $body[] = $param_values;
           }

        $to = $to; // Set this email address - emails will be sent to this email address!
        $params = array(
            'body' => $body,
            'subject' => 'Website Information Request',
     );
        if (drupal_mail('sendmail_webform', 'some_mail_key', $to, language_default(), $params, $from, TRUE)) {
            drupal_set_message('Thanks, we will be in contact with more information soon.');
     } else {
            drupal_set_message('There was an error subscribing you. Please try again later');
        }

    }
  }

 function sendmail_webform_mail($key, &$message, $params) {
     $headers = array(
         'MIME-Version' => '1.0',
         'Content-Type' => 'text/html; charset=UTF-8;',
         'Content-Transfer-Encoding' => '8Bit',
         'X-Mailer' => 'Drupal'
    );
    foreach ($headers as $key => $value) {
         $message['headers'][$key] = $value;
    }
      $message['subject'] = $params['subject'];
      $message['body'] = $params['body'];
 }

```

# Answer
> -2 votes
There are two types - Custom and Component, if You select custom you can write your own like: test@gmail.com. For Component - the submitted form field value will send email. For your requirement simply add another email custom : admin@example.com

---
Tags: 7, webforms
---


title: text overlay image views

text:
# Question
Title: text overlay image views
I want to show images on my website. website example

When I hover over the images, the page title shows up. But when you move with your cursor over the text it won't link to my colorbox popup. How can I solve this problem. I've been looking for a long time.

I've used the rewrite results to get the title on hover.

# Answer
> 0 votes
There are 2 solutions:

1. use `title` as the text and it will automatically redirects you to the content page when you click on it.
2. in your `views` add the path field to your fields,

apply it and now check the `exclude from display` checkbox in its setting. go to `Rewrite Results` and set these settings:

click ok and move the path field at the top of the fields.

Now click on the field that displays your text on the image and set these settings:

Now that field will be a link to your content.

---
Tags: views
---


title: Drupal Views page into a menu subitem

text:
# Question
Title: Drupal Views page into a menu subitem
Somehow I cannot get the result I want. I have a view that produces a page and I am offered to have this as a menu item in menu of my choice. But what I actually want to achieve is to nest it as a menu item of a MENU ITEM of main menu, such as in:

\[main menu\] \> Downloads \> PDF Diagrams

Is that possible at all?

Artur

# Answer
> 3 votes
As far as I understand your question,
after creating menu item entry within Views UI
you can go to chosen menu configuration (`admin/structure/menu` for D7) and set parent for your new entry as you would like.

# Answer
> 0 votes
Yes it is, and is also the preferred way. You need to set the proper values on the views configuration page under **Page Settings**.

Make sure that:

* you have everything set up the way you want it under **Menu** (Title, Description, Weight, Parent Menu, etc).
* the view's page path is set up properly. Let's say you wanted as a child of a menu item with an **/admin/custom** path, then you should set the view's path to something like **/admin/custom/myview**

---
Tags: views, routes
---


# Question
Title: responsive tabs (tab to accordion on small screen width)
I have a task of building a responsive website with custom theme and all that good stuff. One thing I stumbled across is using tabs to display data.

Tabs are a requirement in the site but they are not responsive. I have seen some wordpress sites that have this nice feature of turning tabs into accordion when the screen width is small.

Unfortunately I could not find a way to implement that in Drupal so far. The only way that I thought of is loading to view blocks (1 tabs and 1 accordion) and show/hide one of the two based on screen width using JS but this solution is not an efficient one.

Please let me know if there is a way in which I can accomplish this task.

# Answer
Short way : download Easy Responsive Tabs to Accordion Jquery plugin, add it to your theme and call the `easyResponsiveTabs` function for your HTML tabs markup.

**Drupal Solution with Panels :** use Panels responsive tabs to accordion, a sandbox project which provides a Responsive Tabs to Accordion Panel style.

1. Install Panels module.
2. Install the sandbox project. This was a quick done project (no time to develop the admin options) so you may have to modify a few lines in `responsive_tabs.inc` to set up the paths to css or js files and/or HTML markup in `responsive_tabstoaccordion_panels.js`.
3. Go to your region Panel style and choose the new style **Responsive Tabs to Accordion**
> 1 votes

---
Tags: theming
---


title: Resolving internal image paths?

text:
# Question
Title: Resolving internal image paths?
Inside my template.php I am populating a custom variable to be used inside my **views-view-unformatted--latest\_stories.tpl.php**

The image data associated with the content type has the structure:

```
[field_photos] => Array
    (
        [und] => Array
            (
                [0] => Array
                    (
                        [fid] => 4
                        [uid] => 1
                        [filename] => DSCF2639_0.jpg
                        [uri] => public://story/photos/DSCF2639_0.jpg
                        [filemime] => image/jpeg
                        [filesize] => 129245
                        [status] => 1
                        [timestamp] => 1397504538
                        [alt] =>
                        [title] =>
                        [width] => 800
                        [height] => 600
                    )

                [1] => Array
                    (
                        [fid] => 5
                        [uid] => 1
                        [filename] => DSCF2657.jpg
                        [uri] => public://story/photos/DSCF2657.jpg
                        [filemime] => image/jpeg
                        [filesize] => 89144
                        [status] => 1
                        [timestamp] => 1397504538
                        [alt] =>
                        [title] =>
                        [width] => 800
                        [height] => 600
                    )

            )

    )

```

How do I translate the path to a URI which a browser will be able to resolve?

Do I simply strip the public://

What if I move my files to AWS at a later date? Is there a function in drupal API that will handle this for me???

# Answer
You can use the handy `file_create_url()` function:

> Creates a web-accessible URL for a stream to an external or local file.
> 1 votes

---
Tags: media
---


# Question
Title: Cannot access empty property in /var/www/clients/client1/web9/web/modules/field/field.attach.inc
I was deleting nodes using Views Bulk Operations and suddenly I got a white screen.

In my error log I get the following error:

> mod\_fcgid: stderr: PHP Fatal error: Cannot access empty property in /var/www/clients/client1/web9/web/modules/field/field.attach.inc on line 324

I'm using domain module and my other subdomains work fine, but my main domain always gives me a white screen with that error.

Does anyone know what I can do to fix this?

# Answer
> 1 votes
This solved my problem: https://drupal.org/node/2051839

Apparently there's something wrong with my image field of a slider, I have no idea that happened during bulk delete of a different content type.

---
Tags: 7, views
---


title: Show node hit counts in a VIEW?

text:
# Question
Title: Show node hit counts in a VIEW?
I have googled and found a few articles:

http://nossdutytask.com/drupal\_config/step\_by\_step\_enable\_view\_post\_access\_counter\_on\_drupal

Only I don't want to show the counter as a block but as a field in a VIEW. I followed the above article but when I add fields to my view I cannot find any stat or counter or anything.

Is this possible without writing a custom module or tweaking my template.php and populating this value programmatically?

# Answer
> 3 votes
You need to enable the **Statistics** module from admin/modules.

Configure what you want to track from admin/config/system/statistics

Then edit your view. Add a **Field**. There will be a category called **Content Statistics** that you can filter on. Choose the stat you want, and then configure it.

The above is for Drupal 7 / Views 3. The steps are mostly the same for Drupal 6 and Views 2 or Views 3, but the labels are a little different.

Just keep in mind that **Statistics** module can cause performance problems on busy sites. You may also want to check out Radioactivity, and see if that will work better for you:

> This module provides a field type which can be used as a hotness metric or a regular view counter for entities and for much much more. In essense, entities receiving attention (views or actions defined by Rules) are heated while inactive ones slowly cool down.

Radioactivity does integrate with Views and a few places.

---
Tags: views, nodes
---


# Question
Title: Add a taxonomy term to many vocabularies
Is there is any way to add one term to many vocabularies with the same name and same id in drupal 7

# Answer
> 1 votes
I don't think it's possible. It's always one to one relationship between vocabulary and term...

If you see taxonomy\_term\_data table which stores term id and vocabulary id reference below..

tid is primary key which means always unique. So, you can't have another row which points to different vid.

Below schema definition in taxonomy.install confirms same..

```
  $schema['taxonomy_term_data'] = array(
    'description' => 'Stores term information.',
    'fields' => array(
      'tid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary Key: Unique term ID.',
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The {taxonomy_vocabulary}.vid of the vocabulary to which the term is assigned.',
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The term name.',
        'translatable' => TRUE,
      ),
      'description' => array(
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
        'description' => 'A description of the term.',
        'translatable' => TRUE,
      ),
      'format' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'description' => 'The {filter_format}.format of the description.',
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The weight of this term in relation to other terms.',
      ),
    ),
    'primary key' => array('tid'),
    'foreign keys' => array(
      'vocabulary' => array(
        'table' => 'taxonomy_vocabulary',
        'columns' => array('vid' => 'vid'),
      ),
    ),
    'indexes' => array(
      'taxonomy_tree' => array('vid', 'weight', 'name'),
      'vid_name' => array('vid', 'name'),
      'name' => array('name'),
    ),
  );

```

---
Tags: taxonomy-terms
---


title: Adding an Image Style

text:
# Question
Title: Adding an Image Style
I'm new to Drupal, and I'm attempting to add an image style to a Basic Page in the "Manage Displays" area. After savings, there is no effect with the images on my basic pages (i.e. the image style was not applied) What would cause this, and how can I fix it?

Thanks! (PS - I'm sure this is probably a novice question.)

# Answer
I think you are maybe looking at the Default display (top right corner of page). Make sure you are on the Full Content, or Teaser (as the case may be) to make the appropriate changes.
> 0 votes

# Answer
I think (if i did understand you correctly) you need to add a new image style first and then you apply it to your image in the manage display area.

you can add a new style by going to admin/config/media/image-styles and then click on "Add Style"
> 0 votes

---
Tags: media
---


title: Error while running "drush st"

text:
# Question
Title: Error while running "drush st"
On a Linux system I installed Drush 7 with Composer. When I try to use it with Drupal 8 alpha-11, for example running `drush st`, I get this error. I looked around but I can't find anything about it.

> PHP Fatal error: Class 'Drupal\Core\Site\Settings' not found in /home/$USER/.composer/vendor/drush/drush/commands/core/drupal/environment.inc on line 278
> Fatal error: Class 'Drupal\Core\Site\Settings' not found in /home/$USER/.composer/vendor/drush/drush/commands/core/drupal/environment.inc on line 278
> Drush command terminated abnormally due to an unrecoverable error.
> Error: Class 'Drupal\Core\Site\Settings' not found in /home/$USER/.composer/vendor/drush/drush/commands/core/drupal/environment.inc, line 278

# Answer
I found the same issue. Upgrading Drupal 8 to the latest change (8.x branch instead of the alpha11 version) Drush works properly.
> 1 votes

---
Tags: 8, drush
---


# Question
Title: Cloned node entity reference field stay in sync with parent node
I have three content types A, B and C. A have entity reference fields to B and C. I create a Node of type A say a1. When i clone a1 node as a2 with node clone module i get the same value for entity reference fields in a2 same as a1. In a2 i can change the entity reference field value so that they refer to another nodes of B and C content type.

But with node clone module there is no way to maintain relationship between parent node and cloned node.

So I basically have two requirements:

1. In cloned node i can override the entity reference field value or leave it same as parent node. If i override, later i should be able to revert back to those values same as parent node. Currently there is no way to do this.
2. If parent node change the value of those entity reference fields then in all the cloned node of this parent node also change their respective entity reference field value except overridden cloned nodes.

The solution i found so far during searching is using Replicate, replicate\_ui module which provide more hook to alter the cloning process. The another module is Corresponding Entity References which create entity reference field back to parent node.

I don't need comprehensive solution but anything existing solution can do almost this functionality?

# Answer
> 0 votes
1) You could use a hidden field of the same type with the same information. This way, the information relating the parent to child can be reverted, regardless of the changes or overrides. Use Rules to populate the duplicate field. Create a "Revert" button on the node and again use Rules, or as a form submit to react to copy the information from the hidden field to the visible one.

2) Use Rules to adjust any child nodes when the parent is saved/updated. This would act on both the hidden and visible field, with a condition on the visible (not to change if it has been overridden).

You could also write a module to do this, but I think it can be done with just Rules.

---
Tags: entities
---


title: View API connection to external DB

text:
# Question
Title: View API connection to external DB
I've a Drupal 7 site setup on an AWS server, and I'm trying to access a mysql db on a AWS RDS.(The Drupal db is located on the Drupal server, the table I'm trying to get is just to access some external data).

When I try to use the Views API I get the following error:

> PDOException: SQLSTATE\[HY000\] \[1045\] Access denied for user 'drupal\_viewer'@'localhost' (using password: YES) in views\_plugin\_query\_default-\>query() (line 1293 of /opt/bitnami/apps/drupal/htdocs/sites/all/modules/views/plugins/views\_plugin\_query\_default.inc).

I've setup the mysql user "drupal\_viewer" with the correct permissions, and to verify that I've created a short php page in the root folder of the Drupal server. When I run that, it runs fine and connects and executes a test query. So that verifies that the security groups etc are fine and that my Drupal server can "see" the RDS instance.

I've tried various combinations of the user on the mysql setup (@%, @localhost and @127.0.0.1), but the views API keeps trying 'drupal\_viewer'@'localhost' which is failing.

I have the db info setup correct in my settings.php (and have done Clear Cache etc).

```
$databases['pc_propertychannel']['default'] = array (
  'database' => 'propertychannel',
  'username' => 'drupal_viewer',
  'password' => 'xxxxxx',
  'host' => 'pc-live-main-db.xxxxxxxxx.eu-west-1.rds.amazonaws.com',
  'port' => '3306',
  'unix_socket' => '/opt/bitnami/mysql/tmp/mysql.sock',
  'driver' => 'mysql',
  'prefix' => '',

```

);

What am I forgetting?

\[Edited to Add: as a debug, I tried connecting via mysql console from the Drupal server to my RDS instance, using the above credentials, and it works fine. So I'm thinking this may be a Drupal config/issue?\]

# Answer
> 0 votes
Eventually figured it out! (obvious in hindsight!)

I shouldn't have had the line:

```
'unix_socket' => '/opt/bitnami/mysql/tmp/mysql.sock',

```

in the database setting in settings.php

Removed it for the remote db's and it works perfectly.

---
Tags: views, 7, database
---


# Question
Title: Upgrading from 7.22 to 7.28, htaccess file in /tmp
I get this error :

My .htaccess file in that directory looks like this now (I copied it from the url):

```
# Turn off all options we don't need.
Deny All
Options None
Options +FollowSymLinks

# Set the catch-all handler to prevent scripts from being executed.
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
<Files *>
  # Override the handler again if we're run later in the evaluation list.
  SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003
</Files>

# If we know how to do it safely, disable the PHP engine entirely.
<IfModule mod_php5.c>
  php_flag engine off
</IfModule>

```

I still get said error. Why?

# Answer
> 2 votes
Make sure your file system settings are set to /tmp or tmp, then...

In the tmp folder, select the htaccess and delete it from your FTP, then refresh your site cache.

Drupal will replace the missing .htaccess automatically.

# Answer
> 0 votes
First, your Deny directive has a syntax error. It should read

```
Deny from all

```

If this doesn't fix your problem, make sure your temporary directory is set correctly in admin/config/media/file-system. If you still have the problem I would suspect an Apache configuration problem.

# Answer
> -2 votes
As far as https://drupal.org/SA-CORE-2013-003; It suggests,

> To fix the code execution prevention vulnerability on existing Apache installations also requires changes to your site's .htaccess files in the files directories. Until you do this, your site's status report page at admin/reports/status will display error messages about the problem. Please note that if you are using a different web server such as Nginx the .htaccess files have no effect and you need to configure PHP execution protection yourself in the respective server configuration files.
>
> To fix this issue, you must edit or replace the old .htaccess files manually. Copies of the .htaccess files are found in the site's files directory and temporary files directory, and (for Drupal 7 only) the separate private files directory if your site is configured to use one. To find the location of these directories, consult the error messages at admin/reports/status, or visit the file system configuration page at admin/settings/file-system (Drupal 6) or admin/config/media/file-system (Drupal 7). Note that you should only make changes to the .htaccess files that are found in the directories specified on that page. Do not change the top-level .htaccess file (at the root of your Drupal installation).
>
> Go onto your server, navigate to each directory, and replace or create the .htaccess file in this directory with the contents described below. Alternatively, you can remove the .htaccess file from each directory using SFTP or SSH and then visit the file system configuration page (admin/settings/file-system in Drupal 6 or admin/config/media/file-system in Drupal 7) and click the save button to have Drupal create the file automatically.
>
> The recommended .htaccess file contents are as follows.
>
> For Drupal 6:
>
> # Turn off all options we don't need. Options None Options +FollowSymLinks
>
> # Set the catch-all handler to prevent scripts from being executed. SetHandler Drupal\_Security\_Do\_Not\_Remove\_See\_SA\_2006\_006
>
> Override the handler again if we're run later in the evaluation list. SetHandler Drupal\_Security\_Do\_Not\_Remove\_See\_SA\_2013\_003
>
> # If we know how to do it safely, disable the PHP engine entirely. php\_flag engine off
>
> # PHP 4, Apache 1. php\_flag engine off
>
> # PHP 4, Apache 2. php\_flag engine off For Drupal 7:
>
> # Turn off all options we don't need. Options None Options +FollowSymLinks
>
> # Set the catch-all handler to prevent scripts from being executed. SetHandler Drupal\_Security\_Do\_Not\_Remove\_See\_SA\_2006\_006
>
> Override the handler again if we're run later in the evaluation list. SetHandler Drupal\_Security\_Do\_Not\_Remove\_See\_SA\_2013\_003
>
> # If we know how to do it safely, disable the PHP engine entirely. php\_flag engine off Additionally,
>
> the .htaccess of the temporary files directory and private files directory (if used) should include this command:
>
> Deny from all

---
Tags: .htaccess
---


title: Simple webform with payment module

text:
# Question
Title: Simple webform with payment module
what I need do is not an ecommerce site.

On my drupal website I need **a simple web form with a payment** (by *paypal*) and a node reference field prepopulated (by the *entity refence* and *entity reference prepopulate* modules).

The scenario is this:

I have a content type called **Team**. Only the admin can add nodes for this content type. This content type *has field of type user reference* (by *entity reference* module). This field is empty to default.

Now, when an authenticated user visits one of this nodes, he can click on a link *Administer this team!*. If he click on this link, he go on the payment form and it set the referenced node field to the clicked node id. Now with the payment webform he can pay. **The price is always 49 Euro, so he doesn't need set it.**

After the payment I would like **set an action** (by rules module) that fetch the user that pay, the referenced node and set the user on the user reference field on the node. In this way, trough the *nodeaccess\_userreference module*, the user can start to administrate his team's page...

Hi tried to do this with the *payment* module beacause this has a good implementation with *rules* module, but I don't understand how to do a simple webform (at the url www.example.com/pay-your-team) with the reference to the node and without allow to the user change the price.

Can you help me?!

Thanks a lot!

# Answer
You need to create a custom module for this. You'll have to learn how to use PayPal's SOAP requests and handle it that way.

This question, as it is now, is FAR too broad in scope to answer in this forum beyond that though.
> 0 votes

---
Tags: webforms, rules
---


title: Merge Rows and Views PDF integration

text:
# Question
Title: Merge Rows and Views PDF integration
I've got a view that outputs a pdf business card for every student with all the classes he attends. Someting like this:

```
2014
Name Surname
class1, class2, class3

```

To associate students and classes I use a Session content type with fields: year, entity referenced student and entity referenced class (Students and Classes are separated content types as well).

Because I need to control the exact position of every field on the final pdf, I use views PDF. To achieve that some kind of "GROUP\_CONCAT" on classes I succesfully used Merge Rows module.

My query is ok. If I try it on page display everything is all right, but when I try to make a PDF display using views PDF it shows just one value, not the entire comma separated string of classes. I've tried many combinations of merge rows settings, played with custom html output of fields, but **it seems that Merge Rows doesn't work on PDF display**. Any idea to make this work?

As suggested for invoices in the paragraph "Append and Include other Views" from views PDF documentation, I also tried to split the view into two separate views: the main and the secondary view of classes included as a field but with no success. The classes view doesn't filter content using the contextual filters passed by the main view. Removing contextual filter, I can see classes under student name, but all of them. And the query is really slow...

Another solution could be to rewrite the SQL using GROUP\_CONCAT (I use MySQL)... But how?

What should I do?

Thanx in advance

# Answer
Finally I solved applying this patch to views in order to get GROUP\_CONCAT as an aggregate function in views UI and uninstalled views\_merge\_rows. I think this is a better solution from a sql query performance point of view: views\_merge\_rows simply changes how data appear. Probably I was wrong in configuring something in it but I won't investigate any more.

Thanx all for reading... ;-)
> 0 votes

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


# Question
Title: Views Field Show "NEW" if less than 1 day old
I am displaying webform submissions in a view, and need to add a "NEW" notification if the submission is less than a day old.

I have created views-view-field--myfield.tpl.php and have managed to change the value of my field using the template.

I am grabbing the submitted date, which I have printed already to make sure it works, and it comes up as `13/05/2014 - 23:13`

I am then trying to figure out how to return a value for a date that is less than 1 day old. I'm pretty sure the following should do it, but it always renders "not new".

```
<?php
$submitted = $view->style_plugin->rendered_fields[$view->row_index]['submitted'];

if( $submitted > strtotime('-1 day') ) {
  echo '<div style="color:red;">NEW!</div>';
}
  else
{
  echo 'not new';
}
 ?>

```

Can anyone see where I'm going wrong?

**UPDATE:**

So, this works...

```
if( strtotime('14 May 2014') > strtotime('-1 day')) {
  echo '<div style="color:red;">NEW!</div>';
}
else
{
echo 'nothing <br />';
}

```

If i set it to 14th may (today) Its shows up as NEW! , any earlier, it prints nothing.

So, this leads me to believe there is a problem with my submitted date.

But, If I put `echo $submitted;` i get `13/05/2014 - 23:13`

If I put `$newDate = date("d M Y", strtotime($submitted)); echo $newDate;` i get `01 Jan 1970` for every result.

And If I put `$newDate = date("d M Y", $submitted); echo $newDate;` I also get `01 Jan 1970` for every result.

So now I don't know what's going on. If its not in timestamp format, strtotime should sort it shouldnt it?

# Answer
Probably need to strip the html from `$submitted` and convert to timestamp first, e.g something like:

```
$submitted = $view->style_plugin->rendered_fields[$view->row_index]['submitted'];

if (strtotime(strip_tags($submitted)) > strtotime('-1 day')) {
  echo '<div style="color:red;">NEW!</div>';
}

```
> 0 votes

---
Tags: views
---


# Question
Title: error_get_last() returns NULL after valid error in Drush
I have the following command callback function defined in my .drush.inc file:

```
function drush_bv_ftp_products() {
  echo $aadfadf;
  var_dump(error_get_last());
}

```

Assume `hook_drush_command()` is properly implemented and has an alias of 'abc'.

When I run `drush site.local abc` I get NULL for output. What I would expect to see is similar to:

```
Array
(
    [type] => 8
    [message] => Undefined variable: aadfadf
    [file] => ...
    [line] => ...
)

```

I'm running php 5.3.28 so `error_get_last` is there. Any thoughts from the Drush masters out there as to what could be going wrong here?

# Answer
> 1 votes
Drush sets an error handler via `set_error_handler('drush_error_handler');`. This interferes with the operation of error\_get\_last()\`, as php resets the last error when the error handler is called; error\_get\_last() always returns NULL with an error handler, even if it is the first function called in the handler.

Since there is no way to disable the Drush error handler, this prevents the use of error\_get\_last() in Drush command files. For a quick test, you could always temporarily comment out the call to set\_error\_handler in Drush.

---
Tags: 7, drush
---


# Question
Title: Does hook_drush_exit() get called for disabled modules?
I have a module that exposes a drush file that contains an implementation of `hook_drush_exit()`. This function gets called at each drush command, even though the module is disabled.

Is this behaviour by design, or is it a bug/misconfiguration?

# Answer
Using Drush 7, I get different results -- which is to say, hook\_drush\_exit() is *usually* not called unless the module it is implemented in is enabled.

Two things to note about this:

1. Earlier versions of Drush may have behaved differently; I did not test older versions, and I do not remember.
2. In some instances, it may be possible for some hook\_drush\_exit() to fire, even if the module it is not enabled. One example where this happens is the `drush help` command.

hook\_drush\_exit() will be called for all commandfiles (module.drush.inc) that are loaded. If Drush bootstraps the Drupal site all the way to the configuration level, then it will only load commandfiles for enabled modules. If Drush is going to bootstrap the Drupal site at least to the "BOOTSTRAP\_DRUPAL\_ROOT" level, but not all the way to the configuration level, then it is not possible for Drush to determine which modules are enabled, and which are disabled. In these somewhat rare cases, Drush will go ahead and load all of the commandfiles it can find anywhere inside the Drupal root, even for modules that are not enabled.

In any event, the workaround you used is the right solution, but now you know why your hook is being called.
> 1 votes

---
Tags: 7, drush
---


# Question
Title: Drush Not recognizing it's in a drupal root
Drush commands seem to succeed but don't.

For example, `drush dl module` results in:

> Install location /doc\_root/feeds\_tamper already exists. Do you want to overwrite it? (y/n): y
> Project feeds\_tamper (7.x-1.0-beta5) downloaded to /doc\_root/feeds\_tamper.
> Project feeds\_tamper contains 2 modules: feeds\_tamper\_ui, feeds\_tamper.

However, it's the wrong download location, and there is no feeds tamper in that location.

Drush status returns:

> PHP configuration: C:\xampp\php\php.ini
> Drush version: 5.9

I am in the document root of the Drupal site.

This is on Windows with Cygwin.

# Answer
If your settings.php file is inside a directory named default, then Drush will find it whenever your current working directory is anywhere inside the document root. However, if settings.php is in some other directory, then you must either cd to the directory that contains settings.php, or identify your site via some other technique -- for example, by specifying --uri=mysite.com, or by using a Drush site alias.
> 1 votes

---
Tags: drush
---


# Question
Title: How to only allow alphabets and spaces in the middle in Profile2 field
I'd like to only allow alphabets in and spaces in the middle of a my Profile2 "real\_Name" field. I have found what I think I need: profile2\_form\_validate\_handler but I don't know how to get it to work.

I think it should be similar to user\_validate\_name, especially for

```
  if (!$name) {
  if (substr($name, 0, 1) == ' ')
  if (substr($name, -1) == ' ')
  if (strpos($name, '  ') !== FALSE)

```

and I should use

```
preg_match('/[^A-Za-z ]/'

```

I only have a rough idea but I don't know how to make it work and I'd appreciate your help.

# Answer
I've found the Field validation module that works! I used this regex expression:

```
^[\x{00c0}-\x{01ff}a-zA-Z0-9]+([- '][\x{00c0}-\x{01ff}a-zA-Z0-9]+)*$

```

This way I can allow international names and only allow spaces, hyphens and apostrophes in the middle of the name.

It was based on combining
1 https://stackoverflow.com/questions/275160/regex-for-names , and
2 https://stackoverflow.com/questions/2525327/regex-for-a-za-z0-9-with-dashes-allowed-in-between-but-not-at-the-start-or-e
> 0 votes

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


# Question
Title: Show English tabs regardless of current site language
A localised Drupal 7 site has four languages. Three non-English languages are for the site content, and English is the admin language. Most users won't be logged in. The only logged-in users will be admin or editors.

For logged-in users, the View/Edit/Translate/Devel tabs (`$tabs` in page.tpl.php) are shown in the current site language. But as these are only intended for admin, it makes more sense to show these in the admin language (English).

How can I always show the tabs in English (or the admin language)?

(One workaround is to remove the translations for the strings in the tabs, but that would have to be repeated if any new tabs or languages are added.)

# Answer
In the end I just used the workaround: removed the translations for the strings in the tabs. There weren't too many.
> 1 votes

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


# Question
Title: How to display an entity property 'type' with form api 'type' for display in a form and then setting with the submitted value?
Is there is process/ function that maps data types that you can use in entities (specifically custom entities using the Entity API) to form #type options? This is to dynamically add a field to a form from the entity and then once I've got the value from the submit handler, use the wrappers to set the property on a entity of the same entity type. Or am I taking the wrong approach here?

I am trying to get an entity property type and am currently using...

```
$property_info = entity_get_all_property_info('MY ENTITY TYPE');

```

Which generates `$property_info['field_postcode']` which has this value...

```
field_postcode      Array [10]
    label               Post Code
    type                text
    description         Field "field_postcode".
    getter callback     entity_metadata_field_property_get
    setter callback     entity_metadata_field_property_set
    access callback     entity_metadata_field_access_callback
    query callback      entity_metadata_field_query
    translatable        false
    field               true
    required            true

```

There I can see that it's got a 'type' of text which seems to translate well to a textfield in the Form API. But what about something like "file" in the Form API?

I wonder if I'm missing a piece of the puzzle here.

# Answer
> 0 votes
In response to Clive's comments under my question I have setup a project on drupal.org and issue to the Entity module issue queue as adding this functionality appears to be the best action. This would be the first contribution I've made so I'm eager for others to take on co-maintenance.

After I've thought a bit on how to go about doing this (still *very* open to suggestions) I'll add code etc. For the time being Clive's suggestion of using Entity module might be right but I've not yet checked it all out.

In the meantime, here is the code I was using (just as a fairly straight-forward form callback) with a form and call\_user\_func\_array() passing through the callback the user would have used. That's just in a basic custom module I called entity\_to\_form because tbh that's all I know how to do at the moment).

code:

```
/**
 * Form callback
 *
 * @param entity type, existing entity type as in entity_load() $entity_type
 * @param callback, as in call_user_func_array() $callback
 * @param array, as in call_user_func_array() $param_arr
 */
function entity_to_form_new_form($form, &$form_state, $entity_type, $callback) {
    // if not a valid entity type, set error and return
    $info = entity_get_info($entity_type);
    if (!is_array($info)) {
        global $user;
        $variables = array(
            '%uid' => $user->uid,
            '%timestamp' => time(),
            '%callback' => $callback,
            '%param_arr' => json_encode($param_arr),
        );
        watchdog('entity_to_form', 'callback not existing: error during function
            entity_to_form_new_form() timestamp = %timestamp, uid = %uid,
            callback = %callback, param_arr = %param_arr', $variables,
            WATCHDOG_ERROR, $link = NULL);
        drupal_set_message('An error occurred and processing did not complete',
            'error');
        return;
    }
    // if not a valid callback, set error and return
    if (!function_exists($callback)) {
        global $user;
        $variables = array(
            '%uid' => $user->uid,
            '%timestamp' => time(),
            '%callback' => $callback,
            '%param_arr' => json_encode($param_arr),
        );
        watchdog('entity_to_form', 'callback not existing: error during function
            entity_to_form_new_form() timestamp = %timestamp, uid = %uid,
            callback = %callback, param_arr = %param_arr', $variables,
            WATCHDOG_ERROR, $link = NULL);
        drupal_set_message('An error occurred and processing did not complete',
            'error');
        return;
    }
    // get information about the entity properties and custom fields
    $property_info = entity_get_all_property_info($entity_type);

    // dynamically set elements for the properties and custom fields

    // fullfil the final requirements for the submit handler
    $form['entity-to-form']['submit-callback'] = array(
        '#type' => 'value',
        '#value' => $callback,
    );
    $form['entity-to-form']['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Submit',
    );
    return $form;
}

/**
 * Form submit handler
 */
function entity_to_form_new_form_submit($form, &$form_state) {
    $callback = $form_state['values']['submit-callback'];
    $variables = '';
    call_user_func_array($callback, $variables);
}

```

---
Tags: forms, entities
---


title: Add comment link to a view

text:
# Question
Title: Add comment link to a view
I created a new content type (News). I then added a new node. After doing these, I created a 'view' of the node. In the view I added the "Add comment link" as a field.

I have the following issues:

1. In the "Add comment link" settings of the View, if I do not select the "Show teaser-style link" option, the link does not appear on the view page.
2. When I select the "Show teaser-style link", the "Add comment link" appears on the page as expected. However, the link redirects to the original node page.

What I would really like to do is show the 'full node form' on the view page without it redirecting to the original node.

# Answer
If you want to render full node change the view settings as follows

In your view change the FORMAT settings as follows
> 1 votes

# Answer
The easiest way would be to change the view's format from "fields" to "content". Then you can activate the comments in the format settings.

Also, you then have the option of displaying the entire node (with or without links to the original node page).
> 0 votes

---
Tags: views
---


# Question
Title: Add custom forms in checkout process in commerce kickstart
In Commerce Kickstart checkout process Checkout,Review order,Payment,Checkout complete are sections. I want to add one more section like Availability. How should I add?

# Answer
> 0 votes
Use hook\_form\_alter to add field(s) or section on any form in drupal.

For more information go through the documentation of this hook.

---
Tags: commerce
---


# Question
Title: How to add fields to 'content' format in Views
I created a view from node. In the FORMAT settings, I choose content (because I need to display the comment form). How do I add fields such as post date or Share this link (ShareThis module) to the view?

# Answer
Here are the steps:

First you need to configure *"share this"* module:

Go to Configuration \>\> Web services \>\> Sharethis (admin/config/services/sharethis)

select the **Node Types** where you want to use this.

Then go to content type manage display settings and in custom display settings check the modes which you have used in view.

That's it.
> 0 votes

---
Tags: 7, views, comments
---


title: drupal_goto not working in hook_init

text:
# Question
Title: drupal_goto not working in hook_init
*First some introduction:*

The hook is working in other pages or direct urls. The only situation where is not working is in the find content page, "admin/content".

When the user clicks on edit link, drupal loads the node edit page, but we need to redirect that edit page to our own edit page. That's why we use the code in the hook.

**THE PROBLEM:**

When the user clicks on edit, he or she is redirected to the same page again (Find content). Intead of going to the my\_module edit page. I Don't know why it's happening this. Any help is welcome :)

*The Code:*

```
function my_module_init() {

    // redirect drupal edit page to our own module edit page.
    if (preg_match('/^node\/(\d+)\/edit$/', current_path(), $matches)) {
      $code = _my_module_check_code($matches[1]); //check if the nid is of the content type we need
      if ($code) {
        return drupal_goto('my_module/' . $code . '/edit');
      }
      // If the code is not from the content type we need, we do nothing
      // just leave drupal work it's way
    }

}

```

# Answer
The solution is to use the hook\_preprocess\_page().

```
function my_module_preprocess_page() {

    // redirect drupal edit page to our own module edit page.
    if (preg_match('/^node\/(\d+)\/edit$/', current_path(), $matches)) {
      $code = _my_module_check_code($matches[1]); //check if the nid is of the content type we need
      if ($code) {
        global $base_url;
        $url = $base_url.'/my_module/'.$code.'/edit';
        header('Location: ' . $url);
      }
      // If the code is not from the content type we need, we do nothing
      // just leave drupal work it's way
    }

}

```

After clearing cache, all is working fine.
> 4 votes

---
Tags: 7, hooks
---


# Question
Title: How to add dev modules to a distribution without getting security updates warnings?
I have made a distribution, which contains some modules which are in dev state. These modules are being by drush make checked out by git. So my drupal-org.make file contains something like:

```
projects[ctools][type] = module
projects[ctools][download][type] = git
projects[ctools][download][url] = http://git.drupal.org/project/ctools.git
projects[ctools][download][revision] = e720f61
projects[ctools][subdir] = "contrib"

```

(I need ctools' current dev version because of a batch that was commited shortly after 7.x-1.4 came out.)

This works ok but when using my distro I always get "security updates available"-warnings, which I would not get if I downloaded and used this same dev version on a standalone project.

What is the best way to handle this? Can I somehow tell drush make to download a specific dev version, as these dev versions are packaged by d.o. and are idenifiable: e.g. version = "7.x-1.4+4-dev"

# Answer
Article Common Drush Make errors and their solutions has a solution for you. It seems that you should provide **both branch and revision**, if you want to clone exact revision and still have other info filled properly.

> ```
> projects[ctools][type] = module
> projects[ctools][download][type] = git
> projects[ctools][download][revision] = 747151e
> projects[ctools][download][branch] = 7.x-1.x
>
> ```
>
> Although you're specifying both a revision and a branch, drush make is smart enough to use the more specific thing (the revision) when cloning. It just uses the **branch information for other metadata** (updating the .info files in the things it checked out, and for displaying the contents of the distribution on the release node).

Emphasis mine.
> 3 votes

---
Tags: installation-profiles
---


# Question
Title: After upgrade from Drupal 6 to Drupal 7 search does not work
Same server, upgrade went well and site is stable however it won't index content even after clicking on re-index. Crons are running just fine on server, checked on the MySQL database and all the tables related to search (search\_dataset, search\_index, search\_total etc) are all empty. I have tried turning all modules off, emptying cache, turning search on off, nothing works.

I would really appreciate if anyone knew a way around this.

Kind Regards

Javier

# Answer
> 0 votes
Reindex the search data in config-\>search-\>setting and run cron again and again upto the index percentage reaches 100%.

This will solve your issue.

You can also do it via drush to get around limit on the number of items that get indexed per cron run.

```
$ drush help search-index

```

Index the remaining search items without wiping the index. and/or

```
$ drush help search-reindex

```

Force the search index to be rebuilt.

Options: --immediate Rebuild the index immediately, instead of waiting for cron.

---
Tags: search
---


# Question
Title: link field template syntax / display link field as an image / devel dpm (D7)
My link field is currently displaying as a URL as you can see here (yellow border). I have added dpm($items) to my link field template file. How do I read the dpm output or more specifically how do I edit my template file to say "display this field as the specified image"?

The following example works in a different situation where the field is an uploaded file but in this case the field is a link.

```
<?php $path = $items[0]['#file']->uri; ?>
<a href="<?php print file_create_url($path); ?>"><img src="../images/download.png"></a>

```

# Answer
> 0 votes
I dont really understand what the problem is, If you are already outputting the link URL, and you want to display that as an image, surely you can just wrap it in an img tag?

```
<?php $path = $items[0]['#file']->uri; ?>

<img src="<?php print file_create_url($path); ?>" />

```

OR, with an mp3 file like in your example...

```
<?php $path = $items[0]['#file']->uri; ?>
<audio controls>
  <source src="<?php print file_create_url($path); ?>" type="audio/mpeg">
</audio>

```

---
Tags: theming, debugging
---


# Question
Title: How to add site Validation for all pages
I want to implement google site validate meta tag on each page page of my site. I tried Site\_validation module but its allows to implement the google meta tags only on front page. Could anyone help me?

# Answer
> 0 votes
One way to do that is using the "site\_verify" module and you can add another hook to add it to all page that will look like this:`/**
 * Implements hook_init().
 *
 */
function YOUR_MODULE_init() {
 $meta_tags = db_query("SELECT svid, meta FROM {site_verify} WHERE meta <> ''")->fetchAllKeyed();
 foreach ($meta_tags as $svid => $meta_tag) {
 $data = array(
 '#type' => 'markup',
 '#markup' => $meta_tag . "\n",
 );
 drupal_add_html_head($data, 'site_verify:' . $svid);
 }
}`

you need to change "YOUR\_MODULE" with your custom module name. Also clear drupal cach after adding it

---
Tags: google-search-console
---


title: What do I set GUID to in Feeds Import?

text:
# Question
Title: What do I set GUID to in Feeds Import?
I was told I should use GUID and tick Unique setting for best method of filtering out duplicate content each time cron runs. But what do I set GUID to? My XML sources has like only , etc.

Now I am using Title as unique for duplicates. But I get lots of random issues, Feeds Import doesn't import all feeds after each cron, or even better, it gets stuck e.g. 'Importing 48%' and etc.

I got 4 feed imports that parse XML from external site, all from same site (also Drupal). Also I use custom module to trigger them when running cron, because by default Feed Import doesn't even react to hourly cron.

So trying various solutions, maybe this GUID thing will solve this.

I also use XPath XML parser.

# Answer
You can use a the node or article URL as it's Unique and a lot of feeds use it with no issues at all
> 1 votes

---
Tags: 7, feeds
---


# Question
Title: Shared Database With Domain Access and Multiple Accounts With Same Email
We are planning to have the following Drupal architecture:

* One install of Drupal.
* Multiple domains sharing the same database using the Domain Access module.

Each domain will have user login capabilities, and user accounts will not be shared across domains. This means we will have times when one email address could be associated with multiple accounts (one for each domain where the email address is associated with an account).

Is such an architecture possible using a shared database, or will we have problems trying to associate many accounts to the same email address?

# Answer
You should not use Domain Access unless you are planning on sharing users and content between the different domains. In your instance, you do not want to share users -- and yes, you would have problems if you tried to have duplicate user entries sharing the same email address. You are therefore better off creating multiple independent Drupal sites, and replicating shared content (if any) via other means.
> 1 votes

---
Tags: users, domain-access
---


# Question
Title: Custom module Pager does not work with Ajax filter
My custom module uses an Ajax enabled drop down to allow users to filter images. There is also a pager attached to the query. The pager works fine when all the data is displayed i.e. no filter applied but after applying a filter, clicking a pager button just gives a white screen.

Here is my code.

```
function view_colouring_sheets($form, $form_state){
$query = db_select('field_data_field_image','fi')->extend('PagerDefault');
$query->join('node','n','n.nid = fi.entity_id');
$query->fields('fi');
$query->fields('n',array('title'));
$query->limit(20);
if($form_state['input']['tid']){
    $query->condition('entity_id',  colouring_sheets_filtered_tid($form_state['input']['tid']),'in');
}
$images = $query->execute()->fetchAll();

$output = array(
    '#theme'=>'image_matrix',
    '#type'=>'markup',
    '#images'=>$images,
    '#title'=>'Colouring Sheets',
    '#pager'=>theme('pager'),
    '#filter_form'=>  drupal_render(drupal_get_form('image_filter_form')),
);

return $output;
}

function colouring_sheets_filtered_tid($tid){
    $query = db_select('field_data_field_image_category','ic');
    $query->condition('field_image_category_tid',$tid);
    $query->fields('ic');
    $result = $query->execute()->fetchAll();
    $term_array = array();
    foreach($result as $row){
        $term_array[] = $row->entity_id;
    }
    return $term_array;
}

function image_filter_form($form, $form_state){
    $terms = taxonomy_get_tree(18);
    $terms_array = array();
    foreach($terms as $term){
        $terms_array[$term->tid] = $term->name;
    }
    $form['tid'] = array(
        '#type'=>'select',
        '#options'=>$terms_array,
        '#required'=>TRUE,
        '#title'=>'Fitler Images',
        '#ajax'=>array(
            'method'=>'replace',
            'wrapper'=>'image_matrix',
            'callback'=>'view_colouring_sheets',
            'progress' => array('type' => 'throbber', 'message' => 'Images Loading'),
            'effect'=>'fade',
        ),
    );
    return $form;
}

```

# Answer
> 0 votes
I have discovered a sort of workaround. It requires storing the result of `current_path()` in a JS setting variable, and rewriting the path in JS when the pager is regenerated.

Sample code:

```
php
// building an ajax form...
global $base_path;
$settings = array(
    'my_module' => array(
    'my_path' => $base_path . current_path(),
  ),
);
drupal_add_js($settings, 'setting');

```

That will make the current page's path available in your JavaScript file to manipulate. There are still kinks though, especially with AJAX filtering and AJAX paging all at once. I will update this once I resolve all those kinks.

---
Tags: 7, ajax, paging
---


title: file unmanaged save upload

text:
# Question
Title: file unmanaged save upload
I'm moving some existing functionality into a new Drupal site.

1. Files are uploaded via posted form
2. Their file names are prefixes with UID
3. They are then moved to temp holding directory
4. A cron job on another server SCPs the files in batches
5. The files are verified copied, then deleted via batch ssh command

**I'm looking for a clean way to handle (save) an uploaded file coming from a submitted form with an element of type 'file' without "managing" it.** I've browsed over `file_save_upload()` and like the validation/error handling it offers.

However, I'd rather not have the files exist in the managed file tables. I would need to modify my pulling server's cron job to trigger a managed deletes via web request.

Just as there is a `file_save_data()` and analogous `file_unmanaged_save_data()` I'm looking for `file_unmanaged_save_upload()`. I basically want the first half of `file_save_upload()` before it touch the database. It seems like something similar or a workaround should already exist but I haven't found one. I trying to avoid reinventing the wheel.

# Answer
> 1 votes
**I suggest using `file_save_upload()` anyway**, beacause (as the API docs say):

> The file will be added to the {file\_managed} table as a temporary file. Temporary files are periodically cleaned. To make the file a permanent file, assign the status and use file\_save() to save the changes.

So you don't need to worry about having the file "managed" by Drupal as long as you don't change the status of the file to `FILE_STATUS_PERMANENT`.

**Otherwise, if you really don't want this default behaviour** (and also no hooks to get invoked), just copy the file in your `form_submit()` using `file_unmanaged_copy()` (give it uploaded tmp file as source).

# Answer
> 1 votes
You may create your own file\_unmanaged\_save\_upload() which won't insert item into Drupal DB file\_managed table.

I did. I copied file\_save\_upload() as file\_unmanaged\_save\_upload() in /Drupal\_root/includes/file.inc, and deleted "file\_save()" in it, modify the last lines as below:

```
function file_unmanaged_save_upload(){
.....
if ($file = file_save($file)) {
    // Add file to the cache.
    $upload_cache[$source] = $file;
    return $file;
  }
  return FALSE;
}

```

It works as expected.

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


# Question
Title: How do you allow a role to assign other users roles - but only specific roles?
I'm creating a "level'ing" role system on my page. At a certain role (Full Member) the user must be able to assign someone with the role level 5 the new role level 6 manually once a dialogue is complete.

How can you do this?

# Answer
> 1 votes
I think Role Delegation is what you're looking for.

> For each role, **Role Delegation** provides a new assign ROLE role permission to allow the assignment of that role.

---
Tags: users
---


# Question
Title: How can I create hyperlinks and mailto links in a node?
I need to create external hyperlinks to external pages and also mailto links. But when doing so, Drupal prints the code, ie `<a href...`.

I downloaded a link module which was okay except you could not remove the http from the page display, and also it would not code a mailto link.

How can this be done in Drupal 7, do I have to install some sort of editor? If so, which one?

# Answer
If I understand you correctly, you probably want to look at Text Filtering options.

If your content creators are all trusted, you can allow them to input unfiltered content directly in to the node. The text filter I like to use for this is "PHP Code"... it literally lets you put in whatever you want.

If they're less trustworthy, consider using an editor like TinyMCE. It will let you set which tags are allowed and gives you a nifty interface to edit the node with.
> -1 votes

---
Tags: 7, theming
---


# Question
Title: Redirecting Views dynamically generated URL's via .htaccess RewriteRule - CSS stylehseets arent loading after change
I have many dynamically generated pages via views and it seems the easiest way to redirect them is using the .htaccess file via a **RewriteRule**. I put in the following right above the index.php rewriterule and none of the css files are loading anymore. obviously i have something wrong here, but what?

Doesn't the first rewrite fire only if it detects the **buy** string in the first part of the url? I dont see how that would interfere with anything.

```
RewriteRule ^buy(/?.*) http://www.EXAMPLE.com/buy$1 [R=301,L]

RewriteRule ^ index.php [L]

```

# Answer
actually i put the RewriteRule above the RewriteCond and it seems to be working good now. so it seems that RewriteCond corresponds to the RewriteRule that's right below it only like an inline if statement
> 0 votes

---
Tags: views, redirection, .htaccess
---


# Question
Title: How to find out which form I want to alter
I am adding a functionality to drupal commerce kickstart, which involves product display modification. There should be a lot of forms but I don't which one to alter and add my new object to the existed form. Any good idea? (There is almost no documentation about it)

# Answer
> 1 votes
The way I usually do it is just implement `hook_form_alter` and inside put `dpm($form_id);`. Reload the page and it will echo all form ID's. You should find the one you want pretty easily, you can then change the `hook_form_alter` into a `hook_form_FORM_ID_alter`.

# Answer
> -1 votes
You can find form\_id by looking in the HTML of your site with firebug. Forms have their own id. For example the form to add a article-node has this:

```
<form id="article-node-form" class="node-form node-article-form" accept-charset="UTF-8" method="post" action="/node/add/article" enctype="multipart/form-data">

```

So the form name is article-node-form. So check the html for the forms you want to alter for a element.

---
Tags: commerce, forms
---


# Question
Title: Making rules refresh page when message after one has time to read the message?
Issue: I added a message that should be displayed upon user login using rules. It worked fine only that 1. The page stuck (showing the message) and you had to refresh and click okay to discarding information upon reload. 2. The page did refresh but did so immediately so that one did not have more than a split-second to view the message.

Question: How do you make rules display the system for, say, 5 seconds and then refresh the page? A mixture between the two possible scenarios described above.

# Answer
> 0 votes
You might want to consider

Absolute Messages

> Displays system messages in fully themeable colored horizontal bars on top of the page. ...
> * messages could be dismissed automatically after a specific time - configurable in module settings for each message type separately,

---
Tags: rules, javascript
---


# Question
Title: My sitemap.xml have a different domain and this is an error
I have created a site with a development domain name. Now this site is online (camperlife.it), but sitemap.xml created by XML sitemap module still contains the development domain name.

I have rebuilt sitemap many times, but without success.

Where is my problem ?

# Answer
> 1 votes
I think you have a setting wrong.

Browse to the XML Sitemap settings page (admin/config/search/xmlsitemap/settings).

Expand the **Advanced Settings** section.

Check/set the **Default Base URL**. Typically, I set this to make sure the default base URL gets used, as rebuilding from drush won't set it properly if you don't `$uri` set in your site alias.

---
Tags: 7, xml-sitemap
---


# Question
Title: Displaying article image on full display conditionally
I would like to enable/disable visibility of article image on full display for **some** articles while keeping article image always visible on teaser display. Is there a way to achieve that apart from dealing with views?

Thanks.

# Answer
You have to use Field formatter conditions module to achieve this goal.

First thing attach a field on desired content type with boolean value and then use this field value as a condition in field formatter settings to display other fields as you want.

For more information go through the module documentation.
> 0 votes

---
Tags: nodes
---


# Question
Title: hybridauth module - redirect problems after connect
I am using Drupal 7 And the hybridauth module.

In the past - everything worked great, and new & existing users could connect with Facebook and with Twitter.

Now, I have a problem that no one is able to connect with facebook or twitter.

The "closing..." window is stuck for a long time (looks like refreshing itself all the time - like a loop). When I close this "closing.." window, it looks like the user has succeed to login, but I get a message in a repeat many times that says "You have already registered this identity". When this issue is happen - I usually see that the user is finally login - after this long process and many messages (not a clean connect). It's looks like the problem is mainly on the connection to facebook.

Does someone knows what is the problem, and how can I fix it?

dblog errors:

TYPE hybridauth
DATE Friday, March 28, 2014 - 18:16
USER user name
LOCATION http://www.example.com/hybridauth/window/Twitter?destination\_error=home
REFERRER http://www.example.com/hybridauth/window/Twitter?destination\_error=home
MESSAGE Exception: User profile request failed! Twitter returned an error. in Hybrid\_Providers\_Twitter-\>getUserProfile() (line 77 of /home5/mysite/public\_html/sites/all/libraries/hybridauth/hybridauth/Hybrid/Providers/Twitter.php).
SEVERITY error

Here is another db log, that looks fine here, but caused a stuck "closing.." window that refresh itself all the time:

TYPE user
DATE Friday, March 28, 2014 - 19:00
USER user name
LOCATION http://www.example.com/hybridauth/window/Facebook?destination\_error=home&destination=home
REFERRER http://www.example.com/ MESSAGE Session opened for hybridauth\_Facebook\_6003111111.
SEVERITY notice

# Answer
> 4 votes
We had the same exact issue using the above configuration.

It turned out that I had a rule enabled to redirect the user to a page upon login.

When I disabled the above rule everything went back to normal

Probably a conflict between modules.

Thanks, Leonidas

# Answer
> 0 votes
I solved it by letting hybridauth open the authentication in a popup window. When the user inserts his credentials the popup windows gets closed and then the original page gets a refresh.

To set the popup window for Linkedin: admin/config/people/hybridauth/provider/LinkedIn?destination=admin/config/people/hybridauth there you'll find "Authentication window type" and select "New popup window" instead of "current window"

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


# Question
Title: Load current node from block and from display suite field
Sorry if this question is too obvious, I need to load the current node from display suite and then execute this php code:

```
<?php

$project = node_load(5);

foreach ($project->field_gallery['und'] as $val ) {
  echo '<img src="' . $val['filename']  . '">';
}

?>

```

In display suite I tried:

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

and

$project = $entity->nid;

```

I also tried the same within a block, and it failed. It only works when I set a static id as node\_load(5).

Please, can I get the answer how to load the node from display suite custom field and from a simple block?

Edit: I'm adding a custom field to display suite from this url:
/admin/structure/ds/fields/manage\_custom
Structure \> Display Suite \> Fields \> Add a code field.

# Answer
> 2 votes
You can load the node id from node page using arg function...

> Returns a component of the current Drupal path.
>
> When viewing a page at the path "admin/structure/types", for example, arg(0) returns "admin", arg(1) returns "structure", and arg(2) returns "types".

node pages always has path 'node/nid' so arg(1) gives node id...

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

```

---
Tags: entities, nodes
---


# Question
Title: Fatal error: Call to a member function fetchAssoc() on a non-object
Fatal error: Call to a member function fetchAssoc() on a non-object in C:\wamp\www\drupal\modules\php\php.module(80) : eval()'d code on line 34

May I know why this error occurs? Using druapl 7

# Answer
> 0 votes
You are trying to use(access) a variable as an object, that variable is not an object. That variable may be an array.

---
Tags: 7
---


# Question
Title: Rewriting Views results with tokens on multi field
I need to write a paragraph laced with field values from a result from a view. For example, "Our camera case works with model ABC, 123, and XYZ", where ABC, 123, and XYZ are 3 out of multiple results values for that field.

Can I use tokens to achieve this?

# Answer
> 1 votes
yes using field\_fieldnamename:delta

"Our camera case works with model \[field\_fieldnamename:0\], \[field\_fieldnamename:1\], and \[field\_fieldnamename:2\]"

---
Tags: 7, views, tokens
---


# Question
Title: Single page Drupal apps with custom theme
I have a static HTML page which contains navigation that links to different sections on the same page. Just like this one http://www.cedricvella.com/#node-3 .

What I would like to know is how can this functionality be built with Drupal when creating a custom theme. I don't want to use Panels.

Is there a way you can pull each page node into one single page?

# Answer
> 0 votes
you could do it using the single page module. Each menu item can be a single page which can be mapped to a node.

# Answer
> 0 votes
One way I can think of is to create a custom tpl for that page. define custom ID's on the div's for blocks that contain the information that you need to scroll to, and use a little jQuery to make the scroll smooth or add any other effects you want.

# Answer
> 0 votes
Closing this question. It seems the simplest answer is to use panels with custom panel layouts. However I like the idea of decoupling Drupal's back end from my front end app and feed the data using Web services. It's a good solution for single page applications.

---
Tags: services
---


title: Get fields values in the view

text:
# Question
Title: Get fields values in the view
I am new on Drupal and I need to update an existing **Drupal 7** website.

The website is multi-domains, multi-languages.

Getting the **views fields values** makes me a big headache!

---

The existing code of the website is like this:

In the folder **templates**:

Each template of the website has a file like: `views-view-unformatted--some-name.tpl.php`

And the to print the fields values, the code is similar to this:

```
<?php
$idInFieldCollection = $view->result[0]->field_field_a_name[0]['raw']['value'];
$item = $view->result[0]->field_field_a_name[0];
$value = $item['rendered']['entity']['field_collection_item'][$idInFieldCollection]['field_the_field_needed']['#items'][0]['value'];
?>
<span><?php print($value); ?></span>

```

This process seems huge!

And finding the path for each field value requires to use `kpr()` and explore the view object.

I don't understand so much yet all I read about Drupal, could you guys let me know if there is an easier way. With getters for example ?

# Answer
You should use Entity module. in this module no matter what the language of the website is you can use `entity_metadata_wrapper` command to get the fields value. here is an example of my project where `field_article_writer` and `title` are fields of article content type:

```
function MYTHEME_preprocess_node(&$variables){
switch ($variables['node']->type){
    case 'article':
        $suggest = "page__node__article";
        $variables['theme_hook_suggestions'][] = $suggest;
        $wrapper = entity_metadata_wrapper('node',$variables['node']);
        $variables['title']= $wrapper->title->value();
        $variables['writer']= $wrapper->field_article_writer->value();
        break;
    }
}

```

Now in `page--node--article.tpl.php`, `$title` and `$writer` hold their correspondent value.
> 1 votes

---
Tags: views, entities
---


title: Drupal widget not saving field values

text:
# Question
Title: Drupal widget not saving field values
I'm new to Drupal but have been given the task of creating a widget.

The module loads, fields are displayed, but when I create some content the form values are not being stored when the content is being saved.

.install file:

```
function cloudinary_field_schema($field) {

  $columns = array(
    'publicID' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
    'url' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
    'caption' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
    'alt' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
    'credit' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE)
  );

  return array(
    'columns' => $columns,
    'indexes' => array(),
  );

}

```

.module file:

```
/**
 * Implements hook_field_info().
 * define the field type
 */
function cloudinary_field_info() {
    return array(
        'cloudinary' => array(
            'label' => t('Cloudinary image selector'),
            'description' => t('Search for images and select one for display.'),
            'default_widget' => 'cloudinary_widget',
            'default_formatter' => 'cloudinary_formatter',
            'settings' => array(),
            'instance_settings' => array(),
        )
    );
}
/**
* This is the dropdown options for widget
*/
function cloudinary_field_widget_info() {
    return array(
        'cloudinary_widget' => array(
            'label' => t('Default'),
            'field types' => array('cloudinary', 'text'),
            'behaviours' => array('multiple values' => 'FIELD_BEHAVIOUR_DEFAULT'),
        )
    );
}

/**
*/
function cloudinary_field_widget_form(&$form, &$form_state, $field, $instance, $lang, $items, $delta, $element) {

    $element += array(
      '#type' => 'fieldset',
    );

    $item =& $items[$delta];

    $element['field_cloudinary_publicID'] = array(
        '#title' => t('Public ID'),
        '#type' => 'textfield',
        '#required' => TRUE,
        '#default_value' => isset($item['field_cloudinary_publicID']) ? $item['field_cloudinary_publicID'] : '',
    );

    $element['field_cloudinary_url'] = array(
        '#title' => t('Url'),
        '#type' => 'textfield',
        '#required' => TRUE,
        '#default_value' => isset($item['field_cloudinary_url']) ? $item['field_cloudinary_url'] : '',
    );

    $element['field_cloudinary_caption'] = array(
        '#title' => t('Caption'),
        '#type' => 'textfield',
        '#required' => TRUE,
        '#default_value' => isset($item['field_cloudinary_caption']) ? $item['field_cloudinary_caption'] : '',
    );

    $element['field_cloudinary_alt'] = array(
        '#title' => t('Alt'),
        '#type' => 'textfield',
        '#required' => TRUE,
        '#default_value' => isset($item['field_cloudinary_alt']) ? $item['field_cloudinary_alt'] : '',
    );

    $element['field_cloudinary_credit'] = array(
        '#title' => t('Credit'),
        '#type' => 'textfield',
        '#required' => TRUE,
        '#default_value' => isset($item['field_cloudinary_credit']) ? $item['field_cloudinary_credit'] : '',
    );

    return $element;
}

function cloudinary_field_is_empty($item, $field) {
    $flag = FALSE;
    foreach ($item as $key => $value) {
        if(empty($key[$value])) {
            $flag = TRUE;
        }
    }
    return !$flag;
}

function cloudinary_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
    foreach ($items as $delta => $item) {
        if (!isset($item['field_cloudinary_publicID']) ||
            !isset($item['field_cloudinary_url']) ||
            !isset($item['field_cloudinary_caption']) ||
            !isset($item['field_cloudinary_alt']) ||
            !isset($item['field_cloudinary_credit'])) {

            $errors[$field['field_name']][$langcode][$delta][] = array(
                'error' => 'cloudinary_fields_missing',
                'message' => t('%title: Make sure all fields are completed. '.
                    'Make sure all fiends are entered.',
                    array('%title' => $instance['label'])
                ),
            );
        }
    }
}

function cloudinary_field_widget_error($element, $error, $form, &$form_state) {
    switch ($error['error']) {
        case 'cloudinary_fields_missing':
            form_error($element, $error['message']);
            break;
    }
}

function cloudinary_field_formatter_info() {
    return array(
        'cloudinary_formatter' => array(
            'label' => t('Default'),
            'field types' => array('cloudinary'),
        ),
    );
}

function cloudinary_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
    $element = array();
    foreach ($items as $delta => $item) {
        $element[$delta] = cloudinary_format_field($item);
    }
    return $element;
}

function poutine_maker_format_field($item) {
    $element = array(
        '#type' => 'container',
        '#attributes' => array( 'class' => array( 'field-item') ),
    );

    $element['field_cloudinary_publicID'] = array(
        'label' => array(
            '#type' => 'container',
            '#attributes' => array( 'class' => array( 'field-label' )),
            'text' => array(
              '#markup' => t('Public ID'),
            ),
        ),
        'item' => array(
            '#type' => 'container',
            '#attributes' => array( 'class' => array( 'field-item') ),
            'text' => array(
              '#markup' => $item['field_cloudinary_publicID'],
            ),
        ),
    );

    $element['field_cloudinary_url'] = array(
        'label' => array(
            '#type' => 'container',
            '#attributes' => array( 'class' => array( 'field-label' )),
            'text' => array(
              '#markup' => t('Image Url'),
            ),
        ),
        'item' => array(
            '#type' => 'container',
            '#attributes' => array( 'class' => array( 'field-item') ),
            'text' => array(
              '#markup' => $item['field_cloudinary_url'],
            ),
        ),
    );

    $element['field_cloudinary_caption'] = array(
        'label' => array(
            '#type' => 'container',
            '#attributes' => array( 'class' => array( 'field-label' )),
            'text' => array(
              '#markup' => t('Image Caption'),
            ),
        ),
        'item' => array(
            '#type' => 'container',
            '#attributes' => array( 'class' => array( 'field-item') ),
            'text' => array(
              '#markup' => $item['field_cloudinary_caption'],
            ),
        ),
    );

    $element['field_cloudinary_alt'] = array(
        'label' => array(
            '#type' => 'container',
            '#attributes' => array( 'class' => array( 'field-label' )),
            'text' => array(
              '#markup' => t('Image Alt'),
            ),
        ),
        'item' => array(
            '#type' => 'container',
            '#attributes' => array( 'class' => array( 'field-item') ),
            'text' => array(
              '#markup' => $item['field_cloudinary_alt'],
            ),
        ),
    );

    $element['field_cloudinary_credit'] = array(
        'label' => array(
            '#type' => 'container',
            '#attributes' => array( 'class' => array( 'field-label' )),
            'text' => array(
              '#markup' => t('Image Credit'),
            ),
        ),
        'item' => array(
            '#type' => 'container',
            '#attributes' => array( 'class' => array( 'field-item') ),
            'text' => array(
              '#markup' => $item['field_cloudinary_credit'],
            ),
        ),
    );

    return $element;
}

function cloudinary_format_canvas_field($item) {
    drupal_add_js(drupal_get_path('module', 'cloudinary') . '/cloudinary.js');
}

```

# Answer
> 2 votes
You have some logic problems in `cloudinary_field_is_empty()`.

```
foreach ($item as $key => $value) {
    if(empty($key[$value])) {
        $flag = TRUE;
    }
}

```

Will result in `$flag` **always** being false (because `$key` is not an array, and certainly not one keyed by the values of the original array). Since you return `!$flag`, you're always returning `TRUE`...so Drupal (correctly) discards the incoming data.

---
Tags: 7, entities
---


title: Migration of Drupal 6 to Drupal 7

text:
# Question
Title: Migration of Drupal 6 to Drupal 7
I have a Drupal 6 site with different content types, and node references. I also have a custom theme. I want to migrate to Drupal 7. I use the Node export, and Node import modules, but they are not working perfectly, as I am not able to import node references.

Is there any easy way to do this?

# Answer
> 1 votes
1. Read the UPGRADE.txt
2. Have a look at the CCK Module for D7. It comes with a migration submodule.
3. The them has to be adapted to D7 manually. Have a look at this for reference.

# Answer
> 0 votes
Please follow the below points to migrate drupal 6 to drupal 7,

* Take up a backup of your Drupal website and the database set on it.
* Put your production website into Maintenance mode to make sure no new data is being recorded on it.
* Configure the backup of Drupal to a test environment, such as a subfolder or subdomain.
* Perform the upgrade to D7 on the test website.
* Test if all features on your upgraded, test website are working properly.
* If you are happy with the result, switch places of your test and production website, so the upgraded version will become the main one on your server.

From the points, if you need any queries let me know.

---
Tags: 7, nodes, migrations
---