The civicrm_form_alter() function conflicts with a new civicrm_form_alter() defined in v3.0's civicrm.module.

This patch merely renames the function to civicrm_theme_form_alter().

Tested in CiviCRM v2.2.8 and v3.0b2

Comments

fen’s picture

StatusFileSize
new225 bytes
fen’s picture

StatusFileSize
new536 bytes

new patch file in patch format

jackalope’s picture

Thanks for the patch, fen! I had the same problem with civicrm_theme and your patch took care of it handily.

marcomatic’s picture

The patch works for me also. Any chance it can get rolled into a new or dev release? This way we can update the module and not have to worry about the patch? Thanks.

(I edited it to say "the patch" instead of "our patch" :) I had nothing to do with writing it)

bcobin’s picture

Thanks a ton! Works perfectly... you rock, fen!

greenbeans’s picture

StatusFileSize
new2.05 KB

Here's a patched version of the module.

okokokok’s picture

Thanks, the .zip works for me!

Please release it, it would be nicer to just have it work after a drush update :)

bcobin’s picture

This is broken once again in Civi 3.1 beta1 - issue posted here.

greenbeans’s picture

Given how Drupal hooks work, the only solution may be to rename the whole module.

catch’s picture

Subscribing.

catch’s picture

Status: Active » Needs review
bcobin’s picture

I'm not sure what's meant by "renaming the whole module" in #9, Mr. Greenbeans - please elaborate, if it's not too much trouble - and thanks!

greenbeans’s picture

Drupal requires that a module use "hooks" to alter system behavior -- in this case one named "hook_form_alter()". The module's version of the hook must be named based on the module name and the hook name [replacing "hook" with the module name]: in this case, civicrm_theme + hook_form_alter() = civicrm_theme_form_alter().

If we change the function name again without changing the module name, Drupal won't call it because it won't know to look for it at the new name. (I believe that civicrm_form_alter() only worked because there was a module called "civicrm" already installed, so Drupal looked for civicrm_form_alter()).

If the module were to be renamed to something like "civitheme" then we could name the hook function civitheme_form_alter() -- which is unlikely to clash with anything introduced by civicrm in the near future.

catch’s picture

Priority: Normal » Critical
StatusFileSize
new4.93 KB

Here's a patch renaming everything to civicrmtheme. Also bumping this to critical.

bcobin’s picture

This is what I got:

warning: Invalid argument supplied for foreach() in /home/[sitename]/public_html/includes/form.inc on line 1429.
warning: Invalid argument supplied for foreach() in /home/[sitename]/public_html/includes/form.inc on line 1429.

So, not soup yet - at least on this end... thanks, though!

bcobin’s picture

Hey, all! Has there been any progress on this?

Just tried everything I can think of (I'm not a coder) and I still get the same error message with 3.1 beta4. I'm using a fixed-width theme, which is pretty problematic with Civi. Yes, I'm creating custom templates, but it would be SO much easier if I could get this to work like it used to way back when...

Any help is greatly appreciated - thanks!

greenbeans’s picture

I'm in the middle of some other stuff right now, but will create an updated version next time I return to a CiviCRM project -- probably in a month or two.

bcobin’s picture

Thank you, Mr. (Ms?) Greenbeans - I'll keep an eye out - good luck with your projects!

brightbold’s picture

This seems to work for me after applying the patch from #14 (although I haven't tried to do anything with the module yet! But it is now installed on CiviCRM 3.1b5 with no errors.)

For anyone who wants to do this, and, like me, isn't a developer and is used to applying patches by hand, just make sure that you have replaced every instance of "civicrm_theme" with "civicrmtheme" not only in the .module file but also in the .info file. And don't forget to rename both files to remove the underscore!

bcobin’s picture

Nope - I've tried all possible variations I can think of and still get the same error as listed above on the Administration Theme admin page.

(To be clear, that's when the error appears - there's no error upon instanciating the module.)

Have you seen no error on the Administration Theme page? Can't imagine what's going on here...

Any help would be most appreciated - many thanks!

gislars’s picture

I got the module to work and set civicrm administration and civicrm user theme in the admin/settings/admin menu.
But for the "find participants" page (civicrm/event/search&reset=1) I get my standard theme back.

I'm not sure how to solve this. Does anybody can confirm this behavior or/and knows how to change it?

bcobin’s picture

If it's not too much to ask, gislars, could you possibly post a zipped version of the working module folder? Even that would be a big help for me... thanks!

gislars’s picture

StatusFileSize
new1.34 KB

Please find attached the module folder.

Maybe I did something wrong by changing all occurrences of civicrm_theme to civitheme.

Thanks for looking into it!

bcobin’s picture

Thanks, gislars - unfortunately, I get the same error with the attached file. Note that BrightBold says that he/she was able to get it to work by changing "civicrm_theme" to "civicrmtheme," not "civitheme."

I haven't been able to get it to work either way, so perhaps there's something else going on here.

Still at square one over here - any and all ideas welcome!

sonicthoughts’s picture

zip in comment #23 works for me.

bcobin’s picture

Gosh - I can't imagine what would be different with my installation, but I still get the error:

warning: Invalid argument supplied for foreach() in /home/[sitename]/public_html/includes/form.inc on line 1429.
warning: Invalid argument supplied for foreach() in /home/[sitename]/public_html/includes/form.inc on line 1429.

I've cleared caches, theme registry - everything I can think of, but the problem persists.

Below is the code from includes/form.inc with line 1429 commented - any ideas would be great... I am totally stumped here... thanks much!

function form_select_options($element, $choices = NULL) {
  if (!isset($choices)) {
    $choices = $element['#options'];
  }
  // array_key_exists() accommodates the rare event where $element['#value'] is NULL.
  // isset() fails in this situation.
  $value_valid = isset($element['#value']) || array_key_exists('#value', $element);
  $value_is_array = is_array($element['#value']);
  $options = '';
  foreach ($choices as $key => $choice) { // Line 1429
    if (is_array($choice)) {
      $options .= '<optgroup label="'. $key .'">';
      $options .= form_select_options($element, $choice);
      $options .= '</optgroup>';
    }
    elseif (is_object($choice)) {
      $options .= form_select_options($element, $choice->option);
    }
    else {
      $key = (string)$key;
      if ($value_valid && (!$value_is_array && (string)$element['#value'] === $key || ($value_is_array && in_array($key, $element['#value'])))) {
        $selected = ' selected="selected"';
      }
      else {
        $selected = '';
      }
      $options .= '<option value="'. check_plain($key) .'"'. $selected .'>'. check_plain($choice) .'</option>';
    }
  }
  return $options;
}
gislars’s picture

replying to #25:
*DOH* it works for you... Do you mean you can use the participant search with the alternate theme defined in admin/settings/admin? because its just that where I'm getting the public theme.

If your answer is still yes... hmm then something with my installation or theme might be wrong

jeffsensat’s picture

Title: civicrm_form_alter() conflicts with CiviCRM v3.0 » civicrm_form_alter() conflicts with CiviCRM v3.1.1

Instead of my drupal site, now I’m getting this:

Fatal error: Cannot redeclare civicrm_form_alter() (previously declared in [MYWEBSITE]/modules/civicrm_theme/civicrm_theme.module:28) in [MYWEBSITE]/sites/all/modules/civicrm/drupal/civicrm.module on line 805

Everything was working fine with the newly-released CiviCRM 3.1.1 on Drupal 6.15 ... until I installed civicrm_theme. I followup the thread here ( http://drupal.org/node/568710 ). Installing the patched, newly-named "civitheme" module didn’t help. I also completely replaced my civicrm module folder via FTP.

I’ve tried running update.php, evoking the " http:///civicrm/upgrade?reset=1 " command, but my site’s dead.

Help?

bcobin’s picture

Not an expert here, but I've been deploying a site with Civi today, so it's fresh in my mind. I decided to punt on CiviTheme until it gets sorted out.

I assume you deleted the civitheme module folder? You may also need to delete the files/civicrm folder as well; I believe the system will regenerate those files. That's all I can think of at the moment.

Good luck!

catch’s picture

Just a note I've been running the patch in #14 for some time on a site that's in active development with no side effects, you might want to try that instead of the .tar.gz - and if it works, set it to rtbc. Can't reproduce bcobin's issue.

jeffsensat’s picture

Thanks, bcobin and catch, for your ideas.

In my sleep-deprived condition, I incorrectly placed a duplicate copy of the civicrm_theme module in [MYWEBSITE]/modules/ as well as the CORRECT location at [MYWEBSITE]/sites/all/modules/ ...

Having already deleted the module from the latter folder yet still receiving fatal errors, I took a nap to clear my mind. Then, thinking more clearly, I found and removed the module from the former location. That immediately solved the problem. PHEW.

Note to self: NEVER attempt critical tasks after 20 hours of straight work. I hope this helps others who toil too much and sleep too little.

pearcec’s picture

#14 work for me too, but the patch didn't apply as neatly as I wanted because of the rename.

avolve’s picture

Have applied #14 and is working as well.

Anyone able to have admin module — http://drupal.org/project/admin work with this?

smcclung’s picture

I just installed the version given in comment #23. I may be stating this prematurely, but from what I can see, it works without error. I have the option of selecting an admin theme for CiviCRM in admin/settings/admin. Thank you. There should be a warning for people trying to download/install the module as offered on http://drupal.org/project/civicrm_theme.

bcobin’s picture

Just installed the module on a new installation and it's working fine. There's been a lot of Civi changes since I first ran into the problem; I would say that with Civi 3.1.3 everything's OK. Thanks!

darrick’s picture

#14 worked for me with Civi 3.1.3 upgrade.

zoen’s picture

Status: Needs review » Reviewed & tested by the community

Bump. I get the WSOD with CiviCRM 3.1.3 and CiviCRM Theme 6.x-1.3; #14 patch works.

deviantintegral’s picture

Status: Reviewed & tested by the community » Fixed

I've committed the patch from #14. If there are any issues further to this, please open a new issue with the specifics.

pixelsweatshop’s picture

subscribing

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

meecect’s picture

for those having trouble still, there is an error in the hook_form_alter function. I believe this error is in the module as well as the zip files and patches listed in this thread. This may be because the admn_module has changed a bit. Anyway the funciton should look like this:



function civicrmtheme_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'system_admin_theme_settings') {
    $newform['admin_theme']['civicrm_admin_theme'] = array(
      '#type' => 'select',
      '#options' => $form['theme']['admin_theme']['#options'],
      '#title' => t('CiviCRM Administration theme'),
      '#description' => t('Choose which theme the CiviCRM administration pages should display in.'),
      '#default_value' => variable_get('civicrm_admin_theme', ''),
    );
    $newform['admin_theme']['civicrmtheme'] = array(
      '#type' => 'select',
      '#options' =>  $form['theme']['admin_theme']['#options'],
      '#title' => t('CiviCRM User theme'),
      '#description' => t('Choose which theme the CiviCRM user pages should display in.'),
      '#default_value' => variable_get('civicrmtheme', ''),
    );
    $form = array_merge(array_slice($form, 0, 1), $newform, array_slice($form, 1));
  }
}

The change is in how the options are built, ie:

'#options' =>  $form['theme']['admin_theme']['#options'],

as opposed to:

'#options' =>  $form['admin_theme']['#options'],
Hobbes-2’s picture

Status: Closed (fixed) » Active

subscribe

Currently not working here with last version of Drupal, Civicrm, CiviCRM Theme and admin theme.

I get this error :
/sites/all/modules/civicrm_theme/civicrm_theme.module on line 46

Hugo

deviantintegral’s picture

What is the error exactly? Are you using the latest -dev release?

joelstein’s picture

Title: civicrm_form_alter() conflicts with CiviCRM v3.1.1 » Rename civicrm_form_alter() to civicrm_theme_form_alter()
Status: Active » Needs review
StatusFileSize
new339 bytes

This module's name space is "civicrm_theme", so it doesn't make sense to rename it to "civicrmtheme". That decision may have been suggested by comment #13, but changing the module name is not the appropriate solution to this problem. All that needs to be done is to change civicrm_form_alter() to civicrm_theme_form_alter(). I made this simple change and everything works fine. This is the appropriate use of hook_form_alter().

Attached is a patch which resolves this issues.

I have the latest (stable) versions of Drupal, CiviCRM, and CiviCRM Theme (with this patch applied), and it works great. Please consider using this patch, instead of renaming the module.

deviantintegral’s picture

Status: Needs review » Fixed

The patch from #14 was committed, and the -dev release should work fine. While renaming the form_alter function works for this issue, in the long run renaming the module is the better way to go as it makes it clear that civicrm_* is for civicrm.

Please test the -dev release, and if it doesn't work post the error. I should probably release a new stable version anyways since -dev hasn't been touched in quite some time.

joelstein’s picture

Understood. In that case, I recommend that you release a new module under the namespace of "civicrmtheme". Otherwise, it will be a perpetually confusing issue.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

bcobin’s picture

mecect - thank you so much for the code change in #41; I had been using the latest version of the module without incident for recent sites, but I couldn't get the module to work on a site I did several months back until I made the code change just now. Thank you!

I see that the latest (1.4) version uses the older version of the function; I would think it should be updated lest others run into the same problem that I did.

meecect’s picture

#48, I attached a patch for this issue here:

http://drupal.org/node/947520#comment-3719268