Code Snippets

Importing Taxonomy Terms into Drupal

This example code loads the necessary Drupal modules to get Taxonomy reads and writes which allows you to write some handy command line tools. Refer to this blog post for more information.

class MyExampleClass {
  /* ... all your methods go here ... */
  public function run_something() {
  /* ... your code that uses the 3rd party API and Drupal internals such as
  * taxonomy_get_tree(), taxonomy_term_save() etc
  */
  }
} // end class

/* make sure we are running via command line before including any Drupal bits */
if (php_sapi_name() == 'cli') {
  /* gets rid of Notices where Drupal depends on _SERVER */
  $_SERVER['HTTP_HOST'] = "localhost";
  $_SERVER['REMOTE_ADDR'] = "127.0.0.1";

  define('DRUPAL_ROOT', '/PATH-TO-YOUR-DRUPAL-DIRECTORY/');
  require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
  require_once DRUPAL_ROOT . '/includes/common.inc';
  require_once DRUPAL_ROOT . '/includes/file.inc';
  require_once DRUPAL_ROOT . '/includes/module.inc';
  drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
  drupal_load('module', 'system');
  drupal_load('module', 'taxonomy');
  drupal_load('module', 'inc');
  drupal_load('module', 'field');
  drupal_load('module', 'field.crud');
  drupal_load('module', 'field_sql_storage');
  drupal_load('module', 'options');

 /* if running THIS script, instantiate your class and run your code */
  if (preg_match('/'. basename(__FILE__) .'/', $argv[0])) {
    try {
      $me = new MyExampleClass();
      $me->run_something();
    } catch (Exception $e) {
      print $e ."\n";
      var_dump(debug_backtrace());
      exit(1);
    }
    exit(0);
  } // end if this script was run
} // end if using command line

 

$(this).css("position", "relative");
$(this).css("left", "0px");

and the view should now display at the position where you want it to show.

 

Resource Tags: