# Question
Title: Only allow 1 submission from an email address in webform
I am taking some users information using webform, which is their name and email address.

I need to only allow one submission per email address, restricting the form by IP or cookie in the webform settings is not sufficient in this case.

Is this possible?

# Answer
> 0 votes
Edit the email field in the webform and check both the "mandatory" and "unique" options.

In this case, it would accept entries only for unique mail id's

---
Tags: webforms
---


# Question
Title: Adding own variables on user registration to created user
I want to add additional informations to a user on registration. I have added the fields accountID and clanID to the user . On registration i load these information according to his entered name from another webpage and i want to have these fields added to the user.

My question is, how can i add these additional values to the fields programmatically?

# Answer
> 0 votes
How about using the Profile 2 module for this? Exceerpt from its project page:

> Designed to be the successor of the core profile module, which is deprecated for Drupal 7. In contrast to the deprecated module this module provides a new, fieldable 'profile' entity ... leverage the power of fields!

Refer to this video for an introduction to Profile 2 also.

Maybe you also want to consider something like the answer to How to display a profile form using profile2 module ?

# Answer
> 0 votes
I guess you could use the Prepopulate module for this.

> The Prepopulate module allows fields in most forms to be pre-populated from the $\_REQUEST variable.
>
> For example, the following URL,
>
> http://www.example.com/node/add/blog?edit\[title\]=this is the title
>
> will automatically fill the Title field on a new blog post with the words "this is the title". Any field can be prepopulated this way, including taxonomy and CCK fields. You can prepopulate more than one field at a time as well. Prepopulate is excellent for creating bookmarklets. For examples on usage for all of these cases, please read the USAGE.txt file that comes with the module or you can read the online handbook page.

That should be able to get the information in the field assuming you can add those into the link that is clicked to get to the registration page.

# Answer
> 0 votes
Thank you for the hints. I have solved it with the user\_presave\_hook:

```
function mymodule_user_presave(&$edit, $account, $category) {
$url = variable_get('url');
$account_id = $edit['field_accountid']['und'][0]['value'];

try {
    $api_response = json_decode(file_get_contents($url), true);

    $edit['field_accountid']['und'][0]['value'] = $account_id;
    $edit['field_global_rating']['und'][0]['value'] = $api_response['data'][$account_id]['global_rating'];
} catch (Exception $e) {
    watchdog('mymodule', 'Could not load account_id from url', NULL, WATCHDOG_WARNING, $link = NULL);
}

```

}

But i don't know if this is a good solution.

---
Tags: users
---


# Question
Title: Custom menu link does not show up under "List links" but is in the database
I have three menus with six links each using the i18n module.

All of these links are to panel pages. On one menu, however, there is an additional link to another custom panel that does not appear in the Menu UI (under *List Links*) but is present in the database (I found it in the menu\_links table).

When I go to the panel of the ghost link, the option for showing a menu link is disabled.

How can I put this link back in the UI? Or should I simply delete it from the database and re-create it in the UI?

**EDIT**: I tried adding the link in the menu manually, but then it shows up twice.

# Answer
Simply go to the menu and add that link in the menu and it would start showing up.
> 1 votes

---
Tags: routes
---


# Question
Title: Change Search API Facet title for boolean values
I have my shop set up in Drupal Commerce. I have added search API and configured facets for things like taxonomy terms, which are perfect.

However on my product display nodes, there are a set of values that are boolean on/off checkbox fields for different attributes. These are...

* Vegan friendly
* Vegetarian
* Contains sugar
* Won a taste award
* Contains gluten
* Contains Alcohol

But they are showing their 1 or 0 key values for the boolean. Is there anyway to name these facet values?

I want to hide the 0, hide the block titles, rename the "1" to the block title, and then group them all together with CSS. The only thing im stuck on is renaming the 1 value.

I appreciate any help!

# Answer
> 1 votes
I downloaded Facet API Bonus module, and used the exclusion option to hide fields that were "false" or "0".

I then went into the content type and changed the "1" value to what I wanted it to say.

Along with a little CSS around the field to neaten it up, I now have exactly what I was after.

---
Tags: commerce, search
---


title: Flip Boolean Value in Field

text:
# Question
Title: Flip Boolean Value in Field
I have a product with a field that's a boolean value "Contains Gluten" which stores a "1" for yes and a "0" for no, this is stored in the database as field\_contains\_gluten\_value.

The client now wants it to say "Gluten Free" instead.

Rather than change all of my views and product displays to negate, I figure it would be easier to just flip the value in the database.

I am using feeds to import the products from a csv, but the client has edited products now and changed other fields, so I don't want to change it in excel and import over the top for fear of losing his changes.

In the database how do I change all the "0" values to "1" and vice versa? I'm aware this might not qualify as a Drupal question and might be better on stack overflow, but if there is a Drupal solution you are aware of then I'm all ears!

# Answer
The SQL would be something like:

```
UPDATE [field table] SET [field column name]=1 WHERE [field column name]=0

```
> 1 votes

# Answer
Always the way. Post a question and find an answer immediately.

I simply exported the table field\_contains\_gluten\_value from phpmyadmin, opened it up in notepad++ and used find and replace to swap the "1" and "0" values to the correct way.

I then dropped the table in the database, and uploaded the newly edited one in its place.

I'm there was an easier way to do that in SQL, but in this case it took me less than 5 minutes to do over 1000 products. Seems simple enough to me!
> 0 votes

---
Tags: 7, entities
---


# Question
Title: Is it possible to attach a single field collection to multiple nodes? (And so make updating easier)
Firstly is it possible to attach a single field collection to multiple nodes (so when you opened each node, you'd see the same field collection. If you altered one, they'd all change.)

And secondly, if the answer to the first question is yes, how would you go about doing this? Has anyone ever tried this before?

I've been looking through the database tables and it seems like there's no reason you couldn't just point multiple nodes to one fc, however I can't find anything on the topic.

**Brief Example**

A quick use case to clarify Geoff's question:

When I create node b, I have the option to populate a field collection from node a rather than a blank field collection.

Editing the field collection on node a, would then also change the value in b.

# Answer
> 0 votes
You have to write custom module for this and use hook\_node\_presave($node) to save fieldcollection value of other node into this and save node.

Then check your DB, now single fc attached to other node(s).

# Answer
> 0 votes
I would start it this way:

* install Entity Reference to create a reference in B to A
* create a reference field in B to let the user choose which node they want to reference, and then use some AJAX to do the initial populate of the field elements based on their selection

This will save B as normal but provide the connection between the two

* create a hook\_form\_alter for node B, such that if a reference exists, load the referencing node and populate the fields in node B with the values from node A

This would allow any node to reference any other node (of the same content type) for value mirroring. This approach is passive, in that it requires node B to be viewed before the values are updated - this behaviour could be changed on the node A save to update the field values in all referencing nodes

If you wanted it to go the other way or be more communal, whereby any node could be manually changed and affect all the other nodes (changing node B also changes node A), it would be a little different, but this is the general idea I would use based on your question.

---
Tags: entities
---


# Question
Title: db_query or db_select for getting content type fields
Originally I was doing something along the lines of $query = "SELECT {}" and then $result = db\_query($query). This method works fine for most of my queries until I needed to get the field values and fid from a specific content type. And then be able to call these values when printing inside HTML. Can anyone provide an example of how I would do this?

I had something along the lines of:

```
<?php
$query = "SELECT node.nid AS nid, 'node' AS field_data_field_news_node_entity_type, 'node' AS field_data_field_news_date_text_node_entity_type, 'node' AS field_data_field_news_teaser_node_entity_type, 'node' AS field_data_field_news_body_node_entity_type, 'node' AS field_data_field_news_video_node_entity_type, 'node' AS field_data_field_news_video_image_node_entity_type, 'node' AS field_data_field_mypdf_node_entity_type
    FROM node
    INNER JOIN field_data_field_news_is_featured ON node.nid = field_data_field_news_is_featured.entity_id AND (field_data_field_news_is_featured.entity_type = 'node' AND field_data_field_news_is_featured.deleted = '0')";
?>

$result = db_query($query);

<?php foreach ($result as $row) : ?>

    <div class="featuredArticle">
        <?php print $row->field_mypdf_value; ?>
        <?php print $row->field_mypdf_fid; ?>
    </div>

<?php endforeach; ?>

```

# Answer
> 1 votes
If you have your node object, you can use field\_get\_items to get the field values from the node.

```
$items = field_get_items( 'node', $node, 'field_name' );
// now $items is an array of values... you can manipulate...
// then use the field_view_value to build the render array
$specific_item = $items[0];
$item_build = field_view_value( 'node', $node, 'field_name', $specific_item );

```

Here's a link to the field\_view\_value API doc.

Use the devel module and sprinkle in some dpm()'s to understand the underlying data. It's pretty neat! :)

# Answer
> 0 votes
```
$result = db_query('SELECT field_1, field_2 FROM table_name WHERE bundle = :bundle AND entity_type = :entity_type', array(':bundle' => 'page', ':entity_type' => 'node' )->fetchAll();

```

Will give you an indexed array of objects with the queried values: $results will look like this

```
    array(
      [0] => [standardclass object](
        [field_1] => Value for field_1
        [field_2] => Value for field_2
      )
      // .. One entry for each result ...
      [n] => [standardclass object](
        [field_1] => Value for field_1
        [field_2] => Value for field_2
      )
   )

```

However querying the database directly is quite a strange thing to do so this might not at all be the best practice way for what you are are trying to achieve. Be sure to look into the field API as mentioned by Purdy.

Read more about the query object and resultsets(There is a lot to say about this but this is a good start).

---
Tags: entities, nodes, database
---


# Question
Title: Redirecting doesn't work with a custom form in a block
I developed a custom form with FAPI and added a block for it.

Block is included only on one specific page (basic node).

When user submits this form it should redirect user to external site (URL is a return value from another external site). For this purpose I've used $form\['redirect'\] which was working when this form was used as standalone page. In block it won't redirect and instead the same page is loaded.

I tried other methods too for redirecting such as php header location and drupal\_goto but none of them work.

Perhaps there is something node level overriding that prevents the form redirect?

EDIT:

Block is a very basic implementation on code level. API based hook\_info and hook\_view functions accompanied with custom content function (which returns form markup:**drupal\_get\_form('my\_form')**).

**The redirect** is defined on **hook\_form\_submit($form, &$form\_state)** in which it first makes two calls to external web services and based on return values it either redirects or shows message:

```
// Debug shows that this evaluates true
if (!filter_var($webservice1, FILTER_VALIDATE_URL) === false) {
    $form_state['redirect'] = $webservice1;
} else if ($webservice1 == 'ok' && $webservice2 == 'ok') {
    drupal_set_message(theme_item_list($formvalues),'status');
} else {
  drupal_set_message('Error', 'error');
}

```

# Answer
> 0 votes
I believe the redirect should be `$form_state['redirect']`

---
Tags: forms, blocks, uri, redirection
---


title: How to embed Facebook videos?

text:
# Question
Title: How to embed Facebook videos?
-Drupal 7.37 & Omega4-Subtheme
-Windows7 HP & Toshiba Laptop
-Acquia-DevDesktop WAMP-Stack
-Latest Wysiwyg, CKEditor & Media\_Module & Media\_Oembed

1. Now I have tried everything and nothing allows a Facebook Video to Embed.
2. I have tried using the Facebook-URI/Embed-Code in the Media\_Module-Media-Browser as well as dropping the Facebook-Embed-Code (using cut-and-paste) in the text-area. The Facebook-Embed-Code that Facebook gives you, BTW seems strange to me.
3. Oembed (not the Media\_Oembed Module) did not work at all.
4. Tried using another Wysiwyg-Rich-Text-Editor, besides CKEditor, because CKEditor strips out code and that switch did not help make the Videos embed.
5. Tried editing the CKEditor Advanced-Content-Filter to stop it from rewiring any code and that did not help.
6. The Video-Lightbox Software application seems to refuse the Facebook URI's also.
7. Media\_Oembed also fails to help Media\_Module to recognize Facebook-Embeds or URI's.
8. When I just cut-and-paste the Facebook-Embed-Code directly into a basic HTML-Document outside of Drupal (and even outside of a WAMP-Stack), this also does not work. Viewing the source-code in FireFox, again I see some of the Facebook-Embed-Code is missing, having been stripped out by something. What? FireFox? HTML5? This is the most puzzling. Maybe the WAMP-Stack is necessary for embeds, but the link works.
9. Something seems to be removing part of the Code or else Facebook is using bad code inadvertently, being unaware of some configuration in the outside world.
10. Basically the URI's just deliver a red-reject-box from the Media\_Module-Browser or else they deliver an iFrame or Flash that is dead in the water. Direct cut-and-pastes deliver just direct unprocessed raw code on output or else just, oddly, a link to the Facebook-Page that shows the name of the Video's owner and nothing more.
11. Any thought from anyone? I am just really interested if anyone out there is embedding Facebook-Videos in ANY kind of way and if so, how?

# Answer
> -1 votes
Copy and paste it in the textarea, make sure you have full HTML filter selected, if y do not have that option, go to Text format and create a filter

---
Tags: nodes, media, wysiwyg
---


# Question
Title: Proper approach for showing menu based on node
I'm setting up a new Drupal site and created a content type, taxonomy, and two menus. The taxonomy just has 2 items, which correspond to the menus. What I'd like to do is render the corresponding menu in a sidebar when the user is viewing a node from the content type, ideally highlighting the current item in the menu.

My current thinking is to write a custom module and use the hook\_page\_build. Then in that hook, see if `arg(0)` is 'node' and `arg(1)` is numeric and then `node_load` `arg(1)` and then if that node's type matches my content type, then `field_get_items` to get the node's taxonomy and pull the corresponding menu and then add it to `$page['sidebar_first']`.

Is this the right approach or is there a better way?

Thanks in advance!

# Answer
> 1 votes
I'd say the best way would be to use Menu Block. This would allow you to use blocks built in visibility rules.

All you would need to do is create a new menu block, select which menu to display and select which content type it should be displayed on. The menus get all the functionality of standard menus.

You could also just use the standard block that is created with every menu, check the disabled blocks section for those. Menu Block however has a few more features.

---
Tags: 7, routes, hooks
---


# Question
Title: How to deal with files with %20 in name in Nginx
I have imported a lot of files from apache staging to nginx live and the files that have been rewritten by apache (%20 etc) are not being read by nginx, although nginx has no problem with me uploading files with spaces in them it doesnt like files with %20 etc. in the title.

I am using Perusio's nginx config which works great but i cant tweak it to fix this.

Any ideas?

# Answer
> 1 votes
Think outside the box of web server configuration.

Install the Transliteration module:

> Provides one-way string transliteration (romanization) and cleans file names during upload by replacing unwanted characters.

And install the File Field Paths module:

> In simple terms, File (Field) Paths allows you to automatically sort and rename your uploaded files using token based replacement patterns to maintain a nice clean filesystem.
>
> **Features ...**
>
> Retroactive updates - rename and/or move previously uploaded files (Use with caution)

With both enabled you can goto the Content Type's Manage Field page and edit the field with the file(s) and enable Transliteration on the file name to be retroactively assigned to all uploaded files.

This will change the space character ' ' to '\_' for all uploaded files.

Then you don't need to worry about difficult server configuration issues. I've used File Field Paths to rename thousands of files successfully on production systems.

---
Tags: 7
---


# Question
Title: How theme a page that is generated by a view?
I want to find a solution for my question in drupal 6.x

I have some pages that are created via node/add/page directly in drupal.

but some pages are as result of view module.

Now I want to theme the pages that are generated by views. for example I want to disable primary and secondary menus. change the location of some objects and etc....

I know that page.tpl.php is the base structure of pages. also page-nid.tpl.php is for special page that is directly made by drupal admin area.

but for the pages that are made by special view, how can I theme it . what is the format of tpl.php file for specific page that is created via specific view.

Please help me.

Thanks a lot.

---

let me explain more.

views-view.tpl.php contains the below codes.

```
<?php
/**
 * @file views-view.tpl.php
 * Main view template
 *
 * Variables available:
 * - $classes_array: An array of classes determined in
 *   template_preprocess_views_view(). Default classes are:
 *     .view
 *     .view-[css_name]
 *     .view-id-[view_name]
 *     .view-display-id-[display_name]
 *     .view-dom-id-[dom_id]
 * - $classes: A string version of $classes_array for use in the class attribute
 * - $css_name: A css-safe version of the view name.
 * - $css_class: The user-specified classes names, if any
 * - $header: The view header
 * - $footer: The view footer
 * - $rows: The results of the view query, if any
 * - $empty: The empty text to display if the view is empty
 * - $pager: The pager next/prev links to display, if any
 * - $exposed: Exposed widget form/info to display
 * - $feed_icon: Feed icon to display, if any
 * - $more: A link to view more, if any
 * - $admin_links: A rendered list of administrative links
 * - $admin_links_raw: A list of administrative links suitable for theme('links')
 *
 * @ingroup views_templates
 */
?>
<div class="<?php print $classes; ?>">
  <?php if ($admin_links): ?>
    <div class="views-admin-links views-hide">
      <?php print $admin_links; ?>
    </div>
  <?php endif; ?>
  <?php if ($header): ?>
    <div class="view-header">
      <?php print $header; ?>
    </div>
  <?php endif; ?>

  <?php if ($exposed): ?>
    <div class="view-filters">
      <?php print $exposed; ?>
    </div>
  <?php endif; ?>

  <?php if ($attachment_before): ?>
    <div class="attachment attachment-before">
      <?php print $attachment_before; ?>
    </div>
  <?php endif; ?>

  <?php if ($rows): ?>
    <div class="view-content">
      <?php print $rows; ?>
    </div>
  <?php elseif ($empty): ?>
    <div class="view-empty">
      <?php print $empty; ?>
    </div>
  <?php endif; ?>

  <?php if ($pager): ?>
    <?php print $pager; ?>
  <?php endif; ?>

  <?php if ($attachment_after): ?>
    <div class="attachment attachment-after">
      <?php print $attachment_after; ?>
    </div>
  <?php endif; ?>

  <?php if ($more): ?>
    <?php print $more; ?>
  <?php endif; ?>

  <?php if ($footer): ?>
    <div class="view-footer">
      <?php print $footer; ?>
    </div>
  <?php endif; ?>

  <?php if ($feed_icon): ?>
    <div class="feed-icon">
      <?php print $feed_icon; ?>
    </div>
  <?php endif; ?>

</div><?php /* class view */ ?>

```

But all of these codes are related to the block that is hold the view result.

tell me please, how can I change the primary link or logo object of the output page that is rendered by the view from these codes?

I want to edit the page.tpl.php that is related to the view's generated page. so imagine that my view name is **latest\_topics**

now page.tpl.php should be renamted to what ?!?!?!

* latest\_topics-page.tpl.php ?
* page-latest\_topics.tpl.php?
* or any other name ?

And finally I mean : **Views-view.tpl.php doesn't override page.tpl.php** Please help me.

---

I found the answer of my question.

the page url is www.domainname.com/latest-topics

so by created another **page.tpl.php** and renamed it to **page-latest-topics.tpl.php** it is working...

Thanks a lot friends.

# Answer
I found the answer of my question.

the page url is www.domainname.com/latest-topics

so by created another page.tpl.php and renamed it to page-latest-topics.tpl.php it is working...

Thanks a lot friends.
> 1 votes

# Answer
The templates and theme functions views uses depend a lot on how you configure the View. You can however see this info from within the views interface.

For Drupal 6 it should look something like this:

As you can see, theme information gives you a list of possible template names and mark which one is currently used.
> 0 votes

# Answer
for example if you have a views and it's machine name is "car" then you have to copy the views-views.tpl.php file from the views/theme folder, then past it in the template folder of your theme that you used and rename it to "views-view--car.tpl.php".
last thing you should do is to clear the cache.

to get the correct name of the tpl.php file go to your views configuration and under "advanced" tab click on information link and get the views name
> 0 votes

# Answer
I have done this using a function in template.php.

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

        // Views Page Override
        if ($the_view = views_get_page_view()) {
        if($the_view->current_display == 'my_view_display_name') {
                $variables['theme_hook_suggestions'][] = 'page__my_custom_page';
            }
      }
}

```
> 0 votes

---
Tags: views, theming, 7
---


# Question
Title: How to access from node template a field added by module
I have a content type that has a custom template. My content type is article and I have a node--article.tpl.php that displays the following.

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

```

I have a module that adds a featured image to each node if it is made a featured node in its options. I believe this is the code in the module that is causing it but I'm not positive.

```
function featured_nodes_field_extra_fields() {
  $extra = array();
  // Get feature types from the database.
  $featured_node_types = db_select('featured_nodes_types', 't')
    ->fields('t')
    ->execute()
    ->fetchAllAssoc('machine_name');

  foreach($featured_node_types as $type => $feature) {
    foreach (node_type_get_names() as $name => $value) {
      $extra['node'][$name] = array(
        'display' => array(
          'featured_nodes_' . $type => array(
            'label' => $feature->label . ' - featured image',
            'description' => t('If this node is featured, display the associated image.'),
            'weight' => -10,
          )
        ),
      );
    }
  }
  return $extra;
}

function featured_nodes_node_view($node, $view_mode, $langcode) {
  if (!empty($node->featured_node)) {
    foreach ($node->featured_node as $delta => $values) {
      $node->content['featured_nodes_' . $values['feature_type']] = array(
        '#theme' => 'featured_node_image',
        '#node' => $node,
        '#view_mode' => $view_mode,
        '#db_values' => $values,
      );
    }
  }
}

```

Despite my attempts I have not been able to print the featured image from node--article.tpl.php but I believe I got close. When I added

```
print render($featured_node[0]['image']);

```

It displayed 10080. And a unique number on each featured node. Possibly the field's id. But I was still unable to produce the image. Any ideas?

# Answer
> 1 votes
I managed to figure it out. I found a location in the module with this code.

```
function theme_featured_node_image($variables) {
  $fid = $variables['element']['#db_values']['image'];
  $file = file_load($fid);
  $url = file_create_url($file->uri);
  return theme('image', array('attributes' => array(), 'path' => $url));
}

```

Then I wrote

```
$file = file_load($featured_node[0]['image']);
$url = file_create_url($file->uri);
print '<img src="'.$url.'">';

```

Which allowed me to print the image.

---
Tags: 7, nodes
---


# Question
Title: If taxonomy vocabulary changes from Translate to Localize how to combine terms?
My d7 is using i18n, internationalization taxonomy. I have vocabulary that have option Translate. So it looks like (eng, de): Creative \- Projects \- Portfolio Kreativ (de) \- Projekte (de) \- Portfolio (de)

These terms have relations between one and other. Really I have about 150 terms and want to simplify this vocabulary. Need to change it to Localize option. If I will check Localize all terms beacame independent (single) so this is very very bad. How to combine all of them, please?

# Answer
Looks like you should consider using the Taxonomy Manager module. From its project page:

> ... provides a powerful interface for managing taxonomies. A vocabulary gets displayed in a dynamic tree view, where parent terms can be expanded to list their nested child terms or can be collapsed.
>
> The Taxonomy Manager has following operations and key features:
>
> * ...
> * merging of terms (using the Term merge module in 7.x)
> * ...
> 0 votes

---
Tags: taxonomy-terms, i18n-l10n
---


# Question
Title: Right way to add JS and CSS to node/edit and other forms
I am making a site with a lots of JS, and I am wondering where I should put the JS code. Optimally I would like to keep the JS with each module and not the theme layer. Some content could be exposed as blocks etc.

But I am having some issues with the cache. In my example I need to add JS & CSS to the node edit form. I have used hook\_block\_view, but it is cached. So if there is an error in the node edit form, the drupal\_add\_js & drupal\_add\_css functions are not called. The same seems to be true for hook\_node\_prepare.

Where would you input the JS & CSS layer? and are there hooks that get's called even if there is an error in the node edit form?

# Answer
You should use the `#attached` property to ensure that JS/CSS always gets loaded properly together with another render element. It can also be used to set more values at the same time, as the example code on `drupal_process_attached()` shows. (That example code is for a generic render array, but it can be used also for a form array.)

```
$form['#attached'] = array(
  'js' => array(
    drupal_get_path('module', 'taxonomy') . '/taxonomy.js',
  ),
  'css' => array(
    drupal_get_path('module', 'taxonomy') . '/taxonomy.css',
  ),
);

```

It also works for JavaScript files hosted somewhere else.

```
$form['#attached']['js'] = array(
  'http://code.jquery.com/jquery-1.4.2.min.js' => array(
    'type' => 'external',
  ),
);

```

As side note, it also works for HTTP headers.

```
$form['#attached']['drupal_add_http_header'] = array(
  array(
    'Content-Type',
    'application/rss+xml; charset=utf-8',
  ),
);

```
> 6 votes

# Answer
I feel that these answers and comments desperately needed example code, particularly those of @AyeshK and @Letharion.

The following example obviously adds CSS, but it would be nearly identical for adding JavaScript.

Using @Sumeet's answer, but using the `#attached` property instead of calling `drupal_add_css()`, the code is the following.

```
/**
 * Implements hook_form_FORM_ID_alter().
 */
function MY_MODULE_form_MY_FORM_ID_alter(&$form, &$form_state, $form_id) {
  $form['#after_build'][] = 'MY_MODULE_some_function_name_after_build';
}

function MY_MODULE_some_function_name_after_build($form, &$form_state) {
  $style_path = drupal_get_path('module','MY_MODULE') . '/css/my_css.css';
  // drupal_add_css('file', $style_path);
  $form['#attached']['css'][] = $style_path;
  return $form;
}

```

Finally, the deprecation of `drupal_add_css()` is described in the drupal\_add\_css(), drupal\_add\_js() and drupal\_add\_library() removed in favor of #attached change record.
> 4 votes

---
Tags: 7, forms, javascript
---


# Question
Title: How to translate the Home link when using Path Breadcrumb?
I am using the i18n module in my site. When using the Path Breadcrumb module, I can manage the *Home* link text in Path Breadcrumbs settings, via `admin/structure/path-breadcrumbs/settings`

But there is nothing related to this within the page "Translate interface". Therefor it allways shows in the same language for all of my site languages.

How can I also translate this Home link?

# Answer
Make sure you have the Variable module installed/enabled. If you also have the Path Breadcrumbs module enabled (as seems the case in this question), then there will be an extra tab within admin/config/regional/i18n/variable of your site (tab title = Path Breadcrumbs).

Within that tab, there are over a dozens of options available for marking them as milti lingual variables. The "*Home link Title*" is one of them, and probably the one you need to enable here.
> 3 votes

---
Tags: i18n-l10n, breadcrumbs
---


title: How to add commas to numbers

text:
# Question
Title: How to add commas to numbers
I have a text field. View select the text field. I entered three numeric values to the text field as 3321,33432 and 110343. In the view, I see the values without the commas. I like to see these numbers as 3,321, 33,432 and 110,343. Is there way I can rewrite the output using comma? Please provide some help.

# Answer
What type of text field did you choose for your field? Regular text field?

If you want to be able to add comas. When you **add a new field to your content type** you need to **select INTEGER as your field type**, not text.

Then View's will detect that its an integer field (numbers only) and give you the comma option.
> 3 votes

# Answer
It is a PHP question, if the number is `$num` and you need no decimal point write

```
number_format($num,0,'.',',');

```

No matter what the field is, this code inserts thousands separator, you can use this in `Rewrite Results` textarea. more information in PHP Number Format.

You can also install currency module
> 1 votes

---
Tags: views
---


# Question
Title: How to prohibit a view for specific languages?
We've got a view like news with only English content and we're not planning to add content in other languages any time soon.
But we do have other languages (more static ones) on the page and therefore are using the language dropdown. If I'm in the view: `/news.html` (in English), Drupal and the language dropdown still provides `es/news.html` even though there are 0 news in Spanish.
How can I point the language dropdown to `/` in case I'm on the news view? (I could do Drupal redirects I reckon - but maybe there is a smarter solution which solves the root, not the impact?)

# Answer
> 0 votes
Applying filter while creating views. Add a new filter & select **"Node translation"** from the **"Groups"** listed and check **"Node translation: Language"** and click **"Add"**. Then you can choose languages which you want to show.

**OR**

> * Create Block
> * Under Visibility settings change to PHP (If PHP is not an option, go into modules and enable the PHP input method)
> * Use below code & save :

```
 global $language;
    $lang_name = $language->language;
    if ( $lang_name == "en" ) { return TRUE; } else { return FALSE; }

```

**NOTE**: *Replace the "en" with the two letter name of what ever language you want the block to be visible for. For Example if you want your block only visible when the language is French, change "en" to "fr" .*

# Answer
> 0 votes
It appears to me that your problem is that you cannot specify any filter for the language (or at least that this is part of your problem).

Therefor I think you should verify your configuration at *Configuration -\> Languages -\> detection and selection*: the order should be 'URL, Default, User', and not something like 'Default, URL, User'.

# Answer
> 0 votes
You can also open the Views UI and in the *Access* Select **PHP**.

make sure the *PHP Filter* module is enabled.

in this field you can use the code other guys mentioned above

```
global $language;
$lang_name = $language->name;
if ( $lang_name == "English" ) { return TRUE; } else { return FALSE; }

```

---
Tags: views, i18n-l10n
---


title: How to edit views settings

text:
# Question
Title: How to edit views settings
I created a views. I am not sure what I selected show and Type when I created the view.

After I created the view, I see it is retrieving data from multiple content types. I am trying to edit the view to select the specific content type but i cant find it under edit view page.

Content type that I created name is "xpress". View name is "GlobalSearch". How can I edit the view and select to display only the content type "xpress".

Thanks. D

# Answer
1. Go to Admin -\> Structure -\> Views
2. Search for the view that you have created.
3. Do an edit on the view.
4. In the Filter Criteria, add a criteria for content type "xpress".
5. Save the view and that filter criteria would automatically work.
> 1 votes

# Answer
admin/structure/views/view/globalsearch/edit

`Filter criteria > type` maybe?
> 1 votes

# Answer
Click on Add and search for Published and select yes.

Click on Add and search for Content: Type then checkmark xpress
> 1 votes

---
Tags: views
---


# Question
Title: Is Display Suite compatible with Panels?
-Drupal 7.37 & Omega4-Subtheme
-Windows7 HP & Toshiba Laptop
-Acquia-DevDesktop WAMP-Stack

1. Just a Simple question. Is \[DS\] Display-Suite-Module compatible with \[panels\] and \[panelizer\]?
2. By that I mean do they implement conflicting Drupal-Code strategies for accomplishing the same objective. Do they have any name-space-collisions?
3. I am well aware that they "purpose-wise" cover basically the same territory.
4. I would like to try using one on certain website-projects and the other on other website-projects. I might then leave one unenabled. When I am familiar with both, I might attempt to use both on the same project.
5. Thank you for taking the time to read this.

-

# Answer
> 0 votes
They are compatible in the sense that you can use Panel layouts on DS. *(See picture below)*

You can use DS for one content type and Panels for another content type. Not sure who would win if I enabled both for the same content type, but why would anyone do that?

Where it's *not* compatible is with mini panels, unfortunately you can't insert mini panels into a custom DS dynamic field.

---
Tags: panels, display-suite
---


# Question
Title: Pathauto like pattern setting for creating menu link titles
Pathauto is great, in that it allows you to set the URL alias of a node to some pattern like '\[node:menu-link:parent:url:path\]/\[node:title\]-DEV' for DEV content type.

I am trying to build a single menu containing menu links for two content types. There is typically a node titled: nodecontent for each content type, then with pathauto we set the URL for the DEV content to be nodecontent-DEV by using the above pattern. It allows us to append a string, which is great.

I cannot figure out how to do this dynamically for menu links though. Since the only automatic action Drupal does is fill in the title for 'Menu link title'.

It would be great if I could append -DEV to each menu link (for that content type), so in one menu I could have: Country\>State\>City and Country\>State\>City-DEV.

# Answer
> 0 votes
You could use the Automatic Node Titles module to create the titles including the DEV string, which depending on your other settings could appear in the menu:

> "auto\_nodetitle" is a small and efficient module that allows hiding of the content title field in the form. To prevent empty content title fields one can configure it to generate the title by a given pattern.
>
> When the token module is installed it's possible to use various node data for the auto generated title - e.g. use the text of a CCK field (since 5.x).

**EDIT**

You could also create a simple module to change the title of the nodes for the DEV content type:

**Custom Node Title**

> custom\_node\_title.info

```
name = Custom Title (DEV)
core = 7.x
description = Appends appropriate titles with DEV
package = custom

```

> custom\_node\_title.module

```
<?php
/**
*   Custom Node Title Module
**/

function custom_node_title_node_presave($node)
{
    /* only run if node type is correct and '-DEV' is not found in title to prevent duplication */
    if($node->type == 'article' && strpos($node->title, '-DEV') === false)
    {
        $node->title .= '-DEV'; /* add '-DEV' to title */
        $node->menu['link_title'] = $node->title; /* reset menu link to new title */
    }
}

```

In this example, it changes the title of an Article content type to include -DEV at the end.

---
Tags: routes, path-aliases
---


# Question
Title: How do I do a file upload with other form data in Drupal 6?
I have this in my form function:

```
$form['#attributes'] = array('enctype' => 'multipart/form-data');
... other form fields
$form['form']['form_file'] =  array (
    '#type' => 'file',
    '#name' => 'form_file',
    '#attributes' => array ('class' => 'textarea_crmform'),
 );

```

and when I call file\_save\_upload in my submit function, I am doing this:

```
if ($file = file_save_upload('form_file'))

```

But it never gets into the above if statement.

# Answer
> 1 votes
My guess is that there's an error. Have you looked at your watchdog log? Is the temporary directory setup and writable by the web server?

---
Tags: 6, forms
---


# Question
Title: Conflict between ajax callback and jQuery UI dialog
I have a button that triggers an AJAX callback with the form api like so :

```
$form['show_modal'] = array(
 '#type' => 'submit',
 '#value' => t('Some crazy text'),
 '#ajax' => array(
     'callback' => 'myCallback',
     'wrapper' => 'myWrapper',
 ),
 '#suffix' => '</div>',
);

```

I then do some stuff and return my new form and display it (working).

```
 return $form['myNewForm'];

```

I want to display it in a custom jQueryUI dialog, but when I do that my AJAX callback doesn't work anymore ...

```
 //On click, open modal
 $('#showModale').click(function(){$('#myWrapper').dialog("open");});
 //Modal itself
 $("#myWrapper").dialog({
  autoOpen: false,
  show: {
    effect: "blind",
    duration: 300
  },
  hide: {
    effect: "blind",
    duration: 300
  },
  height: 400,
  width: 1000,
  modal: true,
  resizable: false,
  draggable: false,
});

```

Any ideas about it ?

# Answer
> 0 votes
a simpler approach might be to include the form in a custom block, and set it's css to match the modal design you want but set the initial block display to `none`. Then use an onclick to show the block using whatever transition you want

---
Tags: 7, ajax, javascript, forms
---


# Question
Title: CSV Feeds import troubles with CiviCRM entity reference field
I'm stumped with this particular Feed import problem.

I've got a content type (node) that has an entity reference field that relates it to an number of CiviCRM organization contacts. When you manually create a node, the entity reference field auto-completes the field and if you look at it in the editing view, you see the name of the contact along with their CiviCRM unique contact id. It would look like the following:

Contact Name \[cid:8\]

In the regular view, you just see the Contact Name.

I figured I could use Drupal Feeds and Feeds Tamper and then create a CSV import but I can't seem to format the entity reference field correctly so that the data is accepted. I've tried setting it to "Organization Name" as well as "id" and "user\_unique\_id". I've fed it straight integers for id and the unique id and I've tried "Contact Name \[cid:8\]" as well as just the contact name or just the "\[cid:8\]" part and nothing seems to stick. The content is created but the entity reference field remains empty. I can of course manually enter the values but that defeats the point of the import.

Any ideas?

These are the pertinent parts of the site:

* Drupal 7.x
* CiviCRM 4.4.x
* Feeds
* Feeds Tamper
* Entity
* CiviCRM entities
* Entity Reference
* CiviCRM Contact Reference Field

Thanks, Andrew

# Answer
> 1 votes
Ok, we finally have a solution to this one. Unfortunately I wasn't able to make use of the CiviCRM User Reference field but familiarizing myself with it was a good exercise anyway. I am certain I will use it elsewhere.

Ours is a pretty specific use-case so it's unlikely that the majority of Drupal developers will run into this issue but nonetheless, in case someone else does, here are the details.

We have a content type that contains one or more values of a CiviCRM Contact (Organization Name) and we are using the CiviCRM Contact field in our content type to collect/render those values.

Here's the catch and the why Feeds on its own can't handle importing to the CiviCRM Contact field. The value that the CiviCRM Contact field holds isn't the Organization Name, it's the Contact ID (cid). The CiviCRM Contact field does all of the behind scenes voodoo to interpret String to CID and CID to String and the Feeds module isn't privy to the process because Feeds doesn't have access to the CiviCRM API. Once we figured this out (and it took a while), the solution wasn't really that difficult.

We required two Feeds helper modules: Feeds Tamper and Feeds PHP Tamper

Feeds Tamper enabled us to add a "plugin" that intercepts the CSV values we are importing and pre-process them before handing them off to Feeds to insert the values in the appropriate fields. Feeds PHP Tamper allows us to run PHP code in our preprocessing plugin.

Our solution required us to expose the CiviCRM API to Drupal in a Feeds Tamper PHP "plugin" and then use it to lookup by Organization name and return the CID while we looped through the contents of the CSV file cell. The following is a proof of concept we came up with while working on this:

```
<?php
  civicrm_initialize(); // Expose the CiviCRM API to Drupal

  function cid_lookup($name) {
    $params = array(
      'version' => 3,
      'organization_name' => $name,
    );
    $result = civicrm_api('Contact', 'get', $params);
    return $result['id'];
  }

  $organization_name = 'ACME Company';
  $organization_cid     = cid_lookup($organization_name);
  print "The ID for $organization_name = $organization_cid";
?>

```

Hopefully this comes in handy for someone else too.

# Answer
> 1 votes
Not sure if https://www.drupal.org/project/civicrm\_user\_reference will work for you, but I wrote that when having issues with CiviCRM Contact Reference Field in another use case.

---
Tags: civicrm, feeds
---


# Question
Title: How to create a views display that is not a block or a page?
I often use `views_embed_view()` in various places. I find myself creating views with multiple displays, each with slightly overridden settings for different purposes. I end up creating a lot of "Block" displays just because I need multiple displays. But I don't actually need it to provide a block, and I don't *want* all of those blocks cluttering up my system.

My question: is there a "generic" display (like Master) that I could use to create multiple displays without resorting to "block" or "page" displays?

# Answer
> 1 votes
May be you can create Attachments for the view.

# Answer
> 0 votes
I think you should try View Field View module. It provide the option to embed a view inside another view.

---
Tags: views
---


title: Views filter criteria

text:
# Question
Title: Views filter criteria
I added a field to content type. The field type is select list. I created a view. I added a filter criteria using the above field:

Operator \> Is one of

Options \> Select All is selected.

When I go to front end, I see **-Any-** selected by default but I dont the content/result. When I click **Apply**, i get the result. I am not sure why I have to click **Apply** to get the result. It should give me result as soon I go to views page.

Please help.

# Answer
> 2 votes
I just tested this and got the same problem as you.

I found the solution you need to check mark limit to selected items.

If you don't have the Limit list option, check marking the expose operator also fixes it. You would then have to use css to hide the expose operator if you don't want it.

---
Tags: views
---


# Question
Title: Using form api to store google map location
Is it possible to use form api (write codes) to display and store google map Latitude and Longitude? Most of the modules available is to add new google map field to drupal content type. I don't want to use drupal content type to store as a node. i wish to store the location using db\_insert. Thanks

# Answer
> 1 votes
Yes, there are couple of ways of doing this. You would need to install Geofield which has a Form API element that can be used as such:

```
$form['location'] = array(
  '#type' => 'geofield_latlon',
  '#title' => t('Location'),
);

```

That'll give you a start to work from. I'm looking at embedding a clickable Google map using the GMap module as follows:

```
$form['contact_us']['map'] = array(
  '#description' => t('Enter your location to be displayed as a Google map.'),
  '#type' => 'gmap',
  '#title' => t('Location'),
  '#settings' => array(
    'zoom' => 8,
    'id' => 'location_map',
  ),
);

```

It shows the map however that is about all, so far. But it's another starting point for you!

---
Tags: forms
---


title: How to publish nodes 3 times a day?

text:
# Question
Title: How to publish nodes 3 times a day?
I have a list of unpublished nodes, created with the Views module. I would like a task to be run 3 times a day, at specified times. Every time the task runs, only one of the nodes on the list should be published. How can I do this?

## Steps I have tried

### Scheduler

The Scheduler module requires you to specify the exact time you want the node to be published. This makes it complicated, as I would have to work out when each node is supposed to be published.

### Views Bulk Operations + Rules + Rules Scheduler

With the Views Bulk Operations module, you can create a list of Nodes that are exposed to the Rules module. Rules can then act on the list and publish the node on the list. You can tell Rules to only publish a specific number of nodes.

This works perfectly. Except, it doesn't seem possible to schedule the Rule to run 3 times a day.

You can link the Rule to the main site Cron job, but this doesn't seem very precise as the Cron job could run more than 3 times.

There is a Rules Scheduler module (a sub-module of Rules), but it doesn't look like you can use this a Rules condition. There also doesn't seem to be a way to specify the running time.

### Job Scheduler

This lets you set a time, but it doesn't seem to integrate with Rules or Views.

# Answer
> 5 votes
# Using modules VBO, Rules and Rules Scheduler

About your approach using modules Views Bulk Operations (VBO), Rules and Rules scheduler (submodule of Rules), for which you wrote "*it doesn't seem possible to schedule the Rule to run 3 times a day.*": that appears to me "a" valid approach.

What you actually need to do is a minor variation of what is explained in the tutorial Hourly tasks using rules scheduler: in your case you should use an offset of 8 hours (instead of just 1).

And as explained also in that tutorial: *Initially execute the component manually.* (from then on every other 8 hours the rule will be executed again).

# Using modules Rules and Rules Once per Day

There is a fairly new module related to rules, i.e. the "Rules Once per Day" module. Here is how it works (as per the comment in issue 2495775, from the module owner):

* You specify a **trigger hour** on the administration settings page for this module.
* The Rule trigger will then **run when cron tasks are first run after the start of that hour**. The actual run time will depend on your cron task timings.

The way I understand/Read this (haven't experimented with it yet though) is like so:

* The "Event" will only be triggered when a cron job is run.
* And that event will only be triggered 1 time / day, i.e. "next time cron runs after the trigger hour has passed".

So by creating 3 similar rules, you could have 1 of them run around (say) 6 pm, another one around 2 pm and the ast one at 10 pm.

PS: I'm assuming this question is about D7.

# Answer
> 1 votes
1. Configuring cron jobs using the cron command at specified times you like.
2. Create a module to implement hook\_cron(). To update your first node as `$node->status = 1`.

$node-\>status = 0, means unpublished.
$node-\>status = 1, means published.

```
function yourmodule_cron() {
  update $node->status = 1;
}

```
3. You may use views\_get\_view() get your node nid

```
$view = views_get_view('your_views_name');

$view->execute('default');

$view->preview();

$renderer = $view->style_plugin->row_plugin;

foreach ($view->result as $index => $row) {

  // get node NID from first row

}

```

# Answer
> 1 votes
You can achieve this by using some coding.

1. A view that lists all the nodes that are published for scheduling. If you also apply DraggableViews you can let administrators reorder the nodes by drag-and-drop, which is always nice.
2. A custom PHP function `publishdaily_get_top_node()` that executes the view above and returns the NID for the top node. I would recommend putting this in a custom mini-module.
3. A rule that is triggered on cron run, and checks whether it is time to publish a new node (by, say, checking if the time is between 00.00 and 00.15 – depending on how often your cron runs). If it is time, then it fires action 'load node' and uses `publishdaily_get_top_node()` to get the NID to load. Then it publishes the loaded node.

If you want to make it even more clean, you write a Rules plugin instead of just a PHP function.

If you want it less clean, you write the function directly in an action for executing arbitrary PHP code.

### Reference

# Answer
> 0 votes
Create a rule as follows:

At /admin/config/workflow/rules/components/add

Create a "Action set": Name = Unpublish Content Variables: Data type = Node Label = Node Machine name = node -Continue-

```
    Add Actions:
      Node > Unpublish content
      Data selector = node
      -Save-

```

At /admin/config/workflow/rules Create a "rule": Name = Unpublish Rule React on event = Node \> After saving new content Restrict by type = your content-type -Save-

```
    Conditions:
              Content is published
            Data selector = node
              -Save-

    Actions:
      Schedule component evaluation
      Component Value = Unpublish Content
      Scheduled evaluation date data selector = node:field-your-node-date-field
      Identifier value = Unpublish content ID [node:nid] ([node:title]).
      Node Data selector = node
      -Save-

```

That is, it is not necessary to filter the content when create the component nor add a content-type condition in the rule.

Additionally, check your website cron setting from Admin \>\> Configuration \>\> System \>\> Cron (admin/config/system/cron)

Let me know if you face any query/concern regarding this.

# Answer
> 0 votes
Whether you use a rule or code to publish a single node from the top of your view, I believe the easiest way to schedule it is to use Ultimate Cron.

Set the scheduler to Crontab and for the specific task you can tell it *exactly* when you want it to run. For instance if you want 8am, 12 noon and 4pm you can make the rule:

```
0 8,12,16 * * *

```

---

Further Information:

Elysia Cron appears to allow for custom cron tasks, which may allow you to target a specific rule (perhaps via php code).

---
Tags: views, nodes, rules
---


title: Sign up with no price

text:
# Question
Title: Sign up with no price
What we need is essentially a free product order. We need viewers to be able to sign up for free classes where there is a limit on the number of students. The registration requirement and the inventory limit indicate that it should be a shopping cart function, but the module that allows for free orders is only available in a Drupal 6 module. Is there such a function for Drupal 7?

# Answer
Ubercart for D7 has a built in free order payment method so the UC Free Order module isn't needed here. You can configure the conditions under which the payment method is available under the payment method configuration page (**Store \> Configuration \> Payment method**).

If you need to limit available purchases, the included UC stock module enables restricting products to a limited quantity of available purchases.
> 1 votes

---
Tags: 7, ubercart
---


# Question
Title: how to import term by name in csv file in drupal 7?
I need to import a CSV with 3-4 fields with taxonomy, but I need to insert taxonomy by name. Is it possible with the feeds module?

# Answer
Try Views data export

> This module is designed to provide a way to export large amounts of data from views. It provides a display plugin that can rendered progressively in a batch. Style plugins are included that support exporting in the following types:
>
> CSV
>
> Microsoft XLS
>
> Microsoft DOC
>
> Basic TXT
>
> XML.

Requirements

The batched export functionality of this module requires a MySQL database. This module also requires version 2.7 or higher of views.
> 0 votes

# Answer
You can try `Taxonomy CSV import/export` module
> 0 votes

---
Tags: 7, feeds, importing-exporting
---


# Question
Title: Lightbox doesn't show images loaded by entity_metadata_wrapper
There is a field collection in a content type, it's name is `field_jeld`. This field collection has an image field, it is `field_image`. I also defined an image style called `book_mini`. I need to load the images using lightbox, to do so I set the following image format in manage display of every display mode:

I have to load the images in the front page so I used entity metadata wrapper, this is my code:

```
$nid = "A NID GET FROM SOMEWHERE ELSE";
$node = node_load($nid);
$wrapper = entity_metadata_wrapper('node',$node);
$jelds = $wrapper->field_jeld->value();
foreach ($jelds as $jeld){
    $item_id = $jeld->item_id;
    $fc_wrapper = entity_metadata_wrapper('field_collection_item', $item_id);
    $photo_field = $fc_wrapper->field_image->value();
    $image = theme('image_style',
        array(
            'style_name' => 'book_mini',
            'path' => $photo_field['uri'],
        )
    );
    print $image;
}

```

This code prints the image in *book\_mini* format very well but the problem is, when I click on it, it is not loaded by lightbox and no popup is shown, in fact the image is not a link. How do I can solve this problem?

---

**UPDATE1**

I also tried this

```
$nid = "A NID GET FROM SOMEWHERE ELSE";
$node = node_load($nid);
$wrapper = entity_metadata_wrapper('node',$node);
$jelds = $wrapper->field_jeld->value();
foreach ($jelds as $jeld){
    $item_id = $jeld->item_id;
    $fc_wrapper = entity_metadata_wrapper('field_collection_item', $item_id);
    $photo_field = $fc_wrapper->field_image->value();
    $image = theme('image_style',
        array(
            'style_name' => 'book_mini',
            'path' => $photo_field['uri'],
        )
    );
    $name = $photo_field['filename'];
    $url=  $base_url."/sites/default/files/image/".$name;
    print "<a href='".$url."' rel='lightbox'>".$image."</a>";
}

```

I'm sure the `$url` points to the right file, after clicking the browser opens the lightbox but it doesn't show image, only white screen!

---

**UPDATE2**

The only solution I found is to use **filed collection views** and **Views**. I created a View called *loadcover* and selected `field_jeld` as a field. I also created a View of *field collection views*, called *fc\_jeld*, and selected the required fields. This is the Formatter configuration of `field_jeld` :

Then using this code

```
print views_embed_view("loadcover","block",$nid);

```

it worked ! sounds the lighbox works with field collection only in the Views not the node!!!

# Answer
In the lightbox configuration settings it allows you to define a certain class, so it popups whenever an image has that certain class. So all you have to do is to find a way to add a class to your image.

Perhaps you could use the Image URL Formater module. Set your image field format to url. (So when it prints, it will print the image url instead of the actual picture)

then concatenate a string to add html to your code.

```
print '<img src="' . $image . '" class="lightbox">';

```
> 0 votes

---
Tags: nodes, media, entities, javascript
---


# Question
Title: Where do I make a feature request to drupal.org?
What is the best place to make a feature request about the drupal.org website?

I probably spent an hour searching. There is/was the redesign project, there is the drupal.org issue queue but I was refused access.

FYI - I'd simply like to suggest that project owners have a tab for "roadmap" or "project Future". Sure, the summary page can include that but often it is crammed with things and maintainers forget to talk about what plans they have, what they need, etc.

# Answer
> 1 votes
*Generally speaking*, the correct place to post feature requests for Drupal.org is the **Drupal.org customization project** issue queue.

However, you also wrote:

> FYI - I'd simply like to suggest that project owners have a tab for "roadmap" or "project Future".

If you just want to *suggest* that project owners publish a "roadmap", you can add that suggestion to the community documentation. It is a wiki so you don't request anything - you just do it (like I just did).

If you want to actually modify the project page layout by having a feature where project owner's may add an addtional tab for "Roadmap" to the page summary, you request this in the **Project** module's issue queue

Finally, I shall *not* suggest you use the Webmasters issue queue for any type of feature requests. The Drupal.org webmasters issue queue is for reporting spam, broken links, or user account problems at Drupal.org - and that is about it. My experience is that nothing much happens to feature requests posted there, even if the request just involves flipping a trivial setting in a module already installed. The webmasters obviously have the power to do this, but they do not make decisions about such things. They usually move feature requests to the Drupal.org customization project, and bug reports to the Infrastructure project.

# Answer
> 0 votes
There are indeed quite a few "projects" on Drupal.org that might be a candidate for suggesting such feature request. My best bet for you would be the "projects" Project or Project Issue Tracking.

However, are you sure you want to suggest such feature? Things like "roadmap" are typically located already in either of these areas on drupal.org (related to a specific module and/or distribution):

* in the module's issue queue (often using "roadmap" or "release" in the issue title or issue summary), such as for the Forena module.
* within the community documentation, which you should be able to find via the "Read documentation" link on the project pages.
* on the module's project pages, such as for the ArrayShift distribution.

The technique that I believe works best so far, is what I've started to use in (eg) the Charts module. I.e using issues such as Charts 7.x-2.0 Release and Charts 7.x-3.x Release. These are "parent" issues to which other issues are referring to as their "parent" issue. Combined with the status (color) of each child issue you then also get an idea of the progress of such release. Checkout those parent issues to see that technique at work.

If such feature ever gets requested/implemented, I'd assume/expect it to be another field without the "Resources" section when you edit the project page of a module, where today you can already enter links to Demos, Screenshots, Community docu, etc). These links, if provided, are then shown within the "Resources" block when viewing the project pages.

# Answer
> 0 votes
I will answer this question basing on what I learned in the period I was site maintainer on drupal.org. My answer doesn't reflect in any way what the current site-maintainers think, or the thought of the maintainers of any module.

The first project queue one would think is the one for the Project module since Drupal.org is effectively using that module, but I think it's improbable the current maintainer would plan to add such feature, if that is not generic enough to be applied to other sites as well. The answer is probably going to be something on the lines of "If you want to implement that feature, you can implement it in a custom module."
Drupal.org does use custom modules to implement those features that are not currently used in any module, or to alter how some of the features are implemented in existing modules.

If the feature request involves writing code, then the project queue for Drupal.org customization project is the best choice. In this case, I would also provide a patch for such feature to be implemented.
If the feature request is about a module to enable, I would use the Drupal.org site-maintainer project queue, since some of the site-maintainers have the permission to enable modules on Drupal.org.

In both the cases, be ready to convince other users this is really necessary. In the case of custom code, it is much preferable to be ready to provide a patch for one of the custom modules used on Drupal.org, if one of the maintainers find the feature request interesting.

---
Tags: community-official-site
---


title: custom wrapper to a form api field

text:
# Question
Title: custom wrapper to a form api field
In form api, `#prefix` and `suffix` are not working for `'#type' => 'managed_file'`. Below is my code, is there any other way to wrap this?

```
    $form['cvFile'] = array(
    //'#title' => t('Upload your CV'),

    '#type' => 'managed_file',
    //'#description' => t('The uploaded file will be processed.'),
    '#default_value' => variable_get('cvFile', ''),

    '#upload_validators' => array(
        'file_validate_extensions' => array('pdf doc docx'),
    '#prefix' => '<span class="row">',
    '#suffix' => '</span>'
    ),

    '#upload_location' => 'public://cv/',
    '#process' => array('gng_job_my_cv_element_process'),

    );

```

# Answer
The way you are using #prefix and #suffix is wrong. It should not be a part of #upload\_validators array.

```
    $form['cvFile'] = array(
    //'#title' => t('Upload your CV'),

    '#type' => 'managed_file',
    //'#description' => t('The uploaded file will be processed.'),
    '#default_value' => variable_get('cvFile', ''),

    '#upload_validators' => array(
        'file_validate_extensions' => array('pdf doc docx'),
    ),

    '#prefix' => '<span class="row">',
    '#suffix' => '</span>',
    '#upload_location' => 'public://cv/',
    '#process' => array('gng_job_my_cv_element_process'),

    );

```

Check the form API for this : https://api.drupal.org/api/drupal/developer%21topics%21forms\_api\_reference.html/7#prefix https://api.drupal.org/api/drupal/developer%21topics%21forms\_api\_reference.html/7#suffix
> 1 votes

---
Tags: 7, forms
---


title: render array with images

text:
# Question
Title: render array with images
I have this array in PHP

```
$link = array(
    '#type'    => 'link',
    '#title'   => 'link1',
    '#href'    => 'http://www.link1.example',
    '#suffix'  => '<br />',
  );

```

when i call the render() functions i get the correct html

```
<a href="http://www.link1.example">link1</a>

```

How i can change the above render array in order to include an image as a link?

In other words i want this as output from the render() function

```
<a href="http://www.link1.example"><img src='images/link1img.png' /></a>

```

I have tried to use the theme('image',$array) function but when the result of theme() is passed to the render() i don't see the image to my page but the actual html code.

# Answer
> 4 votes
The pre-render function for a 'link' element type is `drupal_pre_render_link()`...looking at the docs, you can pass these parameters:

* #title: The link text to pass as argument to l().
* #href: The URL path component to pass as argument to l().
* #options: (optional) An array of options to pass to l().

You can force a link prepared through `l()` to display HTML by passing `'html' => TRUE` as an option, so you should be able to do the same through the render array:

```
$image = theme('image', array('path' => 'images/link1img.png'));

$link = array(
  '#type'    => 'link',
  '#title'   => $image,
  '#href'    => 'http://www.link1.example',
  '#options' => array('html' => TRUE, 'title' => 'link1'),
  '#suffix'  => '<br />',
);

```

# Answer
> 1 votes
Better maybe to create a single render array which optionally can be altered through out the render process, ie.:

```
$image = array(
  '#theme' => 'image_formatter',
  '#item' => array(
    'uri' => '/images/link1img.png',
  ),
  '#suffix'  => '<br />',
  '#path' => array(
    'path' => 'http://www.link1.example',
    'options' => array(
      'attributes' => array(
        'title' => 'link1',
      ),
    ),
  ),
);

```

renders into:

```
<a href="http://www.link1.example" title="link1"><img typeof="foaf:Image" src="/images/link1img.png" alt="" /></a><br />

```

If the image has been uploaded using the Field or File module, `image_formatter` can also be used to apply an image style, ie. `thumbnail`:

```
$image = array(
  '#theme' => 'image_formatter',
  '#image_style' => 'thumbnail',
  '#item' => array(
    'uri' => 'public://images/link1img.png',
  ),
  '#suffix'  => '<br />',
  '#path' => array(
    'path' => 'http://www.link1.example',
    'options' => array(
      'attributes' => array(
        'title' => 'link1',
      ),
    ),
  ),
);

```

renders into:

```
<a href="http://www.link1.example" title="link1"><img typeof="foaf:Image" src="http://DOMAIN.TLD/sites/SITENAME/files/styles/thumbnail/public/field/images/link1img.png?itok=Bo4ZpxnG" alt="" /></a><br />

```

For more info, see https://api.drupal.org/api/drupal/modules!image!image.field.inc/function/theme\_image\_formatter/7

---
Tags: media, navigation, theming
---


# Question
Title: Theme a link with l - redirect to translated version
I'd like to insert a link in my node templates that displays when viewing nodes of a particular type (news). That link should lead to the news archive (node/26). Node 26 is a normal drupal page made in swedish (with a menu item and so on). On that page a block is displayed with a viewed list of news items.

There is a translated version of node/26 - translated with normal multi language modules.

What I'd lite for the system is to redirect from node/26 to the english translated version (node/27) if the current users language is english.

I have the module Translation Redirect activated - but it does not redirect.

If a redirect can't be achieved - is there any way that the link function can create the link depending on what the current language is (preferably without if-cases for each language).

Version is Drupal 7.

Thank you very much for any replies!

# Answer
I ended up doing it this way:

```
$nodepath = "node/26";
$languagepaths = translation_path_get_translations($nodepath);
$currentlanguage = i18n_language()->language;
$path = $languagepaths[$currentlanguage];

if (preg_match('/^node/',$path)) {
    $path = "". drupal_get_path_alias($path, $currentlanguage);
} else {
   $path = $nodepath;
}

```
> 1 votes

# Answer
```
<?php
global $language;
$link = url('node/26',array('language' => $language));
?>
<a href="<?php print $link?>">My Page</a>

```

credit to mojzis solution.
> 1 votes

# Answer
according to the docs it should be enough to do something like this :

```
global $language;
$link = l('GO THERE','node/26',array('language' => $language));

```
> 0 votes

---
Tags: navigation, i18n-l10n, redirection
---


# Question
Title: Not getting fieldset as a option while adding new fields in content type
I am adding new field in content type and I want that field's Field type to be Fieldset but there is no such option in Field type column.

Can anyone know how can I add new field's Field type as Fieldset

Thanks

# Answer
> 1 votes
There's no 'fieldset' field type as such.

If you want to wrap entity fields in fieldsets, install the Field Group module:

> Fieldgroup will, as the name implies, group fields together. All fieldable entities will have the possibility to add groups to wrap their fields together. Fieldgroup comes with default HTML wrappers like vertical tabs, horizontal tabs, accordions, fieldsets or div wrappers.

---
Tags: 7
---


# Question
Title: how to insert the See All link in a drupal view block
i created a News block that display only 3 lasted news, and i want create a button "See All News" how i can do it ?

# Answer
> 1 votes
In the footer section of the view add a global text area with the link of the See all news.

**STEP 1:**

**STEP 2:**

**STEP 3:**

Once you are done adding a field in the footer, save the view and the See all news link would work as expected.

**For creating the Read more link**

1. Go to the body field of the news.
2. In the Rewrite Result, you have a checkbox "Trim this field to a maximum length".
3. Once you check the checkbox, you have the option to "Add a read-more link if output is trimmed.".
4. Add the Read more text and use the \[path\] token for getting the path of the node.
5. Save the view and the Read more link would be there for all the news that you have.

Adding an image to help you in a better way:

---
Tags: views, blocks
---


title: Can a node be accessible only by ajax?

text:
# Question
Title: Can a node be accessible only by ajax?
I'm using the **ajax\_links\_api module** to "ajaxify" a certain menu. When a menu button is clicked, the corresponding node loads into a specified div via ajax. This works well.

The problem is that the nodes I want to load in this way should not be accessible as pages. I often create Drupal content that is only designed to appear in views, or as related content on other pages and is not supposed to be displayed by itself. My method is to use .htaccess to block these pages. But when I do that, the ajax can't access them either.

Is there a way to block access to pages in a browser but to allow requests coming from Drupal itself? Localhost access is not really an option since the site may well end up spread across different servers and virtual machines.

If not, then can someone recommend an alternative to the ajax links module - perhaps I need to write some custom ajax that triggers Drupal to serve up a node "directly" rather than via a page - but I am confused about this and could use some pointers in the right direction. I must admit I find the "example" modules confusing!

EDIT: I've tried making a custom module as David Thomas suggests below and using hook\_node\_access. However this stops the ajax call from returning the content.

# Answer
You could use RabbitHole module:

> **Rabbit Hole** is a module that adds the ability to control what should happen when an entity is being viewed at its own page.
>
> Perhaps you have a content type that never should be displayed on its own page, like an image content type that's displayed in a carousel. Rabbit Hole can prevent this node from being accessible on its own page, through node/xxx.
> 1 votes

# Answer
You can control access to nodes with

`hook_node_access`

For example, to restrict node viewing on node/\[nid\] pages:

```
/**
 * Implements hook_node_access
 */
function MYMODULE_node_access($node, $op, $account) {

  // If viewing node and URL path is node/[nid]
  // where [nid] is current $node->nid
  if($op == 'view' && arg(0) == 'node' && arg(1) == $node->nid){
    // Deny access to view current node page
    return NODE_ACCESS_DENY;
  }

}

```

You can add your own conditions to get more specific about access control there.

If you want to deny access to all `node/%node/view` pages, you can do it quite simply with:

`hook_menu_alter`

For example, set the access callback to FALSE

```
/**
 * Implements hook_menu_alter
 */
function MYMODULE_menu_alter(&$items) {
  // Disable the node view page at node/%node
  $items['node/%node']['access callback'] = FALSE;
}

```
> 3 votes

# Answer
I hope I am not too late to try and answer this question... I ran into it because I am in the exact same position as the author...

Well, the difference is I make an ajax call with jQuery's load(). And yes, when I take the href of the node page I get 403 (Forbidden).

But, firstly let me explain my kind of set!

I don't use any modules for restricting access to node content... You see I randomly (again) ran into a video and saw sth that guy did extremely genious (sorry, I wish I could endorse him... didn't bookmark it):

When he created a new content type eg. a slider and because he didn't want to theme the node page (it was a photo and a link!! Why bother?) he unchecked (oh man! God bless you!) the Published default option in the content type edit page. GENIOUS!! It's on top of Promoted to first page etc... So, no Rabbit holes and internal pages modules needed... Users anonymous etc. see 403 when viewing content... And you could change permissions etc. etc. Perfect!! Now, with the new knowledge I have by default restriction to unthemed nodes...

And you might ask! With Views? How I display nodes? EASY: remove Content: Published filter... WOW!! We are set to go!!

But, then ajax call came... I had node page hrefs for the url parameter of ajax call... And, while unpublished I got 403 errors... The thing is I had already made big progress with theming etc. and left it for the end!! Looking desperately for a solution with no refactoring big changes in code and CSS... And I published my content type... So, the bug is this... if someone right clicks and open link in new tab sees... well a mess (in comparison with the other site... I themed it as better as I could... hahahaha)!!

And, then came the lighting (too late of course for me to follow... I don't have enough time right now):

I should have left Content type unpublished and make a new view page... So, when my load() function took the url as input that would show my unpublished-restricted node without problem... Of course, I should rewrite output etc... Instead of /node/id I would have sth like if my content-type was article -\> articles/nid...

I hope this helps someone!! Cheers...
> 0 votes

---
Tags: 7, nodes, ajax, .htaccess
---


title: How to theme a view block

text:
# Question
Title: How to theme a view block
I'm a drupal beginner. I'm using drupal 7 and views. I created a block using views in order to list my latest projects. I'm displaying the block in my home page. I would like to know how to override HTML and Css in order to display something like this:

I want to use this code:

```
<div class="media">
                        <a class="pull-left" href="#">
                            <img src="assets/custom/img/project1.jpg" class="projectImg" title="project one">
                        </a>
                        <div class="media-body">
                            <h4 class="media-heading"><a href="#">Projects One</a></h4>
                            <p>
                                On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire
                            </p>
                            <a class="pull-right" href="#">more details</a>
                        </div>
                    </div>

```

# Answer
> 0 votes
1. Open the view which you've created, expand Advanced Option column
2. open Theme:Information
3. copy the last theme suggestion from `Row style output` row
4. go ahead to the theme(project theme) folder and create that file, example, `views-view-fields--docs---page-1.tpl.php` (this is how my template looks like, this is just for an example), rescan the templates, and save the view.
5. debug `$fields` array (better install Devel module, it provides useful functions, like `dpm()`, `dsm()`..)
6. Copy the code from the sample template and put into this template.
7. Lastly, put the output of fields (e.g. something like this `<?php print $fields['SOME_FIELD']->content; ?>`) to the desired html blocks..

Don't forget to clear the cache;

# Answer
> 0 votes
The solution presented by @xurshid29 is good.

For me i use view modes, with that you can design the list as you want with a tpl file that you create and associate it with your view, you can also make more than one design for the same block.

This is a helpful link to see more details about this solution : 3 Easy Ways to Create View Modes in Drupal 7

---
Tags: views, blocks
---


# Question
Title: Boost crawler - maximum time to use for crawling on every cron run?
I have a drupal 7 site. The site is really big and has few content types, and a lot of content. I use boost and Cache expiration to improve performance.

I will be happy to get some information regarding the crawler of Boost. I want to Pre-cache as much pages of the website as I can, so they get cached before anyone accesses them.

what is the maximum recommended time (in seconds) to use for crawling on every cron run?

# Answer
> 0 votes
I am using it, and 30 second enough.

---
Tags: performance, cron, caching
---


# Question
Title: WSOD while using Boost after upgrading to Apache 2.4.6
I was using Boost module with Drupal 7 for a few months and all was working fine.

I recently upgraded to Apache 2.4.6 and noticed that Drupal frontpage has white screen.

I disabled Boost and uninstalled it and the site worked fine after that. Then reinstalled Boost and it was generating cache but the frontpage was WSOD again.

Any idea what could be causing this and/or how to fix?

# Answer
> 0 votes
check by putting this code in you index.php.

**strong text**

error\_reporting(E\_ALL); ini\_set("display\_errors", 1); include("file\_with\_errors.php");

this will tell you what is happening, or you can also check in your Watchdog.

---
Tags: 7, caching, wsod
---


# Question
Title: simplenews. confirmation of subscription for registered user
purpose: confirmation of subscription for registered user

installed on the website simplenews module (https://www.drupal.org/project/simplenews). now on the main page there is a form to subscribe to the newsletter.

if the user is not authorized, he introduces email and sends a subscription request, he comes to notice by email that he signed up for the newsletter and confirm the proposal (!) the desire to receive the newsletter.

if the user is authorized, he sees only the button (email enter) and if you send a subscription request, it immediately becomes signed.

can to make it so that an authorized user before activating the subscription, as well as anonymous, received a notice to activate your subscription?

# Answer
> -1 votes
well, since no one here, I will use:

```
simplenews_subscribe_user($email, $tid, TRUE, 'website');

```

---
Tags: emails
---


# Question
Title: Responsive bootstrap grid with 6 columns of equal heights
In the front page of our website, I would like to list down groups led by researchers and each group is having a thumbnail picture and a title where the picture is of fixed width/height but, the title is not (could be small or large - title appearing a the bottom of the image).

For some reason the grid is not displaying properly and I feel like it is due to the big/small titles of the groups which cause this issue. Column heights could be an issue.

My settings are as follow:

Drupal 7 Views 3 (Block and/or Page) Unformatted Fields

http://www.bootply.com/wtGxTJjXva (I have 18 divs and they have to be divided into six in each row but, it does not) - could anyone point out what I am missing?

According to the image, first row and last column is showing two divs rather than one and in second row I got three divs squeezing into single column.

# Answer
I couldn't find a proper solution to this issue however, fixed the problem with giving each div (within row class) a height of 200px and it perfectly organized everything.

I can use viewports to assign an appropriate height (than 200px for all displays) for different views.
> 1 votes

# Answer
You should use '**Bootstrap Grid**' format for Views in some cases, which you'll be able to select after install/enable of the Views Bootstrap module. Here is a quote about this module (from its project page):

> ... enables you to create components following the theme structure of the Bootstrap framework all within the configuration settings of the powerful Views module.
> 2 votes

# Answer
I had the same problem and had tried jQuery/Javascript solutions or CSS. I ended up using the module Views Responsive Grid. For a two column grid layout I edited the View and used these settings:

```
 Format: Responsive Grid
 Number of columns: 2
 Column classes: views-column col-sm-6 (for every column)
 Row classes: views-row clearfix (for every row)

```

In your case, since you want t 6 column grid, you would use the following settings for the Column Classes:

```
 views-column col-sm-2

```

I hope this helps!
> 1 votes

# Answer
If you list the items in a for/foreach loop, add

```
<div class="clearfix"></div>

```

at after each 6th item. For example

```
$items = array(...);
$j = 0;

foreach($items as $i){
    if(++$j % 6 == 0){
        echo '<div class="clearfix"></div>';
    }
    echo '<div class="col-md-2">' . $i['key1'] . '</div>';

}

```

Thus, your items will be in order.
> 1 votes

---
Tags: views, theming, bootstrap-theme
---


# Question
Title: Summary/Trimmed field in view doesn't include Read More link
I have a view, and the key display points are:

* Format: Unformatted List (I'm adjusting the views look through CSS)
* Show: Fields

One of the fields to show is Body (so, a textarea.) When I choose to display it as "Summary or Trimmed", and set the trim length to, say, 600, it trims it fine, but it doesn't show a "Read More" link to the content's page. Is there something I'm missing?

# Answer
> 1 votes
did you check " Add a read-more link if output is trimmed. "?

If yes, maybe the problem is, that the text is not trimmed. If you want to have a "read more" link in any case, then you sould add the field "Link" to the view. You can then also enter your custom text, e.g. "details..." instead of "read more" etc.

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


# Question
Title: How can I import special characters using Feeds?
I am using the Feeds module to import data into my site from a CSV file.

When I try to import a row that has the € character, nothing gets imported and I get an error message.

> error:General error: 1366 Incorrect string value: '\xE0 Cali...' for column 'message' at row 1

How can I import special characters using Feeds?

# Answer
> 0 votes
Consider using the Feeds Tamper module. Here is a quote from its project page:

> ... provides a small plugin architecture for Feeds to modify data before it gets saved. Several plugins are available by default and are described in the examples section below. Additional plugins can be added in separate modules or through the issue queue.

It allows for HTML encoding / decoding of feeds content before saving.

PS: Feeds Tamper doesn't know anything about taxonomy terms (you cannot use it for "Terms", as mentioned in a comment to this answer, which the original question didn't mention though).

# Answer
> 0 votes
I had also problems importing special german and french characters with feeds. The problem was solved this way: \- Open the CSV File in editor (e.g. pspad) \- Set Format to UTF 8 \- Save

--\> you have to do this even when it shows, that the format is UTF 8.

Maybe this helps?

---
Tags: feeds, importing-exporting
---


# Question
Title: Hide Fields in Edit Page based on Role and Content Type?
Use Case: Content Editor A (Role of Monday) when edting a node (of Content Type Alpha) is able to use Field AA and Field BB.

But Content Editor B (Role of Tuesday), when editing the same node, does not see Field AA and Field BB.

I have experimented with many of the modules of this regard (Field Permissions, Conditional Fields, Rules), but nothing that can compute for all four conditions (role, content type, edit, fields).

# Answer
How does field permissions, custom permissions, not work for you?

> Example: Using field permisions, I am able to "hide" Field AA by not allowing Content Editor A (Role of Monday) to Edit, or View. But...it also hides the Field AA in Views. That's not what I want. The Editor should still be able to see the Field in any View.

In the above picture, Monday is not going to see the field when he edits the page, but will be able to see the field when its displayed by views.

This is the solution to the Example you provided. In your original question, it would be the role of Tuesday who needs to look like that.
> 1 votes

---
Tags: users
---


# Question
Title: How to get a Drupal 7 Services 3 custom resource to fire
I have a service endpoint defined in a custom module, as well as a custom resource. They both appear in the Services admin pages, with the resource and its operation checked.

When I hit http://localhost/myservice/myresource?myparm=1, I do not make it to the callback for the resource, but do not receive an error message. The log output shows:

```
Location    http://localhost/myservice/myresource?myparam=1
Message
Server info main object:

stdClass Object
(
    [module] => rest_server
    [endpoint] => myservice
    [endpoint_path] => myservice
    [debug] => 1
    [settings] => Array
    (
    )

```

)

Which *seems* to indicate that it is only recognizing the endpoint and not the resource portion of the path.

The defining code is as follows:

```
function my_feed_ctools_plugin_api($owner, $api) {
  if ($owner == 'services' && $api == 'services') {
    return array(
      'version' => 3,
      'file' => 'my_feed.services.inc', // Optional parameter to indicate the file name to load.
      'path' => drupal_get_path('module', 'my_feed'),
    );
  }
}

function my_feed_services_resources() {
  $my_resource = array(
    'myresource' => array(
      'retrieve' => array(
        'file' => array('type' => 'inc', 'module' => 'my_feed', 'name' => 'my_feed.services'),
        'callback' => '_myresource_retrieve',
        'help' => 'Lorem ipsum.',
        'args' => array(
          array(
            'name' => 'myparm',
            'optional' => TRUE,
            'source' => array('param'),
            'type' => 'string',
            'description' => 'Lorem ipsum',
          ),
        ),
      ),
    ),
  );

  return $my_resource;
}

function my_feed_default_services_endpoint() {
    $endpoint = new stdClass();
    $endpoint->disabled = FALSE;
    $endpoint->api_version = 3;
    $endpoint->name = 'myservice';
    $endpoint->server = 'rest_server';
    $endpoint->path = 'myservice';
    $endpoint->authentication = array();
    $endpoint->server_settings = array();
    $endpoint->resources = array(
      'myresource' => array(
        'operations' => array(
          'retrieve' => array(
            'enabled' => '1',
          ),
        ),
      ),
    );
    $endpoint->debug = 1;

    return array($endpoint);
  }

```

and in my\_feed.services.inc

```
function _myresource_retrieve($args) {
  print "args=" . print_r($args,1);
}

```

# Answer
> 2 votes
You need to wrap your **retrieve** resource in an `actions` array:

```
function my_feed_services_resources() {

  $my_resource = array(
    'myresource' => array(
      'actions' => array(
        'retrieve' => array(
          'file' => array('type' => 'inc', 'module' => 'my_feed', 'name' => 'my_feed.services'),
          'callback' => '_myresource_retrieve',
          'help' => 'Lorem ipsum.',
          'args' => array(
            array(
              'name' => 'myparm',
              'optional' => TRUE,
              'source' => array('param'),
              'type' => 'string',
              'description' => 'Lorem ipsum',
            ),
          ),
        ),
      ),
    ),
  );

  return $my_resource;
}

```

You can then "*fire*" it by doing a **POST** to: `?q=[my-endpoint]/myresource/retrieve.json`

Don't forget to attach the **X-CSRF-Token header** to your POST calls. Its value can be retrieved here: `?q=services/session/token`

---
Tags: services
---


# Question
Title: Views PHP: Comparing two Field and display Answer
I tried to build a soccer magazine website. I want to display Match Win/Loss/Draw in the Match Result Page with the score result. I want to display it like:

if \[field\_score1\] \> \[field\_score2\] display 'Win' if \[field\_score1\] \< \[field\_score2\] display 'Loss' if \[field\_score1\] = \[field\_score2\] display 'Draw'

Im stuck please Help.

# Answer
> 0 votes
First, In your Match Results view, add a **Global: Custom text** field and just leave it blank/empty. (we will use this field to print the outcome)

You can override the view's display through your themes template file.

Go to sites/all/themes/YOURTHEME/ look for template.php and open it. You probably have other code inside there, so make extra space by hitting enter at the bottom and add the following code.

```
function YOURTHEME_preprocess_views_view_fields($vars){

      if ($vars['view']->name == "VIEWNAME" && $vars['view']->current_display == "DISPLAY" && $vars['fields']['field_score1']->raw > $vars['fields']['field_score2']->raw){
        $vars['fields']['nothing']->content = print 'Win';
      }

      else if ($vars['view']->name == "VIEWNAME" && $vars['view']->current_display == "DISPLAY" && $vars['fields']['field_score1']->raw < $vars['fields']['field_score2']->raw){
        $vars['fields']['nothing']->content = print 'Loss';
      }

      else if ($vars['view']->name == "VIEWNAME" && $vars['view']->current_display == "DISPLAY" && $vars['fields']['field_score1']->raw == $vars['fields']['field_score2']->raw){
        $vars['fields']['nothing']->content = print 'Draw';
      }

}

```

Replace YOURTHEME with your actual theme name

Replace VIEWNAME with your view machine name. (example: match\_results)

Replace DISPLAY with your display machine name. (example: block, block\_1 ) You can find the name by looking at your view. (see picture below). If you're using the Master view, then the machine name is "default"

.jpg

---
Tags: views
---


# Question
Title: Benefit of running custom query over views
I have a content type and some nodes. I am displaying latest 10 nodes from these content type through views block display. Is there any benefit if i add a custom SQL query to display latest 10 items. I will use the same SQL query that i got from view.

# Answer
Another module to consider for situations where views "might need some help" is Forena (disclosure: I'm a co-maintainer of it). Here is a quote from one of its community docu pages, i.e. Reasons for considering Forena:

> "Why not use views instead of forena?" ... The answer is generally something along the lines of "Most forena users love views, views is great! If you want to report against external data though, or you want to do **aggregation or analytics**, Forena is much more suited to address these requirements."

And since this question is about blocks also, you may want to take advantage of the Forena integration with the Bean module. Here is a quote about that module, its project page:

> Think of a Bean as a method to provide new types (compared to node this would be a content type) which then provides an add content interface to create as many blocks as you require (see screenshot below). The bean content can then be placed around the site just like any other block.

You may also want to look at my answers to these somehow related, I think, questions:
> 0 votes

# Answer
Not really. you should stick to using Views; it will provide you more benefits. To name a couple:

* Less custom code to maintain; it's one of the mostly heavily used modules and will be part of D8 core. There's much less worries of security holes, bugs, etc.
* The versatility of the Views features: caching, multiple view displays, filtering, a UI to change all this, etc.

I'd say the only exception to this would be the instances where your query is going to be hit very often, in which case you'd might be able to squeeze more performance out of an optimized SQL query.

For your needs, a block of 10 latest nodes, views will do everything you need it to, not be a burden on performance, and will take much less time to complete than creating & maintaining possibly bug ridden custom code.
> 1 votes

---
Tags: database
---


# Question
Title: "exceeded the maximum file size" error even when uploading small files
This error in my Drupal 7 site happens when I try to upload an image through `image_field` field. This is the error:

> An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (64 MB) that this server supports.

Although I am trying to upload a small 5KB photo, this problem exists. I know this is kind of common problem, but can't understand why this happens for as small images as 5KB!

How I can fix this? At first I thought this issue may have been temporary and does appear to have resolved itself this morning but again it happens.

# Answer
I found a workaround, as this is a tricky one to nail down.

Don't hit the "Upload" button at all. Just hit the "Next" button directly. If that works, you ran into the same problem I did.
> -1 votes

---
Tags: 7, files
---


title: Expanding the HTML view

text:
# Question
Title: Expanding the HTML view
I am new to Drupal and am having trouble getting my custom HTML to take up most of the page. As you can see below, it is confined to the center and takes up a tiny percentage of the screen.

Here is the image of my module:

Thanks for all the help!

# Answer
> 1 votes
First of all, you should't use a Drupal default theme. As when you update Drupal core, you're going to overwrite all your theme files. So if you want to use a default Drupal theme you need to create a sub theme, if you haven't already. Follow this tutorial Creating A Drupal 7 Sub Theme.

Secondly, it looks small because you have items in your left column.

Thus, you need to remove the left column blocks. Go to /admin/structure/block and disable those blocks. **OR** Edit those blocks and in the **Show block on specific pages** you can control on which pages you want them to show up or be excluded from.

If that still doesn't do it, you need to edit your theme files. Go to /sites/all/themes/YOURTHEME/ **folder** and edit the page.tpl.php file and get rid off the left column.

Even after doing this, if you still want it bigger, then right mouse click on the page and select inspect element. Find the name of the div class or id that is controlling your output.

example `<div id="hello" class="cool">`

then on your css you put

`#hello { width: 5000px; }` if its and ID

`.cool { width: 5000px; }` if its class

If it has both, pick whichever you want

BTW: Your themes css file is located in the sites/all/themes/YOURTHEME/css folder.

**Finally, after you make changes always remember to clear/empty your cache**

# Answer
> 0 votes
Here are a few contributed (+ free of charge) themes you may want to look at (assuming your using Drupal version 7):

Actually there are hundreds of great themes.

When cherry picking from this list, you may want to use criteria such as responsive, fluid (that appears to be one of the issues you're struggling with), base theme, etc ...

---
Tags: theming
---