Hello
I have an error message in terminal using drush when I enable the fences module

Fatal error: Cannot redeclare mytheme_preprocess_html() in template.php on line 27

The same thing appears if I remove theme_preprocess_html() function :

Fatal error: Cannot redeclare mytheme_preprocess_page() in template.php on line 95

It appears with Bartik theme and semantic panels enable in drupal 7.34 and php5.3

Comments

gold’s picture

Status: Active » Closed (cannot reproduce)

This does not appear to be an issue with Fences. The error suggests it's a copy/paste error in a theme rather than something from this module.

gold@shipnet /tmp $ git clone --branch 7.x-1.x http://git.drupal.org/project/fences.git
Cloning into 'fences'...
remote: Counting objects: 594, done.
remote: Compressing objects: 100% (591/591), done.
remote: Total 594 (delta 424), reused 0 (delta 0)
Receiving objects: 100% (594/594), 89.97 KiB | 143.00 KiB/s, done.
Resolving deltas: 100% (424/424), done.
Checking connectivity... done.
gold@shipnet /tmp $ cd fences/
gold@shipnet /tmp/fences (7.x-1.x) $ ls
CHANGELOG.txt     fences.api.php     fences.info     fences.module  field-rtl.css
fences.admin.inc  fences.fences.inc  fences.install  field.css      templates
gold@shipnet /tmp/fences (7.x-1.x) $ grep -rn mytheme_preprocess_html *
gold@shipnet /tmp/fences (7.x-1.x) $ 

Closing this. If you can provide more detail to identify the issue within Fences feel free to reopen.

henrijs.seso’s picture

Assigned: creatile » Unassigned

Unassigning author. I got this too. When using drush aliases, not with plain drush in working directory.

forestmars’s picture

Status: Closed (cannot reproduce) » Active

This bug is a craymaker. (Also, a heisenbug?)

WRT #1 it is *definitely* not a copy/paste error in a theme, since it occurs with vanilla Bartik.

WRT #2 Disabling Semantic Panels didn't suppress this bug for me. The only thing that suppresses the bug is disabling fences.

With Fences enabled, drush insists every function in template.php is being redeclared, regardless which core or custom theme is the enabled default theme (with the exception, of course, of Stark, which has no template.php.)

Tested with both 7.x-2.0-beta1 & 7.x-1.x-dev with the same results.

Re-opening as a matter of record, as there is evidently a bug in there, albeit an elusive one.

creatile’s picture

I can reproduce the bug easily with drupal-7.41 with the following action :

drush dl drupal
Install drupal 7.41

Then here are my terminal actions :

imac-fixe:fencestest creatile$ drush dl views views_ui module_filter devel pathauto token
Project views (7.x-3.13) downloaded to                               [success]
/Users/creatile/sites/fencestest/sites/all/modules/views.
Project views contains 2 modules: views, views_ui.
No release history was found for the requested project (views_ui).   [warning]
Project module_filter (7.x-2.0) downloaded to                        [success]
/Users/creatile/sites/fencestest/sites/all/modules/module_filter.
Project devel (7.x-1.5) downloaded to                                [success]
/Users/creatile/sites/fencestest/sites/all/modules/devel.
Project devel contains 3 modules: devel_generate, devel, devel_node_access.
Project pathauto (7.x-1.3) downloaded to                             [success]
/Users/creatile/sites/fencestest/sites/all/modules/pathauto.
Project token (7.x-1.6) downloaded to                                [success]
/Users/creatile/sites/fencestest/sites/all/modules/token.
imac-fixe:fencestest creatile$ drush dl fences
Project fences (7.x-1.2) downloaded to                               [success]
/Users/creatile/sites/fencestest/sites/all/modules/fences.
imac-fixe:fencestest creatile$ drush en fences
The following extensions will be enabled: fences
Do you really want to continue? (y/n): y
fences was enabled successfully.                                     [ok]
imac-fixe:fencestest creatile$ drush en views views_ui pathauto
The following projects have unmet dependencies:
views requires ctools
views_ui requires ctools
Would you like to download them? (y/n): y
Project ctools (7.x-1.9) downloaded to                               [success]
/Users/creatile/sites/fencestest/sites/all/modules/ctools.
Project ctools contains 10 modules: views_content, term_depth, stylizer, page_manager, ctools_plugin_example, ctools_custom_content, ctools_ajax_sample, ctools_access_ruleset, bulk_export, ctools.
The following extensions will be enabled: views, views_ui, pathauto, ctools, token
Do you really want to continue? (y/n): y
Drush command terminated abnormally due to an unrecoverable error.   [error]
Error: Cannot redeclare bartik_preprocess_html() (previously declared
in /Users/creatile/sites/fencestest/themes/bartik/template.php:6) in
/Users/creatile/Sites/fencestest/themes/bartik/template.php, line 27
creatile’s picture

I started a new test :
drupal-7.41
drush 5.9
php 5.4

The problem appears with token pathauto and fences enabled

imac-fixe:fencestest creatile$ drush en token
The following extensions will be enabled: token
Do you really want to continue? (y/n): y
token was enabled successfully.                                      [ok]
imac-fixe:fencestest creatile$ drush en fences
The following extensions will be enabled: fences
Do you really want to continue? (y/n): y
fences was enabled successfully.                                     [ok]
imac-fixe:fencestest creatile$ drush en pathauto
The following extensions will be enabled: pathauto
Do you really want to continue? (y/n): y
Drush command terminated abnormally due to an unrecoverable error.   [error]
Error: Cannot redeclare bartik_preprocess_html() (previously declared
in /Users/creatile/sites/fencestest/themes/bartik/template.php:6) in
/Users/creatile/Sites/fencestest/themes/bartik/template.php, line 27
j.cowher’s picture

A workaround that works for me when this happens is to "sudo" the Drush command, e.g.

sudo drush cc all

johnalbin’s picture

Title: Cannot redclare preprocess in template.php » Cannot redeclare preprocess in template.php

99% of the time, using "sudo" is not the answer. And it has nothing to do with this issue either. If someone told you to "try the command with sudo" if something doesn't work, that was bad advice.

Anyway…

This bug is probably caused by this code in fences.admin.inc:


  // Include the template.php files of the entire theme stack.
  foreach (array_keys($themes) as $theme) {
    $file = './' . drupal_get_path('theme', $theme) . '/template.php';
    if (file_exists($file)) {
      include_once $file;
    }
  }

Note that Fences is using "include_once" to try to prevent the template.php from being included more than once. If you just "include" it and that template.php has already been included before, you'll get the "Cannot redeclare preprocess in template.php" error.

The next step is to look in token or pathauto to see if it is including template.php and how it is doing it.