Hi,

I have a handful of modules for a project currently in development, however each time the cache is cleared I can no longer access the content types from these modules. All my form hooks that submit the nodes plus the additional fields in my own tables have stopped loading in and saving content too.

I did read an article about them disapearing with someone using ubercart nd using hook_init() to solve the issue, although I am fairly sure I'm not doing the same as they were changing config_perms.

For the moment its not stopping development as I can disable and re-enable the module to restore it, without loosing data, but it would be preferable to stop this from happening.

any pointers would be helpful.

Paul

Comments

da_solver’s picture

Can you please elaborate. What do you mean by "I can no longer access the content types" ? Please elaborate and detail what you expect to occur versus what actually occurs? For example, are the custom modules creating database tables? If so, are the tables present or absent? Is the data that is supposed to be stored in the database, present or absent?

cliffp’s picture

I have the same in Drupal 7.

My module creates a content type and initially it appears in /node/add. After cache clear it no longer appears in /node/add.

/node/add/mymodule takes me to /node/add, not the mymodule data entry form, as it did before cache clear.

I installed the examples package and node_example within that package and all works as expected through a cache clear. I'm code browsing to try to work out what the difference is between that package and mine.

Cheers,

Cliff

paul.linney’s picture

Hi Cliff,

I wrote a follow up post to a different thread and got the answer, http://drupal.org/node/982270

That solution was for Drupal 6, in Drupal 7 I've not done the content types the same way. The my module content types are done as entities.

I think as long as your hook_info is in the .module file all should be ok.

Paul

Paul Linney
Owner & Web Developer

cliffp’s picture

Thanks, I'll take a look.

Cheers,

Cliff

cliffp’s picture

That fixed it. I'd love to know why. There are modules that don't implement hook_node_info that work OK. EG the Devel module.

Cheers,

Cliff

cliffp’s picture

I had misconfigured the node type definition, specifically the 'body' item. See the comment in this page from the API documentation:

http://api.drupal.org/api/drupal/modules--node--node.module/function/nod...

paul.linney’s picture

What do you mean by "I can no longer access the content types" ?

Prior to clearing the cache I can goto create create content and all my custom module content types are listed.

Please elaborate and detail what you expect to occur versus what actually occurs?

I expect them to still be available for adding content versus not being available.

For example, are the custom modules creating database tables?

Yes they are

If so, are the tables present or absent?

Present

Is the data that is supposed to be stored in the database, present or absent?

Present

Everything else defined within the modules are still available such as block and menus, just the content types disappear.

Here is one of my modules


///// .info /////
; $Id$
name = GHA Office
description = Office - Content type and Forms
package = GHA Studio
core = 6.x
version = "6.x-1.0"
php = 5.2
dependencies[] = gha_base


///// .install /////
function gha_office_install() {
  drupal_install_schema('gha_office');
}

function gha_office_uninstall() {
  drupal_uninstall_schema('gha_office');
}

function gha_office_schema() {
    
    $schema['GHA_Office'] = array(
      'fields' => array(
          'nid' => array(
            'type' => 'serial', 'not null' => TRUE
          ),
          'title' => array(
            'type' => 'varchar', 'length' => 64, 'not null' => TRUE
          ),
          'address' => array(
            'type' => 'varchar', 'length' => 255
          ),
          'description' => array(
            'type' => 'varchar', 'length' => 255
          ),
          'published' => array(
            'type' => 'int', 'precision' => 1, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'
          )
      ),
      'primary key' => array('nid'),
    );

    $schema['GHA_Office_User'] = array(
      'fields' => array(
          'id' => array(
            'type' => 'serial', 'not null' => TRUE
          ),
          'user_id' => array(
            'type' => 'int', 'default' => 0
          ),
          'office_id' => array(
            'type' => 'int', 'default' => 0
          )
      ),
      'primary key' => array('id'),
    );
    
    $schema['GHA_Office_Address'] = array(
      'fields' => array(
          'id' => array(
            'type' => 'serial', 'not null' => TRUE
          ),
          'office_id' => array(
            'type' => 'int', 'default' => 0
          ),
          'title' => array(
            'type' => 'varchar', 'length' => 64, 'not null' => TRUE
          ),
          'address' => array(
            'type' => 'varchar', 'length' => 255
          ),
          'description' => array(
            'type' => 'varchar', 'length' => 255
          )
      ),
      'indexes' => array(
        'goa_office' => array('office_id')
      ),
      'primary key' => array('id'),
    );

    return $schema;
}

/**
* Implements hook_node_info().
*/
function gha_office_node_info() {
    return array(
        'gha_office' => array(
            'name' => t('Office'),
            'module' => 'gha_office',
            'description' => t('Office'),
            'has_title' => TRUE,
            'title_label' => t('Office Name'),
            'has_body' => FALSE
        )
    );
}

///// .module /////
function gha_office_help($path, $arg) {
    if ($path == 'admin/help#ghastudio') {
        $txt = 'GHA help';
        $replace = array();
        return '<p>'. t($txt, $replace) .'</p>';
    }
}

function gha_office_views_api() {
    return array('api' => 2.0);
}

function gha_office_menu() {
    $items = array();
    
    $items['administration/office/add'] = array(
        'title' => 'Add Office',
        'page callback' => 'page_content_office_add',
        'access arguments' => array('access local housing offices'),
        'type' => MENU_CALLBACK
    );
    
    $items['administration/office/edit/%'] = array(
        'title' => 'Edit Office',
        'page callback' => 'page_content_office_add',
        'page arguments' => array(3),
        'access arguments' => array('access local housing offices'),
        'type' => MENU_CALLBACK
    );
    
    $items['administration/office/delete/%'] = array(
        'title' => 'Delete Office',
        'page callback' => 'page_content_office_delete',
        'page arguments' => array(3),
        'access arguments' => array('access local housing offices'),
        'type' => MENU_CALLBACK
    );
    
    return $items;
}

/**
* Implements hook_perm()
*/
function gha_office_perm() {
    return array(
        'access local housing offices'
    );
}

/**
* Implementation of hook_form().
*/
function gha_office_form(&$node,$var) {
    
    if (!empty($var) && is_numeric($var)){
        // Frontend Admin
        $edit_node = node_load(array('nid' => $var));
    }
    else {
        // Drupal Admin
        $arg_list = func_get_args();
        if (!empty($arg_list) && !empty($arg_list[0]->nid)) {
            $edit_node = node_load(array('nid' => $arg_list[0]->nid));    
        }
    }

    $type = node_get_types('type', $node);
    
    if (!empty($edit_node)) {
        $form['nid'] = array(
            '#type' => 'textfield',
            '#title' => t('Nid'),
            '#required' => TRUE,
            '#default_value' => $edit_node->nid,
            '#disabled' => TRUE,
            '#weight' => 0,
        );
    }
    
    $form['title'] = array(
        '#type' => 'textfield',
        '#title' => t('Title'),
        '#required' => TRUE,
        '#default_value' => $edit_node->title,
        '#weight' => 1,
    );
    
    $form['address'] = array(
        '#type' => 'textarea',
        '#title' => t('Address'),
        '#cols' => 50,
        '#rows' => 5,
        '#default_value' => $edit_node->address,
        '#weight' => 3
    );
    
    $form['description'] = array(
        '#type' => 'textarea',
        '#title' => t('Description'),
        '#cols' => 50,
        '#rows' => 5,
        '#default_value' => $edit_node->description,
        '#weight' => 4
    );

    $form['published'] = array(
        '#type' => 'select',
        '#title' => t('Published'),
        '#required' => TRUE,
        '#default_value' => $edit_node->published,
        '#options' => array(t('Not published'),t('Published')),
        '#weight' => 8
    );
    
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save'),
        '#weight' => 9
    );
    
    return $form;
}

function gha_office_form_gha_office_form_alter(&$form, $form_state) {
    $form['#validate'][] = 'gha_office_validate';
    $form['#submit'][] = 'gha_office_submit';
}

function gha_office_validate($form, &$form_state) { // TODO office validation
    // watchdog('gha product', 'validate');
}

function gha_office_submit($form, &$form_state) {
    //print '<pre>';
    //print_r($form['#post']);
    //exit;
    
    // Get Current User
    global $user;
    $account = user_load($user->uid);
    // Create Node    
    $node = new stdClass();
    $node->title = $form['#post']['title'];
    $node->type = 'gha_office';
    $node->created = time();
    $node->changed = $node->created;
    $node->status = $form['#post']['published'];
    $node->promote = 0;
    $node->sticky = 0;
    $node->format = 1;
    $node->uid = $account->uid;
    $node->language = 'en';
    // Load extra fields into node
    $node->description = $form['#post']['description'];
    $node->address = $form['#post']['address'];
    $node->published = $form['#post']['published'];
    
//print '<pre>';
//print_r($node);
//exit;
    
    if (!empty($form['#post']['nid'])){
        $node->nid = $form['#post']['nid'];
        node_save($node);
        drupal_set_message(t('Office <strong>'.$form['#post']['title'].'</strong> saved successfully'),'status');
        $form_state['redirect'] = '/administration/office/list';
    }
    elseif ($node = node_submit($node)) {
        node_save($node);
        drupal_set_message(t('Office <strong>'.$form['#post']['title'].'</strong> saved successfully'),'status');
        $form_state['redirect'] = '/administration/office/list';
    }
    else {
        drupal_set_message(t('There was a problem saving the office, please try again'),'error');
        $form_state['redirect'] = '/administration/office/add';
    }
}

function page_content_office_delete($var=NULL) {
    // watchdog('gha product', 'delete '.$var);
    if (!empty($var)) {
        $delete_node = node_load(array('nid' => $var));
        if (!empty($delete_node) && $delete_node->nid == $var) {
            node_delete($delete_node->nid);
            drupal_set_message(t('Office <strong>'.$form['#post']['title'].'</strong> deleted successfully'),'status');
        }
    }
    else {
        drupal_set_message(t('There was a problem deleting the office, please try again'),'error');
    }

    drupal_goto('administration/office/list');
}

/*
* Extra Node Information hooks
**/
function gha_office_insert($node) {
    // Save Office Info
    db_query("INSERT INTO {GHA_Office} (nid, title, address, description, published)
             VALUES (%d, '%s', '%s', '%s', %d)",
             $node->nid, $node->title, $node->address, $node->description, $node->published);
}
function gha_office_load($node) {
    // Get Office Details
    $additions = db_fetch_object(db_query('SELECT address, description, published FROM {GHA_Office} WHERE nid = %d', $node->nid));
    return $additions;
}
function gha_office_update($node) {
    // Update Office Info
    db_query("UPDATE {GHA_Office} SET address = '%s', description = '%s', published = %d WHERE nid = %d",
        $node->address, $node->description, $node->published, $node->nid);
}
function gha_office_delete(&$node) {
    // Delete Office Details
    db_query('DELETE FROM {GHA_Office} WHERE nid = %d', $node->nid);
}


/*
* Page Functions
*/
function page_content_office_add($var=NULL) {
    $page_content = drupal_get_form('gha_office_form',$var);
    return $page_content;
}

Paul Linney
Owner & Web Developer