# Question
Title: Making a custom theme and want to know how to style first post different from the rest
After months of figuring out how to upload a background image, I decided to scrap that and use a solid color with the color picker.

Now I moving on making a custom theme and it's very different from making a WordPress theme. So I need help with the following:

On my page.tpl.php, is there a way to have the first post different from the rest of the posts? Example: First post has a title, date, time and a description. The rest just have a date and title.

Also I don't want to use view module as it looks complicated to setup and I want to use as little of modules as possible.

All help is greatly appreciated and thanks for understanding my annoying questions for help, Gregory S.

UPDATE: Looks like I'll have to do views after all.

# Answer
Using views module to make it :

1. go to -\> views -\> add new view
2. give a name
3. Check Create a page , give a title and a path for the page
4. leave other settings for now and press Save and Continue
5. now in Page Settings -\> Use Pager -\> click on Paged,...
6. change offset to '1' (this will skip the first node)
7. in top menu there is a ADD menu just beside PAGE menu , Click ADD
8. Select 'ATTACHMENT'
9. In format Pane Change Display format to HTML LIST (choose for option as "THIS PAGE")
10. Change Show to Fileds (choose for option as "THIS PAGE")
11. List Field Items you want to display (Again don't forget to change "For" Settings or you would alter other display)
12. ATTACHMENT SETTINGS -\> attach to -\> page
13. ATTACHMENT SETTINGS -\> ITEMS TO DISPLAY -\> '1'

now you have done some thing . to have a better format for display its better to learn "Pannels" And "Page Manager" Modules too .
> 1 votes

# Answer
What you can do is:

1. Create a custom page using hook\_menu.
2. Use Drupal's Database (DBTNG) to get your list of contents. You can do two separate queries for this. The first one would just return one result with more fields than the second. Also you could add the Drupal's pager functionality right out of the box here since you will be using db\_select.
3. Use hook\_theme to create the template for your "node teaser" so that it makes your raw data manipulation separate from your presentation hence the need for a custom template.

Your main code would somewhat look like:

```
function YOURMODULE_page_view() {
  $special_node = db_select(...);
  $nodes = db_select(...);
  $output = array();

  // do stuff here for $special_node_fields
  $output[] = theme('custom_node_theme', $special_node_fields);

  // look through all remaining nodes
  while($nodes) {
    // do stuff here for $node_fields
    $output[] = theme('custom_node_theme', $node_fields);
  }

  return $output;
}

```

This gives you better view on the data manipulation you need to get the list you need.

Also don't forget to replace the **Default front page** value with your custom page in the **Site Configuration** page.
> 1 votes

# Answer
The easiest solution is by using views module , it will take you just a few minutes but if you really want to ignore it , there would be another way :

Download and install the devel module (you will find it as a helping hand when developing on drupal , when you are done developing you can unistall it)

in your theme folder you would need a page-front.tpl.php , drupal will use this file (if exist) to make front page of the site . for now just copy and rename the page.tpl.php to make this file .

in page-front.tpl.php file enter this code in the first line:

```
dsm($content);

```

now visit your home page , there should be a box containing details about content variable of your home page . take some times and you will find many variables which you can build your frontpage with .

Note: The Views module has an option called Display format , if you want to deal with fields (like title , body or even author and .. ) you must select a field view type (like HTML List of Fields) then in fields tab you can add and arrange fields . One more thing if you want to have a view that has two different kind of display (example : first node in full body and rest of the nodes in trimmed format) use Views Attachment for the job.
> 1 votes

---
Tags: 7
---


title: Theme div.item-list of views pager?

text:
# Question
Title: Theme div.item-list of views pager?
How can I theme the div with a class of item-list that appears around a views pager? All I need to do is add an additional class to this div when it surrounds a pager.

I can find lots of documentation on theming the content of the pager, but none on how to theme them this div.

# Answer
Typically, unless you are using a specific contributed module, the pager is a template file that comes with views. You can override `theme_pager` for the specific view (or all your paged views) and add the additional div.

https://api.drupal.org/api/drupal/includes!pager.inc/function/theme\_pager/7

Examples on how to do this: https://www.drupal.org/node/387786
> 0 votes

# Answer
function theme\_pager https://api.drupal.org/api/drupal/includes%21pager.inc/function/theme\_pager/7

Its only the very end of the file where anything needs to be changed, by the code comment "Add a div"

```
function THEMENAME_theme_pager($variables) {
  $tags = $variables['tags'];
  $element = $variables['element'];
  $parameters = $variables['parameters'];
  $quantity = $variables['quantity'];
  global $pager_page_array, $pager_total;

  // Calculate various markers within this pager piece:
  // Middle is used to "center" pages around the current page.
  $pager_middle = ceil($quantity / 2);
  // current is the page we are currently paged to
  $pager_current = $pager_page_array[$element] + 1;
  // first is the first page listed by this pager piece (re quantity)
  $pager_first = $pager_current - $pager_middle + 1;
  // last is the last page listed by this pager piece (re quantity)
  $pager_last = $pager_current + $quantity - $pager_middle;
  // max is the maximum page number
  $pager_max = $pager_total[$element];
  // End of marker calculations.
  // Prepare for generation loop.
  $i = $pager_first;
  if ($pager_last > $pager_max) {
    // Adjust "center" if at end of query.
    $i = $i + ($pager_max - $pager_last);
    $pager_last = $pager_max;
  }
  if ($i <= 0) {
    // Adjust "center" if at start of query.
    $pager_last = $pager_last + (1 - $i);
    $i = 1;
  }
  // End of generation loop preparation.

  $li_first = theme('pager_first', array('text' => (isset($tags[0]) ? $tags[0] : t('« first')), 'element' => $element, 'parameters' => $parameters));
  $li_previous = theme('pager_previous', array('text' => (isset($tags[1]) ? $tags[1] : t('‹ previous')), 'element' => $element, 'interval' => 1, 'parameters' => $parameters));
  $li_next = theme('pager_next', array('text' => (isset($tags[3]) ? $tags[3] : t('next ›')), 'element' => $element, 'interval' => 1, 'parameters' => $parameters));
  $li_last = theme('pager_last', array('text' => (isset($tags[4]) ? $tags[4] : t('last »')), 'element' => $element, 'parameters' => $parameters));

  if ($pager_total[$element] > 1) {
    if ($li_first) {
      $items[] = array(
          'class' => array('pager-first'),
          'data' => $li_first,
      );
    }
    if ($li_previous) {
      $items[] = array(
          'class' => array('pager-previous'),
          'data' => $li_previous,
      );
    }

    // When there is more than one page, create the pager list.
    if ($i != $pager_max) {
      if ($i > 1) {
        $items[] = array(
            'class' => array('pager-ellipsis'),
            'data' => '…',
        );
      }
      // Now generate the actual pager piece.
      for (; $i <= $pager_last && $i <= $pager_max; $i++) {
        if ($i < $pager_current) {
          $items[] = array(
              'class' => array('pager-item'),
              'data' => theme('pager_previous', array('text' => $i, 'element' => $element, 'interval' => ($pager_current - $i), 'parameters' => $parameters)),
          );
        }
        if ($i == $pager_current) {
          $items[] = array(
              'class' => array('pager-current'),
              'data' => $i,
          );
        }
        if ($i > $pager_current) {
          $items[] = array(
              'class' => array('pager-item'),
              'data' => theme('pager_next', array('text' => $i, 'element' => $element, 'interval' => ($i - $pager_current), 'parameters' => $parameters)),
          );
        }
      }
      if ($i < $pager_max) {
        $items[] = array(
            'class' => array('pager-ellipsis'),
            'data' => '…',
        );
      }
    }
    // End generation.
    if ($li_next) {
      $items[] = array(
          'class' => array('pager-next'),
          'data' => $li_next,
      );
    }
    if ($li_last) {
      $items[] = array(
          'class' => array('pager-last'),
          'data' => $li_last,
      );
    }
    // Add a div
    return '<div class="pager-wrap"><h2 class="element-invisible">' . t('Pages') . '</h2>' . theme('item_list', array(
                'items' => $items,
                'attributes' => array('class' => array('pager'))
            )) . '</div>';
  }
}

```
> 0 votes

---
Tags: theming
---


# Question
Title: How to show users Online and with Photos filter on views
want a view that will have this functionality:

https://www.thaifriendly.com/browse.php

There is a radio box to see users that are:

1. Online
2. With Photos

I have played with views but can't find a way to make it work, the current\_user field works, but it only displays the user that is logged in at the moment, not ALL logged in users

There is not current\_user filed in sort either.

Thanks, Bruno

# Answer
You can filter by "Last Access" and set it to show Last access is less than or Equal to -2 Minutes ;)
> 0 votes

# Answer
You can achieve that by using the User Stats module

> Provides commonly requested user statistics for themers, IP address tracking and **Views** integration.
>
> Statistics are:
>
> 1. days registered;
> 2. join date;
> 3. days since last login;
> 4. days since last post;
> 5. post count;
> 6. login count;
> 7. **user online/offline;**
> 8. IP address;
> 1 votes

---
Tags: views
---


# Question
Title: Change the "Create [content type]" title
I allow registered users to create content of type X, so they can go to the /node/add/X page and fill in the form. However, I want to give this page a bespoke title, i.e. "Make an X" rather than "Create X". I have tried adding a string override in settings.php, and also tried with the string overrides module. However, neither of these worked.

What is the best way to do this? (I don't want to install another module if I can avoid it, I already have too many and this seems like a trivial issue).

# Answer
> 0 votes
You could do:

```
function MY_MODULE_NAME_form_alter(&$form, &$form_state, $form_id)
{
    if($form_id == 'myContentType_node_form') {
         drupal_set_title('Your custom title');
     }
 }

```

---
Tags: nodes, string-overrides
---


# Question
Title: How do I write a hook to compile css and js with drush make?
We are using `drush make` in our deployment of new and updated platforms through Aegir and thus `drush provision`.

We do not keep our theme `css` and `js` under version control as it complicates any conflict resolution between `coffee` and `scss` source files.

I want to automate the compiling of the `css` and `js` directories as part of the *Create new platform* provisioning script run by Aegir but cannot think of the right way to do this.

## Main issues:

* The granularity of a `drush-hook-post-make` is too course; not every download needs to be processed: e.g. only one theme needs to run a compile script after having been cloned from our git repo by drush make. How would we distinguish which downloads needed post-make processing?
* git pre-commit and post-checkout hooks are under vc in the theme's repo and would do the compiles but need to be explicitly invoked. Currently we manually symlink to the vc'd git hooks and run the compiles ... would like to automate this step.

# Answer
In general, you shouldn't use Drush for that. Instead, use a build process, and one of the steps in the build would be `drush make`.

There are a number of existing build systems that can be used to achieve what you're looking for, including (but not limited to):

A typical process would have the following steps:

* Delete build TARGET directory
* `drush make drupal.make TARGET --prepare-install`
* Symbolically link custom profiles, themes, and modules
* Execute task to compile CSS, JS
> 2 votes

---
Tags: drush, aegir
---


# Question
Title: How to create a module to insert some analytics code in the footer of website pages?
I want to create a module for Drupal 7, with a simple scope. It's just to insert the analytics code in the footer of website pages and with an option to exclude some pages if required.

I just need a module configuration page with 1 text field to enter the Analytics ID. And a text area below it, just like in blocks configuration page, which allows you to show the block on specific pages.

After this info is saved, the code should be inserted in the footer of each page, with that Analytics ID.

Can anybody tell me what hooks I will need to implement this functionality?

# Answer
> 1 votes
These two links should get you started:

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

https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook\_page\_alter/7

# Answer
> 0 votes
Consider looking at the Code Examples For Drupal. Excerpt from its project page:

> ... contains many modules which hopefully illustrate best practices for implementing various Drupal APIs. These modules can be enabled individually, and will typically add menu items to your site, which should guide you through their features. You can then look through the code to see what they are doing.
>
> Developers can learn how to use a particular API quickly by experimenting with the examples, and adapt them for their own use.

---
Tags: 7, hooks
---


# Question
Title: How to change wrong English sentences in contributed module?
Sometimes we find grammatically wrong English sentences or spelling mistakes in some contributed modules. While doing translations, we can translate the way we want.

But how to change these kind of sentences or words, also if the client wants to change it in English? As we know, we can't do changes even in contributed modules.

So, do we need to write custom module **or** use String Overrides module **or** contact the maintainer/contributor? Which is the best way to do it?

# Answer
Another approach is to use GIT for such contributed modules to actually change such sentences or words. E.g. with the master branch corresponding to the official version of such module, and a branch containing all the changes.

In doing so, it is straight forward to also create a PATCH each time such changes are needed, which you can then also attach to an issue in the issue queue to report about such changes. Bonus: you're contributing to Drupal! ... Which should also show up in your D.O profile ... By creating such "issue" (in the module's issue queue, the module maintainers will get notified automatically (unless they turned of such notifications for their modules). So that's "a" way to contact the maintainer/contributor. Refer to comment #1 in issue # 2327917 for a contributed patch containing only a 1 character typo correction (remove an "s" that was not appropriate), and which I committed afterwards.

If you're not able or willing to create such patch, then at least "report" about it in the issue queue, even if it is only some small issue (in the format of a few lines or text about the typo to be corected). Such issues should get picked up soon by the module maintainers (who will transform that in a patch, etc).

And next time the module gets updated, you use GIT to also update the master branch of that module in your own site. After doing so, you then also use GIT to re-apply all relevant changes that are needed for the new version again. For patches that got accepted in the official version of the module, you won't need to reapply their changes anymore of course.

With this approach, you've reduced your issue to something like maintaining a custom version of a module, and at the same time you're contributing to a permanent solution to reduce the need for such changes in the future.
> 3 votes

# Answer
If it's a mistake you should inform the maintainer/contributor so the can change it. Keep in mind that it could be an other english, then there would be no change. (Like compare Brit to US english)

I would do it with String Overrides, and check again on module update.
> 1 votes

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


# Question
Title: Installing Drupal with existing Pantheon site?
First, I am completely new to, well, all of this... So I'm sorry if I sound like an idiot. I have been fighting with this thing all day, and I think I'm more confused then when I started. I work for a non-profit, and I'm supposed to be helping our web designer with the new website. He uses Drupal and Pantheon. His instructions were something to the effect of "Download the repositories from Pantheon, install Drupal, and point Drupal to the repositories" Yeah... I downloaded the stuff from pantheon using Git, so I think I at least did that part right, but I have no idea how to install Drupal. I have read half a dozen different manuals, all of which tell me to do different things, most of which I don't understand. And our web designer can't help me because he doesn't know how to do any of this on a Windows box. (He's a Linux guy). Help??

I'm using Windows 7 Ultimate.

# Answer
> 0 votes
To install Drupal on an existing Pantheon site you don't need to install or copy anything to your local computer; you can just work on the Pantheon development environment in the cloud using the dashboard workflow. Pantheon hosts three distinct environments for each site: development, testing, and the live production site. You can install Drupal plus modules and themes on your development site. Once you're satisfied with the results, you can push your site code to the test environment for user testing and then to the live environment to serve the site from your domain, once you've launched with a paid site. The workflow tools let you push code from dev-\>test-\>live, and also clone your database and files between environments. Typically you'll install Drupal and configure the modules on the development environment before launching the site, then clone that database up to live to retain all the content changes. However, post-launch you would only want to copy the live database and files down to development and testing environments, as the live production environment is the canonical source of site content. You'll want to review Pantheon docs for how to use the workflow, both pre-launch and post-launch:

https://pantheon.io/docs/articles/getting-started/

---
Tags: installation
---


# Question
Title: How do I call the menu_rebuild function in Drupal 7?
I would like to call the menu\_rebuild() function, but I am not sure of where exactly paste the code snippet.

I can't find the update.php file anywhere in my local instance.

The reason I would like to attempt this is that I deleted all the nodes, but they are still appearing under the menu structure.

# Answer
Create a file with the following content and simply drop in the Drupal root directory. Let's say `menu-rebuild.php`. Run it http://example.com/menu-rebuild.php

```
<?php
error_reporting(E_ALL);
define('DRUPAL_ROOT', getcwd());
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

menu_rebuild();

```
> 5 votes

# Answer
**Drupal 7**

If you're using drush, you may run:

```
drush eval 'menu_rebuild();'

```

If won't work, see: How to do menu rebuild when having PHP Fatal error?

**Drupal 6**

```
drush php-eval 'drupal_rebuild_theme_registry()'

```

**memcached**

If you're using memcached, you've to restart it.

On Linux: `/etc/init.d/memcached restart`

On OS X (if using Homebrew): `brew services restart memcached`
> 15 votes

# Answer
Open the database schema, then delete all contents of menu\_links and menu\_router tables with the following SQL queries:

```
DELETE FROM menu_links;
DELETE FROM menu_router;

```

Then run http://example.com/update.php. It will call menu\_rebuild(), which will populate these tables with 'fresh' data. It worked for me after a "PHP Fatal Error: Out of memory" turned some of my menus into a mess.

But be aware, that it will wipe out all you custom menus which you will have to rebuild manually. To avoid it you may play a bit with deleting of some selected records from menu\_router and menu\_links, but for me it didn't work well.

And don't forget to back-up your database and site directory before deleting contents from the tables.
> 12 votes

# Answer
A couple of different ways:

1. Call `menu_rebuild()` from hook\_update\_N
2. Edit and save a menu settings form from Drupal admin.
3. From the command line, with drush: `drush cc menu`
> 3 votes

# Answer
Going to `admin/config/development/performance` and clicking on the "Clear all caches" button will cause the menu to be rebuilt, as well as clear template, block, page, etc. cache.
> 2 votes

# Answer
Alternative way is to set variable:

`variable_set('menu_rebuild_needed', TRUE);`

This will trigger the `menu_rebuild();`
> 2 votes

# Answer
To fix the admin menu use in SQL and note that as Valk stated above it will remove all customization from your administration management menu. After you run it clear your cache adn the management menu will be rebuilt to its default settings.

Here is the SQL query:

```
DELETE FROM menu_links WHERE menu_name='management'

```
> 0 votes

---
Tags: routes, updating
---


title: Print current drupal menu level

text:
# Question
Title: Print current drupal menu level
Hitting my head against the wall here. I've volunteered to print a list of the current menu items (at the same level as the currently viewed menu)

```
print theme('links', $secondary_links, array('class' => 'links', 'id' => 'subnav'));

```

Does anyone know how I would print out a list of the menu items at the currently selected level rather than just the top level primary links?

**Update:** Also just prints the children of the primary link parent.

```
      print theme('links', $primary_links, array('class' => 'links'))

```

# Answer
print theme("links", array('links'=\>$secondary\_links), array('class' =\> 'links', 'id' =\> 'subnav'));
> 0 votes

---
Tags: 6, routes, navigation
---


# Question
Title: Group audience versus group content visibility
Can someone explain me what is the difference between group audience and group content visibility?

# Answer
The basic concept is if you don't have any access control on the content specifically then the content would inherit the groups access control. But say you had a private group that you wanted some content visible (but not all) then the access control for the content could be set to allow that to happen.

You can read more in the docs here: Content visibility: https://www.drupal.org/node/2014755 Group visibility: https://www.drupal.org/node/2014751

There are even some pretty diagrams listed in the content for more help visualizing these concepts.
> 0 votes

---
Tags: organic-groups
---


# Question
Title: Field widget item form alter for file field
I want to alter field widget item form of a file field with `cardinality > 1` so that a new form element is added to each row of the file tables. For example, in the attached image, I want to add another text field below the "Description" for each uploaded file, even the one done via Ajax, not just the existing ones. I used `hook_field_widget_form_alter()` but it doesn't seem to work with the newly uploaded file. Any ideas?

# Answer
> 0 votes
A lot of the build logic for the file field widgets is handled in #process callbacks, so some detailed structures of each individual file's form element aren't really available during `hook_form_alter()`s.

You might want to preprocess the individual elements with `hook_preprocess_file_widget()`. Something like:

```
/**
 * Implements hook_preprocess_file_widget().
 */
function MYMODULE_preprocess_file_widget(&$vars) {
  // Make some alterations to normal file-field widgets.
  $element = &$vars['element'];
  if (isset($element['#file']) && is_object($element['#file'])) {
    // This is an existing file... alter $element accordingly.
  }
  else {
    // This is the actual upload widget... you may want to skip this or alter
    // it in a special way.
  }
}

```

You could also use `hook_preprocess_file_widget_multiple()` to specifically target a group of files in a file field that has cardinality \> 1. In this case you may need to have some iteration logic to loop through the children elements with `element_children()`.

---
Tags: entities, files
---


title: Did I set up memache correctly?

text:
# Question
Title: Did I set up memache correctly?
I have applied memcache by via instructions from this page to our production server. The difference in numbers don't look stellar.

My question: **Did I configure memcache improperly? Can I increase the `CACHESIZE` to perhaps get a better overall performance?**

**Settings.php**

In settings.php, I've included this bit of text as recommend by the README.txt inside the memcache module.

```
/**************************************************
 * MEMCACHE
 **************************************************/
$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
$conf['lock_inc'] = 'sites/all/modules/memcache/memcache-lock.inc';
$conf['memcache_stampede_protection'] = TRUE;
$conf['cache_default_class'] = 'MemCacheDrupal';

// The 'cache_form' bin must be assigned to non-volatile storage.
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';

// Don't bootstrap the database when serving pages from the cache.
$conf['page_cache_without_database'] = TRUE;
$conf['page_cache_invoke_hooks'] = FALSE;

$conf['memcache_servers'] = array('server:11211' => 'default');

```

**Memcache Conf**

The memcache system conf has been left it's default:

```
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""

```

**Benchmarks**

I ran a battery of apache benchmark tests and these are the numbers

*With* memcache active

```
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1    1   0.4      1       4
Processing:     4   50   8.6     52      62
Waiting:        4   50   8.6     52      62
Total:          7   51   8.2     53      63

```

Without / Before / Baseline

```
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1    1   0.5      1       4
Processing:     3   50   8.4     52      61
Waiting:        3   50   8.4     52      60
Total:          7   51   7.9     53      62

```

# Answer
> 0 votes
I did end up increasing the RAM in the conf file. Since I've noticed no evictions. In fact the eviction stat is at 0 at the moment.

---
Tags: 7, caching
---


# Question
Title: How to access an external MySQL database in a view if SQLite support is not installed?
I would like to display other MySQL database by Views, and having the similar situation as this question. Except, I'm not able to enable the "SQLite", because I have no control on the server end. While adding the data block on New Forena Report, I got the message "***PDO driver support for sqlite not installed***", as shown in the screenprint below:

**My question**: Is it possible to display other MySQL data by Views without installing and enabling support for SQLite? What are my other options?

**===== Updated June 6, 2015 at 12:45pm - Data block format ====**
Below are the screenshots where I fix the Data Block format for data column with double quote.

*screenshot 1 - While you edit the Forena Reports, you actually can configure each column(block) by left click the gear as screenshot from blow.*

*screenshot 2 - Choosing the "drupal\_text\_format" format will remove double quotes*

# Answer
The Forena module is shipped with 3 types of "sample" reports:

* Reports about your **own Drupal database** (the drupal/\* 'data blocks' in your screenprint), typically in **MySQL** database format.
* **Forena tutorials**, which are actually also delivered in the format of "Reports" which refer to datablocks in **XML** format (the forena\_help/\* 'data blocks' in your screenprint).
* Reports about some **Sample** database which is also delivered with Forena, in the format of an **SQLite** database (none of these Sample/\* 'data blocks' are shown in your screenprint, as they are normally shown when PDO driver support for SQLite is available).

So the error shown in your screenprint is to inform you about something like "sorry, there is no SQLite support available here, so I can't handle the Sample database (which is in SQLite format)".

If however you have MySQL support available on the server where your MySQL data resides (eg: if it's on the same server as where Drupal resides, but just another MySQL database), then you should be able to use Forena for creating reports about that MySQL database. To access that MySQL database, you need to define (within Forena admin) a Data Connection to that MySQL database and 1 or more data blocks (SQL queries). And from then on you should be able to build your custom reports about that MySQL database, e.g. using the WYSIWYG report writer that comes with Forena.

**Note**: if you're interested in trying out Forena, use SimplyTest.Me to do so. If you do, and after you login to such site, you'll also get the same ***PDO driver support for sqlite not installed*** error message, after you visit the "`/reports`" link for the first time (or use the "My Reports" menu option in the Navigation menu). That error is shown because support for SQLite is not enabled on SimplyTest.Me. You get a similar error message if you visit the `reports/sample.toc` link (because the sample reports and graphs are using an SQLite database). However, reports such as these run just fine (they don't require SQLite):

* `/reports/help.toc`.
* `/reports/drupaladmin.enabled_contributions` (by the way: shows all enabled modules in such simplytest.me setup ...).
> 1 votes

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


# Question
Title: Programmatically get menu block & alter classes
I'm invoking a menu block programmatically using: module\_invoke('menu\_block', 'block\_view', 13);

What I want to do is change and add classes to the wrapper & ul tags of the menu block, is this possible? I can't seem to find a class\_array to add & have spent a significant amount of time looking through documentation & online but not come up with a solution.

# Answer
borrowed from here:

add the following code in your template.php file.

```
<?php
  function THEME_menu_tree__main_menu($variables) {
    return '<ul class="nav navbar-nav navbar-right">' . $variables['tree'] . '</ul>';
  }
?>

```

this would update the `<ul>` for main menu, adjust as necessary. You can adjust further up the chain within the page.tpl.php file.
> 0 votes

---
Tags: 7, blocks
---


title: outputting image from custom module

text:
# Question
Title: outputting image from custom module
I am writing a custom module that will output an image on the page. I believe that I should have this image in my module folder and not rely on that image being in the site files. I'm not sure how to reference that image to produce the img tag. mymodule -/mymodule.info -/mymodule.module -/files -/files/myimage.png

I want to be able to render the image so that the source is displayed with an img tag:

# Answer
For outputing image, you should use `theme` function, with `image` theming. And path argument inside.

For example:

```
$img = theme('image', array('path' => "path to image"));
// $img will containt the image tag.
// path can be relative from drupal root, or it can be 'files' path (public://image.jpg)

```

Read more about it, you can here: https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme\_image/7

The power of Drupal in overwriting, so I suggest you to use `theme` way.
> 2 votes

# Answer
you can get the path for the current module with:

```
<?php
  drupal_get_path('module', 'my_module');
?>

```

so you can output with something like:

```
<img src="<?php print drupal_get_path('module', 'my_module') . '/images/image.jpg' ?>">

```

you obviously want to adjust the path and name (this example having a sub folder 'images' within the module folder), but that gives you an idea
> 0 votes

---
Tags: media
---


# Question
Title: How do I add to $page_top in html.tpl.php?
I wanted to add a piece of HTML at the top of all pages, right after `<body>`. In the #drupal IRC channel I got the recommendation to override `html.tpl.php` in the theme. That works fine. But isn't there some useful hook that I could use, so I don't have to copy `html.tpl.php` and just add a few lines?

I tried to modify `$variables['page']['page_top']` in `THEME_preprocess_page()` and `THEME_preprocess_html()` but upon debugging `$page_top` in `html.tpl.php`, the changes had been discarded.

How do I do it by hook? And which way is to prefer?

# Answer
> 1 votes
Have a look at how the Drupal core toolbar module does this:

```
/**
 * Implements hook_page_build().
 *
 * Add admin toolbar to the page_top region automatically.
 */
function toolbar_page_build(&$page) {
  $page['page_top']['toolbar'] = array(
    '#pre_render' => array('toolbar_pre_render'),
    '#access' => user_access('access toolbar'),
    'toolbar_drawer' => array(),
  );
}

```

This is probably the most correct way of adding something to the page top as you can comfortably use render arrays.

# Answer
> 0 votes
$page\_top is rendered in template\_process\_html(). You should be able to override that function to add material before it is rendered and assigned to $variable

# Answer
> 0 votes
You can add region page\_top in your\_theme.info file, see reference Writing theme .info files
The other way is to change html.tpl.php file in your theme, but the first way is better.

---
Tags: 7, hooks, theming
---


# Question
Title: Drupal 7 Display a list of reference node in node being display
I am new to Drupal 7.

I have two content types, they are 'school' and 'course'. In course content type, I used Reference module to create a field that reference to school (a school have many courses, and a course is belong to one school only).

And now what I want is, when I view a specific school info, the list of courses that belong to the school also be displayed beneath.

How can I do that in drupal 7 ? :D Thank you in advance!

# Answer
You need to create a view of contents filter by `Course` content type. Now I assume you have a field name `field_school`.

Add this field in `Contextual Filter` and select default argument `Content ID from URL`.

When this block will be added on node page, it will automatically filters the `courses` of that school. Otherwise pass the school id as argument to view. :)

Here is the screenshot :
> 1 votes

---
Tags: nodes
---


# Question
Title: Ctools Custom Content Type Plugin with Image Field
I was wondering if anyone has been successful with incorporating an Image field `'type'=>'managed_file'` into a ctools plugin. I created a custom ctools plugin but am having some difficulty with the image field as I am getting an error upon upload. After some searching, it seems like this error could be caused from a file that isn't being included when the form is rebuilt after the ajax request. I've attempted to use the `form_load_include` to include the `DRUPAL_ROOT/modules/file/file.field.inc` file, and it is being loaded with the form, but I am still receiving this error:

> Notice: Undefined index: content\_image\_pane\_edit\_form in drupal\_retrieve\_form() (line 763 of /htdocs/development/includes/form.inc).
>
> Warning: call\_user\_func\_array() \[function.call-user-func-array\]: First argument is expected to be a valid callback, 'content\_image\_pane\_edit\_form' was given in drupal\_retrieve\_form() (line 798 of /htdocs/development/includes/form.inc).
>
> Notice: Undefined index: pane\_image in file\_ajax\_upload() (line 271 of /htdocs/development/modules/file/file.module).
>
> Notice: Undefined index: #suffix in file\_ajax\_upload() (line 280 of /htdocs/development/modules/file/file.module).

Here is my settings for my Custom Content Type Ctools Plugin:

```
/*Plugin definition*/
$plugin = array(
  'single' => TRUE,
  'title' => t('Custom: Content Image Pane'),
  'description' => t('This is a custom pane containing a title, textarea and image field.'),
  'category' => t('Custom Panes'),
  'edit form' => 'content_image_pane_edit_form',
  'render callback' => 'content_image_pane_render',
  'admin info' => 'content_image_pane_admin_info',
  'defaults' => array(
    'pane_image' => '',
    'pane_content' => '',
  )
);
/**
 * 'Edit form' callback for the content type.
 */
function content_image_pane_edit_form($form, &$form_state) {

  $form['#attributes']['enctype'] = array("multipart/form-data");

  form_load_include($form_state, 'inc', 'file', 'file.field');

  $conf = $form_state['conf'];

   $form['pane_image'] = array(
    '#title' => t('Image'),
    '#type' => 'managed_file',
    '#description' => t('Upload an Image that is associated with this content.'),
    '#default_value' => '',
    //'#default_value' => !empty($conf['pane_image']) ? variable_get($conf['pane_image']) : '',
    '#upload_location' => 'public://panes/',
    '#upload_validators' => array(
       'file_validate_extensions' => array('gif png jpeg jpg')
     ),
    '#array_parents' => array('pane_image')
  );

  $form['pane_content'] = array(
    '#title' => t('Content'),
    '#type' => 'text_format',
    '#format' => 'full_html',
    '#description' => t('Please enter the content for the custom pane here.'),
    '#default_value' => $conf['pane_content']['value'],
    '#cols' => 40,
    '#rows' => 6,
    '#resizable' => TRUE,
    '#required' => TRUE,
  );
  return $form;
}

```

If anyone could point me in the right direction for an answer to this that would be outstanding!

# Answer
You should try to put this line:

```
form_load_include($form_state, 'inc', 'my_module','plugins/content_types/my_file');

```

at the top of your content\_image\_pane\_edit\_form function, replacing my\_module and my\_file with your module and plugin include file.

Ctools panes are generated in a separate modal from base Drupal forms and so when the AJAX reloads the form it cannot find the original form function. By forcing Drupal to include the full form code each time it is processed, the AJAX will be able to find the necessary function to rebuild the form.

*Tested working with Drupal 7 & panes on a production site.*
> 6 votes

# Answer
If you still get the same error message, try move the form function into .module file.
> 1 votes

---
Tags: chaos-tool-suite, files
---


# Question
Title: How to change the positioning of Drupal blocks when a theme is enabled?
I am developing a Drupal 7 theme. I want to change the position of the blocks when a user set my theme as default.

In my theme the main menu is positioned in left sidebar. Suppose the current theme of the user has main menu in the header block, when a user enables my theme, the main menu should go to the left sidebar.

Basically I want to position the block using code when my theme is set as default.

Any way to implement this?

# Answer
# Only using Drupal core

Investigate the 'current theme of the user', to identify the 'region name' where the 'header block' (which contains the main menu) is positioned. Let's say that region is called "HeaderRegion".

Then in your own theme, make sure to create a region with the exact same name (like "HeaderRegion"), and position that region in the area that corresponds with what you describe as "left sidebar".

With this approach, the "main menu" will be shown in both themes in the block that is positioned in the "HeaderRegion"-region. And the actual theme that is selected will determine if it will be shown in the header (if using the current theme) or in the left sidebar (if using your own theme). Note: a "left sidebar" with a region name like "HeaderRegion" will sound a bit confusing, but that's a way to make it work ... (and maybe that region name in your current theme has a less confusing name, so you might be lucky and not suffer that confusion ...).

# Using a contributed module

By using the Themekey module, you can implement content, user, or role -specific themes.

So if you can come up with the appropriate set of theme variations (which would differ by the location of your theme regions in which the blocks are displayed), this could be a solution that could work.
> 0 votes

---
Tags: 7, theming, blocks
---


# Question
Title: Prompt registration based on number of free articles read
When an anonymous user reads 3 free articles, the system should prompt them that they have reach the limit of free articles, and they now need to register to read more. How can i achieve this. I have just started writing modules. Any help would be beneficial. Thanks in advance

# Answer
> 0 votes
Well, I think you need to use `session` and hook\_node\_view to achieve this. You need to add a logic and set/check session on `hook_node_view` for Anonymous user.

There are modules to restrict number of node creation but not on node view. You can contribute one or use custom module. :)

# Answer
> 0 votes
It seems you're looking for the Node Access module

> Nodeaccess is a Drupal access control module which provides view, edit and delete access to nodes. Users with the 'grant node permissions' permission will have a grant tab on node pages which allows them to grant access to that node by user or role. Administrators can set default access controls per content type, and also define which roles are available to grant permissions to on the node grants tab.

Image from module page

---
Tags: 7, users
---


title: Views Question - Related Taxonomy Terms

text:
# Question
Title: Views Question - Related Taxonomy Terms
I'm a Drupal noob, so this may be a simple question. I have two taxonomies created, one called Programs and another called Divisions. There is a "Division" field in the "Program" taxonomy. For example:

**Programs**

* Math
* English
* Art
* Communication
* Biology

**Divisions**

* Humanities
* Science

Art, English, and Communication are all related to Humanities Math and Biology are related to Science

I have used Views to build a page that will display information for each program. URL format is academics/programs/biology, academics/programs/art, etc.

I'm trying to create a Views pane that will display related programs, but I'm having some difficulty. Essentially, I want it to a display a list of programs that have the same Division. How would I go about accomplishing this since the URL does not have the Division term in it, but rather the Program term?

Any help would be appreciated.

Thanks!

# Answer
> 0 votes
If you put the hierarchical structure into the path you could use a contextual filter to show the related programs in a view. The path would look like: programs/humanities/English

The contextual filter would look at the taxonomy term in position 2 and show related programs (other humanities programs in this example)

# Answer
> 0 votes
Instead of using taxonomy term as the field in programs rather use entity reference with taxonomy term and bundle divisions.

I also installed Views arguments in filters in order to get rid of listing the program in the second view. You can omit this if it is not a requirement.

Then set up your second view as follows (note I just used an attachment but you can alter as you like):

**View**: showing taxonomy terms filtered by Programs

**Contextual filter**: global null, default value = Taxonomy term ID from URL, Validator = Taxonomy term of Vocabulary Programs and Field filter type = Term name

**Relationships:**

**Relationship 1**: A bridge to the Taxonomy term entity that is referenced via field\_division

**Relationship 2**: A bridge to the Taxonomy term entity that is referencing Taxonomy term via field\_division, ans set its relationship to relationship 1

**Fields**:

Taxonomy term fields with the relationship set to relationship 2

**Filter criteria:**

**Taxonomy vocabulary:** machine name = Programs

**Term Name:** set the value to =%1 (picked up from global null via views arguments in filters

**Term Name:** set the value to !=%1 and add relationship 2.

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


# Question
Title: How to add PHP to a node without php filter?
I have a one-off page on my site (webcam), where i need to run some php to eg. calculate today's sunrise time, add a daylight image at night, etc.

I understand PHP Filter is a security risk, and not recommended if it can be avoided.

My page is actually a panesl page, so not neccessarly a node.

I thought maybe i could do the coding and (some) content in a node template, or what other options do i have? A module? Sounds heavy... In my theme's php? What are pro's and con's?

# Answer
> 0 votes
It really depends since you're planning to add functionality then the best place would be a module but if you're altering HTML or basically the output and maybe quite a little raw data manipulations then that could be in your theme.

Mostly a basic question that needs to be asked is, do you want the "thing" to be functional when you turn off or change your theme? If yes then that would give a strong idea that you would be creating a custom module.

For adding PHP code with panels, you can create custom panel panes. For nodes, your can use blocks or hook\_preprocess\_node() to add your code in the node level.

---
Tags: nodes
---


title: Template hierarchy like Wordpress

text:
# Question
Title: Template hierarchy like Wordpress
I am new to Drupal. Is there any template hierarchy structure to output different section of durpla like node, page, vocabulary, block etc. If so how can we use that.

E.g. In WordPress we have a template hierarchy to output page, posts, category, custom post etc.

# Answer
Yes, Drupal has a modular, hierarchical template system. Each of the components you mentioned can be themed individually. The main html template includes the page template, which includes other templates, that include other templates, and on it goes.

See About overriding themable output for the how/what/why.
> 3 votes

---
Tags: 7
---


# Question
Title: How to relate a field to another field in content type like a foregn key?
Can anyone guide my to the best method or module to connect 2 fields together? I want to create a field called (Author) in a content type book, which will refer to a field called (name) in a content type author.

So a book author, will refer to field name of an actual existing author.

It's like creating a foreign key from the a book field to the author author field.

But the modules that I found (like node relation, relation and entity reference) only do a node reference, which is not what I want.

Not sure if I did use the modules correctly. But am I missing something here?

I am kind of new to Drupal as well as the web development era.

Any help?

# Answer
> 1 votes
Instead of using relationships use field collection module. In this module you may create a collection of fields that they all point to an entity.

As an example you can create author collection and in this collection insert first name field,last name field,gender field or any other information you need.

You can add this collection as a field to the book content type.

# Answer
> 1 votes
Just wanted to say welcome to Drupal! :)

The Entity Reference module is what could help you. I think you're on the right track already.

The setup would be: Content type: Book \- Author field (references the Author content type)

Since you're talking about foreign keys, the Entity Reference module does exactly that. In Drupal, it refers to the content using the foreign key(Node ID/Entity ID).

**UPDATED**

> does entity ID mean the field reference in that node??

Yes, it does mean that.

For doing deeper on the field level problem. *I haven't seen any module for that so far* but my solution would be for somewhat for aesthetics only. Use the Book Author's name as the content type's title(You can change this label to like "Author Name"). So when you search authors in the entity reference field, you would be searching for the author's name.

Second option, if you don't want to use the title field of the Book Author content type but with this path I don't know what value you'll place there if you have a field called name would be to alter the autocomplete path of your Book content type's node reference field to use the field\_name or any other deeper fields of the Book Author content type using form api's `'#autocomplete_path'`. So that when you search for an author, it won't match with the node title.

These solutions basically let's the user perceive that your doing a direct foreign key but it's, it still references the node id.

Hope I've helped with my explanation. :)

---
Tags: entities, nodes
---


# Question
Title: How do I add a new condition in Rules 2?
I can't get my new Rules' condition to work.

I wrote the (simple) code below in includes/MYMODULE.rules.inc, and nothing appears in the condition list.

```
/**
 * Implementation of hook_rules_condition_info().
 */
function MYMODULE_rules_condition_info() {
    return array(
        'MYMODULE_rules_condition_MYCONDITION' => array(
            'label' => t('My label'),
            'group' => 'My very own group',
        )
    );
}

/**
 * Condition
 */
function MYMODULE_rules_condition_MYCONDITION() {
    // logic
    return TRUE;
}

```

I have already tried to flush the Drupal cache (as it seems to me that Rules uses a cache system).

# Answer
> 1 votes
Read Rules 2.x / Drupal 7; I think you can find what you want, there.

# Answer
> 1 votes
Custom Rules condition:

```
/**
 * Implements of hook_rules_condition_info().
 */
function your_module_rules_condition_info() {
  return array(
    'your_module_condition_package_type' => array(
      'label' => t('Type of the package'),
      'arguments' => array(
        'package_id' => array('type' => 'value', 'label' => t('The type of the purchased package.')),
        'package_type' => array('type' => 'string', 'label' => t('The type of the purchased package is')),
      ),
      'module' => 'your_module',
      'group' => 'My very own group',
    ),
  );
}
/**
 * Condition packages_condition_packagetype
 */
function your_module_condition_package_type($pid, $type) {
  $package = package_load($pid);
  return ($package->type == $type) ? true : false;
}

```

See more in Rules examples

---
Tags: 7, rules
---


# Question
Title: Create a Ubercart Drupal site to sell memberships?
I want to create a website to sell licenses (not software licenses).
Basically, these licenses are sold in the form of packages for, say, package of 1 license or package of 2 licenses.
If a user comes to the site and buys a package with `n` number of licenses then `n` number of Drupal users will be created.

The created users can have different role types to allow different content to be accessible for different users.

Is it possible to achieve that with some Drupal 7 modules?

I did some research and found that it is possible to sell roles/subscriptions using the *Ubercart* module but I don't know how to create users that way -- with different roles after buying license package(s).

# Answer
> 0 votes
I was also trying to do this fairly recently. Found a nice tutorial on Site Membership and Ubercart from Torontowebsitedeveloper.

https://www.youtube.com/watch?v=vbeqlNjBvwQ

---
Tags: 7, ubercart
---


# Question
Title: How to assigned specific "comment" view mode for specific "node" view mode?
In "Article" content type i have three view mode in "Manage Display" namely "teaser", "default" and "abc".

Similary in "Comment Display" i have two view mode namely "defalut" and "xyz".

Eg: When i see "abc" node page where i am listing comments, that time the comment should be display with my "xyz" view mode not the "default" one.

function custom\_node\_view($node) { return node\_view($node, 'abc'); }

# Answer
You could use hook\_entity\_view\_mode\_alter() to switch it on the fly.
> 0 votes

---
Tags: nodes, hooks, comments
---


# Question
Title: Is there a module to translate blocks and pages with language modules?
I am working on drupal 7, and I want to translate each Block/Pages/Node to multiple language.

Is there any module available that will provide facility language tabs to enter language specific content and save?

```
[<English>]  [Spanish]
|---------------------------------|
| Lorem Ipsum                     |
|                                 |
|---------------------------------|

<Save Content>

```

I have tried following modules:

It only works on Plain/Text format to translate, I need module which allows me to support all Format to translate content in Block/Page/Node, etc.

# Answer
# Block languages submodule of i18n

Submodule `i18n_block`, included in the i18n module, could be what you're looking for ... or at least address part of your question.

Some more details about it:

> This module provides support for multilingual blocks.
>
> You can set up a language for a block or define it as translatable:
>
> * Blocks with a language will be displayed only in pages with that language.
> * Translatable blocks can be translated using the localization interface.

# Bean module

Consider looking at the BEAN module also. It offers all sorts of enhancements as compared to the (old fashioned) blocks. And possibly you may want to combine it with modules such as Entity Translation to achieve your goal.

The video tutorial Drupal Bean module tutorial - using Bean Admin UI provides a great introduction to really understand the power of the BEAN module, and the kind of things you can do with it (by only using site building techniques, no custom coding involved). It also shows how the Bean module transforms Drupal blocks into fieldable entities.

# Managing translations

To actually "manage translations", there are a few typical modules like these (quotes from their project pages, with some bold markup added here):

> ... provides a tool set for translating content from different sources. The translation can be done by people or translation services of all kinds. It builds on and uses existing language tools and data structures in Drupal and can be used in automated workflow scenarios.
>
> This module does not make i18n or any other language module for Drupal obsolete. It does only facilitate the translation process.

This module seems already well ported to Drupal 8 also, so much that it is already recommended as a successor of the Translation Overview module (which is about translations of nodes), which also refers to the Translation Table module (which is about translations of taxonomy terms and menu items).

> ... provides complete workflow management for multilingual Drupal sites.
>
> Content managers can manage all translations from one central page. The module shows which contents need translation and notifies translators about what they need to do.
>
> ... The module introduces a new Translator role. This role allows translating between specific language pairs. Translators have individual job queues, showing documents that were sent to them for translation.
>
> ... Translators can translate everything without having to learn Drupal administration. **Node contents**, menus, taxonomy, CCK, **blocks** and strings are all translated from the same interface.

Note: even though there is no D7 version (yet), there are quite a few D7 related issues (and there is a GIT branch for D7 also). And there is the Drupal-Translation.com website with tons of interesting documentation.

# Interface translations

The **translation of the interface** is about the translation of various text strings used throughout the site, like labels used on buttons such as submit, or on tabs such as view or edit. They are the same on all sites (no matter what actual content is contained in a site).

To manage these kinds of translations, there is the Localization update module.

# More translation modules

Translations in Drupal is fun, here are a few more to finish:
> 5 votes

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


title: Zen theme not writing source maps

text:
# Question
Title: Zen theme not writing source maps
I have made a subtheme of zen and started making some changes to it's SASS files. However now I have some layouts that aren't working as I expected, so I went to the chrome devtools, but that only tells me what CSS file the particular thing is in.

What I want is what SASS file it is in. Now, when I read the config.rb file it says it has some support for FireSass, but that plugin has been removed by the author, so no luck there.

I do have the environment set to :development and the firesass = true, therefore the sass\_options :debug\_info =\> true.

So I go to the root in the theme file /sites/all/themes/mytheme and run compass watch, but there are never any source maps.

# Answer
> 0 votes
I think this issue: https://www.drupal.org/node/2295227 addresses your question.

Though haven't tried it myself, but the current dev-version of Zen should contain the 'fix' (i.e., using FireCompass instead of FireSass) to debug SASS-code in an easy way.

# Answer
> 0 votes
I had to give the sass\_options en extra element { :sourcemaps =\> true } this solves the problem. A demo about how to do just that can be found here: http://cgit.drupalcode.org/zen/tree/STARTERKIT/config.rb?id=8ffd0ac18b51b7a01f2c6019882adb1cb044b340

Don't know why this isn't in Zen 5.5 though.

# Answer
> 0 votes
Try updating Compass, best way is to just update your ruby gems, worked for me.

```
gem update

```

---
Tags: theming
---


# Question
Title: Drupal-git-sandbox project: commits are shown but no new revision
I don't know why I have no new revision, what I do: I change my code locally, then:

```
git add -A
git commit -m "bla"
git push -u origin 7.x-1.x

```

Result:

A new commit is shown in my sandbox repository on drupal.org. But I need a new revision too! I'm new to git, so can anybody explain what I misunderstand?

# Answer
Sandboxes on Drupal.org can't have releases (tagged revisions).

For a *full project*, if you want to push a specific release/revision, rather than just a SHA-identified commit, you create a tag locally before you push a tagged release.

```
git commit -am "Revision 7.x-1.0"
git tag 7.x-1.0
git push origin tag 7.x-1.0

```
> 1 votes

---
Tags: version-control, community-official-site
---


# Question
Title: How to add country phone number prefix in webform?
I have a webform, with a field for phone number.

I would like to have another select dropdown field before phone number, with country name and country phone number prefix.

Eg:
Singapore (65)
United Kingdom (44)
Venezuela (58)

# Answer
Webform allows you to load options in bulk. Just google for this list and load it into a spreadsheet. Use a bit of find/replace to get it into the format needed by a webform select element, which is:

```
65|Singapore (65)
44|United Kingdom (44)
58|Venezuela (58)

```

Then create a webform select field and paste it in.

To get the fields to line up side-by-side (with country code right before phone number and not on a separate line) use the webform\_layout module.
> 1 votes

---
Tags: 7, webforms
---


title: Find out who updated Drupal modules

text:
# Question
Title: Find out who updated Drupal modules
Someone updated modules in my Drupal install 5 days ago, and I would like to find out who.

I looked in Reports \> Recent log messages, but this is filled up with so many php warnings that it only goes back 1 day.

I also tried searching for "update" in the watchdog table, but couldn't find any entries for the date I was interested in.

# Answer
I think you'll find details in the Watchdog if the updates were performed using the UI.

If the modules were updated using a different method, e.g. Drush or manually, then you'll need to turn to your server logs, assuming that you keep logs for such actions. Drupal won't hold any data about those actions, as it wouldn't even necessarily know they had occurred.

Just to clear things up, the "Recent log messages" report gets its data from the watchdog table, so you're looking in the same place for both.
> 3 votes

# Answer
One of the challenges with recent log messages (watchdog), is that there might be quite a few PHP notices, warnings, and errors that are filling up your logs. So a good practice is to identify / address these problems in your site (which will reduce the required resources for your site also and will result in a faster site).

However digesting these messages is quite a challenge. That's why I've come up with my own "custom" reports, as illustrated also.

Within the "Report Execution Parameters" (collapsed in the screenprint above), I specify the search criteria of the log messages to be retrieved (like severity, User name, etc). And the red numbers are hyperlinks to get a drill down report of the specific messages for which I want more details (= to display the actual watchdog entries). I wonder if it is worth publishing these kind of reports in a contributed module (something like a ***Watchdog Dashboard***)?

Refer to my answer to "How to gets analyts and generate visual reports from sessions?" for more details about reports as in the above screenprint.

Some other modules that I've been looking at recently, in the context of Watchdog processing (one of them suggested also in Clive's comment):
> 0 votes

---
Tags: updating
---


# Question
Title: Is there a way to have a language neutral link that automatically redirects to the user's active language?
We have a multilingual Drupal 7 site, and after turning on the first translation, we realized that one of the third party modules we're using, a slider module (comes with Eventus theme, it's a module the vendor built (or perhaps bought and extended/branded)). The slider module is not multilingual aware and it is routing all users to the same URL (which sends them back to the default language), regardless of the active language.

We're evaluating our options to address this, and one idea (that I am unsure if it is possible) is to make the slider links go to a "language neutral" URL, which will then forward them on to the user's currently active language for any given URL. However, so far I haven't been able to figure out A) if this is possible and B) if it is possible, how to construct the URL. So, is it possible, and if so, how would I set this up? Open to suggestions.

The slider module's content is currently identical for all language versions of the site.

To try and clarify, I'm going to use example the following example URLs:

/about -- this is the default, primary language (english) version of the "about" page /pt-br/sobre -- this is the translated, Português version of the "about"

The first "slide" in the slider says "Learn more about us!" and links to the /about.

Our goal is to make Drupal aware of the user's current language setting, and if they click on a link that sends them to /about, but their language is currently set to Português, it will automatically redirect them (or at least provide them) with the Português version of the "about" page.

Is this possible, and/or is there a better way to accomplish this?

# Answer
> 0 votes
I'm not familiar with the "slider" module. But from the example URLs you added, it seems to me that at least you should check your configuration at *Configuration -\> Languages -\> detection and selection*: the order specified there should be 'URL, Default, User', and not something like 'Default, URL, User'. It could well be that that is all that's needed here ...

Curious to hear what the result of checking this will be ...

---
Tags: i18n-l10n
---


# Question
Title: Is it possible to group taxonomy list items by content type?
I'm working on a website which uses a single vocabulary for three different content types. I'm looking for a way to group list items by content type.

To illustrate, I got three content types:

* Manual
* News
* Blog

And I got lots of vocabulary terms which might be used by all three content types:

* Rabbits
* Cats
* Dogs
* Frogs

When I select a vocabulary term it will show all the relevant content, sorted by the publication date, like so:

### Rabbits

* Rabbit escaped from show-ground
* Feeding your rabbit
* Why do rabbits have such big ears?

However, I'd like to group the items by content type:

## Rabbits

### Manual

* Feeding your rabbit

### News

* Rabbit escaped from show-ground

### Blog

* Why do rabbits have such big ears?

I've tried the default 'Taxonomy term' view but found it wouldn't quite work because it affect other vocabularies as well. I also tried the Taxonomy Display module but didn't really understand how it works (I got some configuration options but no view I could change).

Is there a function that could check the vocabulary and the list items' content types and then group them by content type?

# Answer
> 1 votes
I assume you know how to set up the view and have difficulty only with applying the view to the specific taxonomy and letting other taxonomies render by default.

Create a custom module and put this is the main module file:

```
function MODULE_menu_alter(&$items){
  // change taxonomy view path for certain vocabularies
  $items['taxonomy/term/%taxonomy_term']['page arguments'][] = $items['taxonomy/term/%taxonomy_term']['page callback'];
  $items['taxonomy/term/%taxonomy_term']['page callback'] = 'custom_taxonomy_term_callback';
}

function custom_taxonomy_term_callback($term, $callback) {
  if ($term->vocabulary_machine_name == "SOME_TAXONOMY") {
    $view = views_get_view('CUSTOM_TERM_VIEW');
    $view->set_display('default');
    $view->set_arguments(array($term->tid));
    $view->pre_execute();
    $view->execute();
    return $view->render();
  }
  else {
    module_load_include('inc', 'taxonomy', 'taxonomy.pages');
    return $callback($term);
  }
}

```

This is what the code does:

It alters the path taxonomy is called on, then checks if the path is on your taxonomy that you want to special render. If it is it loads and renders the view for that taxonomy, and if not it passes the call back to the default taxonomy callback.

You need to alter the code to suit your taxonomy machine name and view name. And remember to clear the cache.

For your view you can create just the master view (ie no page with path) that accepts the tid as contextual filter. This view is custom rendered and therefore does not need to be on any path.

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


# Question
Title: Is there a way to use Translation Overview with Entity Translation?
When I use the Internationalization module with Translation Overview all works fine, I can see through `admin/content/translation-overview-manage` the state of the translations of nodes.

But when I use Entity Translation I can't see this information. I've been searching for some info on the net, but I can't find anything about this.

So, is there a way to use Translation Overview in combination with Entity Translation?

# Answer
Maybe you should consider switching from the Translation Overview module to the Translation Management Tool module, which allows all Drupal text elements to be used as source for translation. I.e. Nodes, Entities, I18n Strings (Menu, Terms etc.).

That's also what seems to comply with what is written on the Translation Overview project page, i.e.:

> ... The superseding Translation management (TMGMT) module was initiated with Drupal 7 and is already well ported to Drupal 8. We highly recommend it - already with Drupal 7.
> 2 votes

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


title: CTools CSS Cache Error on Status Page

text:
# Question
Title: CTools CSS Cache Error on Status Page
I'm getting this error on the Status report page.

Advice on resolving this?

# Answer
> 1 votes
The "files" directory of your installation (usually located at sites/default/files) must be writable by user the execute the server (Apache, for example).

So, if you have access to a console could try:

sudo chown -R www-data:www-data sites/default/files (for Ubuntu or Debian) sudo chown -R apache:apache sites/default/files (for Centos or Redhat)

---
Tags: caching
---


# Question
Title: Add a variable amount of time to a date field via rules
I'm trying to add a time duration field value (integer type representing seconds) to a date field using rules, but I'm not able to reference the duration field when it comes time to calculate/edit the date value (presumably because they are of different field types). I can do things like "+30 days", but really what I want to do is "+$x days".

# Answer
FYI I solved this by invoking a rules hook to change the field to duration. This solution was inspired by fago's commerce subscription products module.
> 1 votes

# Answer
The interval module provides an action "Apply an interval to a date" (you find it in the "data"-section of the action list). The module supplies a "interval field", but surprisingly, instead of providing integration between rules and that field, it provides that action, which provides integration between rules and an integer field. The action allows you to specify a data value and specify which interval that number is to be interpreted as (days, months, ...)
> 3 votes

# Answer
Thanks to rosell.dk for pointing out the Interval module. Just to expand on that:

First create 2 conditions to check if the 2 fields exist.

```
Entity has field:
  entity1:field_number_of_days (Integer)
Entity has field:
  entity2:field_date (Date)

```

Then you need to create TWO rules. First rule:

```
Apply an interval to a date:
  Interval Number:    entity1:field_number_of_days
  Interval Period:    days
  Date:               entity2:field_date
  Provided Variables: new_date

```

However, you're not finished. This stores ( date\_field + number\_of\_days\_field ) in a new date value called `new_date`. In order to save that new date back into `date_field` you have to create one final rule:

```
Set a data value:
  Data:  entity2:field_date
  Value: new_date

```
> 2 votes

# Answer
I would also like to hear more information about this. I am trying to create a rule which follows up on existing orders of specific products. Each product has a different time interval for "follow up reminder", and my rule should trigger an email to be sent to a customer at a date which is calculated Order Creation Date + Follow Up Interval.

ie Order Creation + Value provided from Products in the order
> 0 votes

---
Tags: rules, datetime
---


# Question
Title: Programmatically set the default value for a field
In Drupal 6, we could use PHP to set default values, but the same code cannot be used with Drupal 7.

I am trying to do this through `hook_form_alter()`, but the code doesn't work.

```
function my_form_alter(&$form, &$form_state, $form_id) {
  dsm($form);

  switch($form_id) {
    case 'accounts_node_form':
      $form["field_accounts"]["und"]['#default_value'] = $default;
      // …
      break;
  }
}

```

# Answer
> 19 votes
Assuming that your form alter function is actually running (which you can confirm with that call to `dsm()`), there are actually 2 more levels of array you need to go down to in order to get to the field element:

```
$form["field_accounts"][LANGUAGE_NONE][0]['value']['#default_value'] = $default;

```

In Drupal 7 you have a an array of values for each language the field has been translated into (so that fields with multiple/unlimited cardinality can be catered for), and under each of those is in array for the various different field columns. In the majority of cases this will be 'value' but not always (for example an image field has a file id column, alt column etc)

Hope that helps

# Answer
> 0 votes
This correct:

```
function my_form_alter(&$form, &$form_state, $form_id) {
  dsm($form);

  switch($form_id) {
    case 'accounts_node_form':
      $form["field_accounts"][LANGUAGE_NONE][0]['value']['#default_value'] = $default;
      // …
      break;
  }
}

```

---
Tags: 7, forms
---


# Question
Title: How can I programatically get the cart's dollar sum of drupal commerce?
For future users `<?php echo '$' . number_format(( $total['amount'] /100),2); ?>` is how.

---

Following this guide http://kahthong.com/2012/08/programmatically-show-number-items-drupal-commerce-shopping-cart I got the cart item total using

```
<?php
global $user;
$quantity = 0;
$order = commerce_cart_order_load($user->uid);
if ($order) {
    $wrapper = entity_metadata_wrapper('commerce_order', $order);
    $line_items = $wrapper->commerce_line_items;
    $quantity = commerce_line_items_quantity($line_items, commerce_product_line_item_types());
    $total = commerce_line_items_total($line_items);
    $currency = commerce_currency_load($total['currency_code']);
}
print format_plural($quantity, '1 item', '@count items');
?>

```

however when I try to get the dollar total using `<?php print $total; ?>`, it just returns 'Array'.

I used Devel on the page, but the cart is just a bunch of markup in `['content']['system_main']['main']['#markup']`. What I want is `<span class="line-item-total-raw">$106.00</span>`, is there a way I can grab that class specifically with php somehow? Or maybe there's another way to go about this.

# Answer
> 1 votes
You should have it already. That call to "commerce\_line\_items\_total" returns the array:

```
return array('amount' => $total, 'currency_code' => $currency_code);

```

Thus you should have the total price at $total\['amount'\] since you already have $total\['currency\_code'\]

---
Tags: 7, commerce, theming, debugging
---


# Question
Title: Drupal Rule to Clear a Field But Still Retain Data?
Need advice on fufilling this use case:

Use Case:

When User edits the node the first time, he populates *Field A*, a text area. The data from *Field A* is eventually displayed on *View A*.

When User or other User returns to edit the same node, *Field A* is cleared for convenience, ready for new text input. (But the original data is still in the DB, and displayed in *View A*).

When the User saves the page this second time, the new data replaces the previous data in *View A*.

Plus: Eventually, I also need to display the history of *Field A* in the application from all the saved edits.

# Answer
> 1 votes
Use hook\_form\_FORM\_ID\_alter() with FORM\_ID = node\_form.

Example:

```
function your_module_name_form_node_form_alter(&$form, $form_state) {
  $form['field_a']['#default_value'] = '';
}

```

For the second portion of your question, look into Node revisions.

---
Tags: views, rules
---


# Question
Title: How can multiple sites use a common default theme with site specific customizations?
We are using Aegir, we would like to use one core theme for all of our websites which handles common theming. But for specific theming for each site, we would like to handle inside of their custom themes.

Basically this will enable us that we can change common theming in just one theme used by all, instead of making the same changes in every theme of respective site.

One challenge by creating the custom theme in one of websites it will overwrite code from common core theme, but both themes should be present in the same time. Is there any kind of solution for something like this?

# Answer
Consider starting from a Base theme, such as Omega, Zen, Bootstrap, etc. Or build your own (custom) theme that you can use as a Base theme (that would be youru "core theme".

And then create Sub-themes (that would be what you named "their custom themes").

Note: the question about "Right way to start with a Bootstrap subtheme?" contains a lot of details to get started with such sub-theme ...
> 2 votes

---
Tags: theming, aegir
---


# Question
Title: How to test if a variable is been sanitized?
I have been doing coder review, and the coder module is showing this complain:

```
Line 111: Potential problem: drupal_set_message() only accepts filtered text, be sure to
use check_plain(), filter_xss() or similar to ensure your $variable is fully sanitized.
drupal_set_message($message);

```

So my question is if there is a way to test if the variable been sanitized ?. In the past, the coder module have show me false positive, that is why I'm asking how to check if is been sanitized or not.

I have check the entire project and does not have check\_plain(), nor filter\_xss().

# Answer
Your answer is already in the comments by @Geoff and @Clive above. If there was a way to unambiguously detect sanitation status of variables in PHP then the Coder module (and probably some IDE:s) would have incorporated it already.

But in some (not all) instances you can name your variables according to their sanitation status, to make it easier to keep track of which variables are sanitised and which are not.

```
<?php
  $myVar_raw = some_source();
  $myVar_safe = check_plain($myVar_raw);
  unset($myVar_raw); // Optional, to make sure raw variable is not used again later
?>

```
> 1 votes

---
Tags: 7
---


title: Using Configuration API in drupal 8

text:
# Question
Title: Using Configuration API in drupal 8
I altered node\_type\_edit\_form and added a section to get some settings like below:

Now I need to save the configurations and build the default value based on last selection using **Configuration API** .

The problem is it needs to build the fields selected (checkbox) in every content type form.

# Answer
> 1 votes
Instead of having your own configuration files, you can also use the third party settings concept to add your configuration directly to the node type config entity.

There are multiple advantages in doing that, you don't need to worry about cleaning up when node types are deleted, it's easier to deploy/export node types with their information and it's also easy to access/write when you have a node type. See the relevant change records: https://www.drupal.org/node/2326151 and https://www.drupal.org/node/2419827.

menu\_ui.module has a great example for this in core, look for the functions `menu_ui_form_node_type_form_alter()`, `menu_ui_form_node_type_form_builder()` (or as an alternative of the builder, define your form structure so that it's saved in the right third party settings key automatically) and the config schema in `menu_ui.schema.yml`.

# Answer
> 1 votes
I believe that you have machine name of `content type` while altering `node_type_edit_form`. So I assume that `$node_type` is the variable in which machine name can be accessible.

So as stated in drupal list changes, `variable_get` and `variable_set` is replaced by config system in drupal 8.

To save a configuration you need to add this code in your submit function :

```
\Drupal::configFactory()->getEditable('modulename.settings')
    ->set('checkboxsetting_' . $node_type, $form_state->getValues()['checkboxsettings'])
    ->set('radiosettings' . $node_type, $form_state->getValues()['radiosettings'])
    ->save();

```

and to get the saved values you need to :

```
\Drupal::config('modulename.settings')->get('checkboxsetting_' . $node_type);

```

To set the default configuration from yml file. Create a yml file and content will be :

**modulename/config/install/modulename.settings.yml**

```
checkboxsetting_page: whatever
checkboxsetting_article: whatever
radio_page: whatever
radio_article: whatever

```

---
Tags: 8, configuration
---


# Question
Title: When checking out, redirected to front page and not payment page
I am creating a new order, and line item (without a product, since this is just a fee we're collecting from the customer). The order is created, with line item, but when I go to /checkout/\[order\_id\], I'm just redirected to the front page.

My code for the order creation is:

```
function mymod_form_submit($form, &$form_state) {
        global $user;
        $order = commerce_order_new($user->uid, 'checkout_checkout');
        commerce_order_save($order);
ddl($order);

        $line_item = commerce_line_item_new('app_fee_type', $order->order_id);
        $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);

        $line_item_wrapper->line_item_label = t('Application Fee');
        $line_item_wrapper->quantity = 1;
        $line_item_wrapper->commerce_unit_price->amount = 3500;
        $line_item_wrapper->commerce_unit_price->currency_code = 'USD';
        $line_item_wrapper->commerce_total->amount = 0;
        $line_item_wrapper->commerce_unit_price->data = commerce_price_component_add(
                $line_item_wrapper->commerce_unit_price->value(),
                'base_price',
                $line_item_wrapper->commerce_unit_price->value(),
                TRUE,
                FALSE
        );
        commerce_line_item_save($line_item);

ddl($line_item);

        $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
        $order_wrapper->commerce_line_items[] = $line_item;
        commerce_order_save($order);
ddl($order);
        commerce_order_status_update($order, 'checkout_payment');
        drupal_goto('checkout/' . $order->order_id);
}

```

The customer should just be taken to the checkout screen. What am I missing?

# Answer
It looks like the order ID isn't being saved for the session. Add this:

```
$_SESSION['commerce_cart_orders'][] = $order->order_id;

```

Just make sure you do this before you save the final version of your order.
> 1 votes

---
Tags: 7, commerce
---


# Question
Title: Re-submit form after confirmed AJAX form
I have a form with submit AJAX button. When clicking this button, it calls function callbackAjax(). In this function callback, I checked a condition A to show a warning dialog if A is FALSE. The warning dialog has a message and two buttons, Confirm and Cancel. Cancel action will close dialog and do nothing. Confirm action will continue doing the callback function with condition A is true.

```
function renderForm($form, $form_state) {
  $form['submit'] = array(
    '#type'  => 'submit',
    '#ajax'  => array(
      'callback' => 'callbackAjax',
    ),
  );
}

function callbackAjax($form, &$form_state) {
  if (!$condition) {
    // Show dialog with confirm button
    // If confirmed, doing code in else clause
  }
  else {
    // Save data
  }
}

```

Please tell me how to re-submit form to save data after I clicked button Confirm which be rendered from AJAX callback?

I tried to set button Confirm as same as Submit button from main from, to call AJAX again, but it shows error.

Thanks for your help.

# Answer
I found the solution, at least it worked in my case. I want to share if someone need it.

```
function renderForm($form, $form_state) {
  $form['submit'] = array(
    '#type'  => 'submit',
    '#ajax'  => array(
      'callback' => 'callbackAjax',
    ),
  );
}

function callbackAjax($form, &$form_state) {
  if (empty($form['#skip_validate']) && !$condition) {
    // Show dialog with confirm button
    // If confirmed, doing code in else clause
    $confirm_form = drupal_get_form('renderConfirmForm', $form, $form_state);
    $commands[] = ajax_command_open_dialog($confirm_form);
  }
  else {
    // Save data
  }
  ...
}

function renderConfirmForm($form, &$form_state, $main_form, $main_form_state) {
  $form['continue'] = array(
    ...
    '#ajax'  => array(
      'callback' => 'renderConfirmFormCallback',
    ),
  );
  $form['close'] = ...;
  $main_form['#skip_validate'] = TRUE;
  $form['#main_form'] = $main_form;
  $form['#main_form_state'] = $main_form_state;
  return $form;
}

function renderConfirmFormCallback($form, &$form_state) {
  callbackAjax($form['#main_form'], $form['#main_form_state']);
}

```
> 1 votes

---
Tags: forms, ajax
---


title: Relationships Between Nodes on Field

text:
# Question
Title: Relationships Between Nodes on Field
I'm trying to work with some information out of our enterprise system to create an employee directory, and I have a question regarding how I can relate nodes together.

I have a content type called Employees, and it has a number of fields, including Employee ID, First Name, Last Name, etc.

I then have a content type called Positions, and it has a number of fields, including Employee ID, Title, etc.

I'm trying to figure out how I can link the Positions and Employee nodes together on the Employee ID field rather than the nid.

Any help would be appreciated. Thanks!

# Answer
> 0 votes
If you're looking for a relatively simple option, Entity Reference is probably best:

> Provides a field type that can reference arbitrary entities:
>
> A generic entity reference field Four widgets: Two implemented on top of the Options module (Select and Radios/Checkboxes), Two autocomplete widgets (one with one text field per entry, one tag-style with comma-separated entries in the same text field) Two formatters: A "Label" formatter, with optional link that displays the label of the referenced entity (the node title, the user name, etc.) A "Rendered entity" formatter, that renders the references entity using a configurable view mode Integration with Views (for both forward and backward references) Integration with Entity Metadata (and as a consequence with Search API and the like) Integration with Devel generate Integration with Feeds and Migrate (\>= 2.3) for painless data import

**EDIT #1**

To set up the view as described in comments:

* Create the view for Employee Content Type, and make settings how you desire
* Add a Relationship to `Entity Reference: Referenced Entity` for the entity reference field, `Require this relationship`

Now you have access to the fields in the referenced (position) content type and can display them in your view. One thing of note, Title field may not work from Position, so you may have to include a separate field for the Position Title. Otherwise, everything should work as a normal view

# Answer
> 0 votes
Try Views Cross Join

> Allows to cross join entities in Views. This is an essential tool to bring in not related data. For example you want to display two nodes in the same row, but there is no reference between them. Then you could cross join all nodes. Important all nodes get joined in, so you need to limit the result with filters and arguments.

You should also put an index on the fields being joined on the database for performance reasons.

---
Tags: views, entities
---


# Question
Title: I want my users to login through 'Last Name', rather than 'Password'
I would like my users to log in through 'Email' and 'Last Name', rather than 'User Name' and 'Password'. I did manage to swap 'User Name' with 'Email', but I cannot replace 'Password' with the user's 'Last Name'.

I have added another customer profile with two new fields, i.e., 'First Name' and 'Last Name' and now want the field 'Last Name' to be used in place of 'Password'.

I tried everything. Any help or guideline will be highly appreciated.

# Answer
You can do this by using a module called **String overrides** to redefine the strings exposed to your users during login and on their profile page.

Navigate to *Administration » Configuration » Regional and language » String overrides* and fille in the following and click "Save configuration":

Now, login will look like this to your users:

Note that this just *renames* the fields. This means that the last name will not have its own field and it will not be displayed on the user's profile page. It is not clear from your question whether this will be a problem.

However, *if* you want a real "Last name" field, and you want to use this field for authentication, you can do this by creating a small module that uses `hook_form_FORM_ID_alter()` to make a couple of changes to the login form:

1. Hide the password field.
2. Add "Last name" as a field.

Now, in the form validation, check that the value of the "Last name" field matches the last name in the user's profile, and if it does, fill in the hidden password field with the correct password. If you use the *same* password for all users in this set up, it can be hard-coded in your form validation. This will make Drupal take care of all the heavy lifting of creating a session, book-keeping of logins, etc.

As for the (in)security of using the last name instead of a real password as a login credential, I'll take your word for security not being an issue here. However, I am puzzled by why want this, so I have added a question about it as a comment.
> 0 votes

---
Tags: users, rules
---


title: nivo slider not working properly

text:
# Question
Title: nivo slider not working properly
I am new user of Drupal 7.3 also using View Nivo Slider in our project but nivo slider not working properly.

When I am traying to uploading images in nivo slider, uploading time is too much. I think images is not uploading. Please give me solution and in status report I am getting error message i.e.

> "Error Nivo Slider jQuery version jQuery 1.4.4 .Nivo Slider requires jQuery 1.7 or greater. Configure jQuery Update."

# Answer
> 0 votes
What the error is telling you is that you need to download and install Jquery Update module.

Then you need to configure jquery update in

> /admin/config/development/jquery\_update

and change the default version to grater than 1.7

---
Tags: 7, javascript
---


# Question
Title: How to merge tables and files from development to production
I am new to Drupal, but have learned a lot over the last two or three months. I am still fuzzy and perplexed about how to migrate new functionality and/or content from development to production.

I have turned off the Comments module because it really doesn't make sense for my site, but visitors can create a login ID. I will add the ability to subscribe to a newsletter soon. This means that I have to identify which tables and/or files are changed when a new login is created so that I don't destroy them when I migrate updates to the site from my local Win 7 computer running Acquia Dev Desktop.

I have learned that:

* Drupal uses a MySQL database to store not only content, but also settings information such as those pertaining to the Backup & Migrate module.
* In addition to the database there are LOTS of files with settings information, php statements and/or HTML.
* The Schema module's compare function tells me which tables are used by a given module.

According to Is there a module that lists which tables are created, owned or modified by a particular module? all well written modules should create tables only using hook\_schema, and should not alter tables in other modules.

If you suspect that other tables got changed, you can find this in the .install file for each module. Look for the database layer calls like db\_add\_field or even db\_create\_table.

With the above in mind, Schema gives me the tables a given module creates in the database. In my case, User is apparently the module that handles loginID's. Since it is a core module I assume that it is well written and that I don't have to go looking in its install file.

It appears that there is no enforcement mechanism in Drupal 7 that would prevent module developers from not using hook\_schema.

I discovered the Backup & Migrate module a few days ago. It works smoothly, but does a wholesale restore which would wipe out new logins.

The Data Export Import module (https://www.drupal.org/project/data\_export\_import) seems like it will work well, but I can't find a video or documentation.

There is lots of useful information at Drupal cross server workflow. From that I got the following:

* The Features module seems to apply to developers, not me because I am not writing modules.
* Drush appears to be overkill as well and yet another learning curve.
* GIT appears to be overkill and another learning curve for a one-man shop.

I seem to be left with a manual export/import of the database using phpMyAdmin to prevent wiping out the login ID's. As I move forward with more functionality this task becomes very cumbersome. I am hoping that the only thing I have to fret over is the database so that I can just use FileZilla for files uploads without having to worry about what files may have been changed by activity on my site.

Please tell me which assumptions I've made above that are incorrect. Also, I'd appreciate any additional advice you can give.

Sorry this post is so long. I wanted to be thorough!

# Answer
Short answer would be: For Drupal 7 use Features module for deployment.

It is not only for developers, it is mainly for site-builders who create new content types, views, install and configure modules.

Main idea is that you extract all required configuration data from your development DB and put it into the code. Then you only need to move this exported features files to your production site - and no more need to synchronize DBs (which could be tricky if you want to keep content from production DB).

Here is a good introduction into using Features.

By using Features, Strongarm and Features Extra modules you can migrate almost all configuration data.

And a few words about Git \- even if you are working alone you should use it. When you export all your Drupal configuration into the files, Git will help you to manage versions and keep history of all changes you did and why you did them (which is even more important).

The next step would be using Git to deploy code to the production instead of using FTP.

Note regarding Drupal 8 - it has built-in support for managing configuration and using Features module is no more necessary. here is a good overview.
> 0 votes

---
Tags: migrations, backups
---


# Question
Title: Show different fields when adding a content depends on the language
i have a question about a multilanguage feature which i don't find. I have contenttype with many fields (about 20 fields). Now i want to translate this page in a few languages. My problem is that some fields (the content of the fields) are only visible for a specific language like italian for example.

So the first idea could be to add additional fields to the contenttype for the specific languages. In aspect to the code i would render the specific field depending of what language is selected on the page.

But in relating of adding a content this could be very confusing with many languages.

So my question is: Is it possible to show fields when adding a content depending on what language is selected for the new content. For example when i have a field which should only visible for the italian translation.

Is this a known problem?

# Answer
> 1 votes
If you have some specific fields which only should be viewed based on language , the best way to do that is by using page manager and panels .

1. Download and enable this modules
2. go to Structure -\> pages
3. enable node\_view
4. add a variant and select Selection Rules
5. now add a rule based on user-\>language and node-\>type
6. and now you can make a custom view based on language

# Answer
> 0 votes
I think it would be easier for you to have only one field that you would be translated with the appropriate function : `t()`

https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/t/7

You may then translate it directly via the code or with the translation interface in the admin menu.

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


# Question
Title: Is ist possible to get the page variables in node templates?
I set a variable by implementing the `hook hook_preprocess_page`. The variable is available in `$variables['my_custom_var']` within the page.tpl.php.

Is it possible to get access to this variable in node.tpl.php or any other node template?

# Answer
> 1 votes
Variables that you set in the *hook\_preprocess\_page* are not available in *node.tpl.php*, only the variables in the *hook\_preprocess\_node* are available in *node.tpl.php*. Also the variables in *hook\_preprocess\_node* are not available in *page.tpl.php*

To share the varialbes between them you can use static variables. To do so use this code

```
function _myTheme_var($var_name, $new_val = NULL) {
  $vars = &drupal_static(__FUNCTION__, array());

   // If a new value has been passed
  if ($new_val) {
    $vars[$var_name] = $new_val;
  }

  return isset($vars[$var_name]) ? $vars[$var_name] : NULL;
}

function myTheme_preprocess_page(&$vars){
  $vars['some_var'] = _myTheme_var('my_var', 7); // Set the value and retrieve it
}

function myTheme_preprocess_node(&$vars){
    $vars['some_var'] = _myTheme_var('my_var'); // Get the value
}

```

# Answer
> 1 votes
In `node.tpl.php` you can render the particular field like this:

```
echo render($content['field_header']);
hide($content['field_header']); // This line isn't necessary as the field has already been rendered, but I've left it here to show how to hide part of a render array in general.

```

If you need to do this in `page.tpl.php` then you want to implement a preprocess function in your template file to get the variable you need:

```
function mymodule_preproces_page(&$vars) {
  if ($node = menu_get_object() && $node->type == 'page') {
    $view = node_view($node);
    $vars['my_header'] = render($view['field_header']);
  }
}

```

# Answer
> 0 votes
You can set variables in template\_preprocess\_node for the node template

---
Tags: 7, theming
---


# Question
Title: Views contextual filter - related nodes as an offset from a node's creation date
I have a related content view which displays similar nodes based on shared taxonomy terms. I want it to display related nodes that were published in a date range relative to the current node's creation/published date. E.g: for a node published in March, I want to filter similar nodes that were published between February and April.

Currently I am only able to create a contextual filter "Node: Published at year + month" which displays similar nodes that were published in the same year+month, but I am looking for something similar to the post date filter criteria with operator (image attached), but instead of offset from current time, have an offset from current node's creation date. Is that feasible with views contextual filter?

# Answer
> 0 votes
I think in this case you can use panels for that In views create a content pane

Then add contextual filter based on Created Date and in "PANE SETTINGS" click on "Argument input" and use this Settings :

this will export the node's created date from it and pass it through arguments to views.

this will give you an Panel's pane , to add it to your view you can use Page manager module .

---
Tags: views
---