2

I'm getting a PHP fatal error whenever I try to use taxonomy_term_save(). I am using it in an install script which may be pertinent information.

PHP Fatal error:  Class name must be a valid object or a string in /var/www/proface.com/includes/common.inc on line 7779, referer: http://domain/install.php?profile=company_install_profile&locale=en&op=start&id=1

Why would this happen? The terms look correct to me:

  $terms = array();

  drupal_load('module', 'taxonomy');
  $vocabulary = taxonomy_vocabulary_machine_name_load('distributor_types');

  $term = new stdClass();
  $term->name = "Platinum Distributors";
  $term->description = '';
  $term->vid = $vocabulary->vid;
  $term->weight = 0;
  $term->vocabulary_machine_name = 'distributor_types';
  $term->format = 'plain_text';
  $term->uuid = 'ee4e4f18-ad5e-46df-a2e7-145876efd907';
  $terms[] = $term;

Pulled out each of the terms from a foreach loop and...

  taxonomy_term_save($term);

And when I print out the entity name that is causing problems, it spits out, "taxonomy_vocabulary".

This is the function throwing the error, the line with "new $class($entity_type)" is line 7779.

function entity_get_controller($entity_type) {
  $controllers = &drupal_static(__FUNCTION__, array());
  if (!isset($controllers[$entity_type])) {
    $type_info = entity_get_info($entity_type);
    $class = $type_info['controller class'];
    $controllers[$entity_type] = new $class($entity_type);
  }
  return $controllers[$entity_type];
}

I believe the version for this is 7.22.

  • 1
    Without any more context it's hard to be helpful... What exact version of Drupal are you using? On 7.25, line 7779 in common.inc points to the docblock for entity_load(). Also, it looks like you're creating default content in a custom install profile, at what point of the installation are you doing this? – Alex Weber Jan 15 '14 at 20:47
  • I am attempting to create default content in a custom install profile. During the "installing Drupal" section, where it loads all of the default modules for the installation profile. The module throwing the error is installed during installation. – Jack Ryan Jan 15 '14 at 20:52
  • Can you upgrade to recent 7.x on dev copy and test if it wasn't already fixed? Your code looks pretty OK, at least at first glance – Mołot Jan 15 '14 at 20:57
  • This appears to be the problem area: drupal_load('module', 'taxonomy'); $vocabulary = taxonomy_vocabulary_machine_name_load('distributor_types'); When these two lines are not commented out, that error is thrown. – Jack Ryan Jan 15 '14 at 21:38
  • What makes you think that upgrading would fix this? Upgrading would be very difficult on the current setup. – Jack Ryan Jan 15 '14 at 21:38
1

It's actually my coworker that should get credit for this, not me, but here's the solution:

drupal_load('module', 'taxonomy');

module_enable(array('taxonomy'), FALSE);

$vocabulary = taxonomy_vocabulary_machine_name_load('distributor_types');

The taxonomy module wasn't enabled.

0

My working theory right now is that as of that point in your code Drupal isn't aware of the taxonomy_vocabulary controller. You could try running entity_get_info('taxonomy_vocabulary') first to inform Drupal of the taxonomy_vocabulary controller.

  • Would I run that after drupal_load('module', 'taxonomy');, or before? – Jack Ryan Jan 15 '14 at 21:54
  • Doesn't matter, tried both, neither worked. – Jack Ryan Jan 15 '14 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.