TransWikia.com

Undefined function in module

Drupal Answers Asked by Idjit on December 19, 2021

I use taxonomy_get_term_by_name() in one of my modules, and it throws a Undefined function exception.
My best guess is that this is due to Drupal core system not being ready for function calls. I’ve looked all over and I can’t find any way to check when the core system is ready for function calls.

Do you have any suggestion?

The module uses require_once to get the file with the function mentioned above.

The content of the file calling taxonomy_get_term_by_name() is the following.

/**
 * Implements hook_init().
 */
function functions_init()
{
    get_tids();
}

function get_tids()
{
    $terms = ['term1', 'term2', 'term3'];
    foreach ($terms as $term) {
        $result = taxonomy_get_term_by_name($term);
        $GLOBALS[$term] = key($result);
    }
}

  • This was not an issue when the module was developed, but with a few days of downtime on localhost and a reboot, this started happening.
  • There is near certainly a workaround through use of EntityFieldQuery, but I would like to know whether it is possible to check Drupal 7 core availability, which would be useful/needed in other situations.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP