Drupal7 .install script not working - drupal

I am trying to convert my module from drupal6 to drupal 7 this is my code. The database table is not created.
function example_install() {
drupal_install_schema('example');
}
/**
* Implements hook_schema().
*/
function example_schema() {
$schema['example'] = array(
'description' => 'example settings',
'fields' => array(
'name' => array(
'description' => 'name',
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
),
'age' => array(
'description' => 'age',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
),
) ,
);
return $schema;
}
Can any one explain whats wrong.

You don't want to run drupal_install_schema() yourself in Drupal 7, hook_schema() is called automatically if it exists in the .install file. That will probably cause a few problems but you'd still expect the table to be created at least once.
Once you've removed hook_install() try uninstalling (not just disabling) your module, then re-enabling it. I recommend the Devel module to do this as it provides a page (devel/reinstall) where you can easily force a reinstall of a module.
If you don't want to do that though, go to the modules page, disable the module, then click the 'Uninstall' tab at the top to uninstall it fully. Then go back to the modules page and re-enable it.
Doing this should force Drupal to re-run your hook_schema() script and the table should be created.

Related

How to add a custom Rules "action" in Drupal?

I'm using the Rules module in Drupal 7, and I tried to add a new Rules "Action"
I followed the steps described in How to create an custom rule action using hook_rules_action_info? to create a custom rule action using hook_rules_action_info:
I tried to create a sample file (save_nid.rules.inc) in the folder /rules/module/.
And I also tried to create a module folder in /site/all/module/save_nid/.
My code in save_nid.rules.inc looks like so:
function rules_save_nid_action_info() {
return array(
'save_nid_action' => array(
'label' => t('Custom Action'),
'parameter' => array(
'param1' => array(
'type' => 'int',
'label' => t('Parameter Label'),
),
'param2' => array(
'type' => 'commerce_order',
'label' => t('Parameter Label2'),
),
),
'configurable' => FALSE,
'group' => t('ABC Custom module action'),
'callbacks' => array(
'execute' => 'abc_custom_action',
),
),
}
After I cleared the Drupal cache, I didn't see my "custom rule" in the list.
What am I missing or doing wrong?
In your case, the machine name of your custom module seems to be save_nid.
So if you want to use hook_rules_action_info in your module, your function needs to be named save_nid_rules_action_info, instead of rules_save_nid_action_info.
Not sure if it is the "only" problem why you can't get it to work, but at least it is "a" problem you need to address.
PS: make sure to save that custom coding in your custom module's folder (in /site/all/module/save_nid/).

Creating custom options for "List-item" option in Option Tree plugin for wordpress

I have a problem, I need to change the default options for a “List-item” option in Option tree . Right now the default are “Title/Image/Link/Descriptions” .. I want to remove them and add my own. I have written this code:
array(
'id' => 'academic_success_content',
'label' => 'Academic Success Content',
'desc' => 'Enter the academic success content. It will appear in the home page in list items format',
'std' => '',
'type' => 'list-item',
'section' => 'academic_perfomance',
'settings' => array(
array(
'id' => 'academic_success',
'label' => 'Academic Success',
'type' => 'textarea-simple',
)
)
),
But when I preview the themes options , the default list item "title" is still there and I only want to see the Academic Success textarea. What should I do?
I also suffered from the same situation.
And after that, I use the older version of "list-item" and "gallery".
This has worked well. Ex: v2.4.6
Is the theme options page being included?
You'll need to reference it in your functions.php, something to the effect of:
require_once locate_template('/path-to-your/theme-options.php' );

Drupal 7 - how to allow file extensions for field

After creating multiple fields with the help of the installation profile I am now also trying to figure out how I can add the allowed file extensions in the installation profile. Here is my code so far:
'name' => 'attachment',
'type' => 'file',
'settings' => array(
'allowed_file_extensions' => array('txt pdf'),
),
The allowed_file_extensions was just a test to see if it works but it doesn't it gives an fatal PHP error. (** PHP Fatal error: Unsupported operand types** )
How can I add the file extensions at the field?
PS: I also tried putting the settings in the instance, this gives the same error.
Oke, I was having this problem for the last three days. Now after a few hours after I posted this question I solved the problem.
For those who have the same question or problem here is what solved it for me and what the right way is to add settings. The settings can be different for each instance so the settings go at the instance creation and not the field itself.
Here is an example on how it is supposed to be:
$instance = array(
'field_name' => 'file'
'entity_type' => 'node',
'bundle' => 'article',
'label' => 'Attachment',
'description' => 'Add an attachment here',
'required' => TRUE,
'settings' => array(
'max_filesize' => '512',
'file_extensions' => 'zip txt pdf docx'
),
);
field_create_instance($instance);
The settings field is not required but i was using an foreach because I generate multiple fields and instances at once, if you do this and you have settings at 1 of your generated field instances then you have to add settings at all instances or check if it is there or not.
I hope my experience can help any of you out when having the same problem.

Drupal 6 module install file not creating tables in database

I'm using the Schema API to create tables for my module on Drupa 6.17, but the tables just do not get created in the database. I have the Schema module installed, and it tells me that while the schema for my module is recognized, its table is not in the database. It comes up under Missing:
Tables in the schema that are not present in the database.
test
* test_table
Here are the contents for my test.install file.
<?php
// $Id$
function test_schema() {
$schema['test_table'] = array(
'description' => t('Test table'),
'fields' => array(
'nid' => array(
'description' => t('test field'),
'type' => 'serial',
'not null' => TRUE,
),
'options' => array(
'description' => t('other test field'),
'type' => 'text',
'not null' => FALSE,
),
),
'primary key' => array('nid'),
);
return $schema;
}
function test_install() {
drupal_install_schema('test');
}
function test_uninstall() {
drupal_uninstall_schema('test');
}
if you want to add module install after the module creation you need to remove the record from system table in your drupal db, and then enable it again.
disable your module and save
goto 'system' table and find your module there
remove that record
enable your module and save
Edit:
Here is code I just wrote that works. Follow as example:
/**
* Implementation of hook_schema().
*/
function action_alert_schema() {
$schema['action_alert'] = array(
'description' => 'Action Alert table.',
'fields' => array(
'aid' => array(
'description' => 'The serial ID.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'nid' => array(
'description' => 'The primary identifier of the node.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'uuid' => array(
'description' => 'The session id of the user if the UID is not present.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
),
),
'primary key' => array('aid'),
);
return $schema;
}
/**
* Implementation of hook_install().
*/
function action_alert_install() {
drupal_install_schema('action_alert');
}
/**
* Implementation of hook_uninstall().
*/
function action_alert_uninstall() {
drupal_uninstall_schema('action_alert');
}
Drupal only runs a module's hook_install() once when you first enable the module. Unless you go through and disable, uninstall, and then re-enable the module will your module's hook_install() get called ever again.
If you had already created a release of your module and are wanting to add a schema to existing installs, you will want to add an implementation of hook_update_N() that calls db_create_table().
I would like to share with you my experiences with this error on Drupal 6. In my first-ever module I had three tables. I had an entry for each in my hook_schema (called education_schema):
function education_schema()
{
$schema['education_course'] = array( /* ... */ );
$schema['education_market'] = array( /* ... */ );
$schema['education_event'] = array( /* ... */ );
}
In my hook_install, I initially had the following:
function education_install()
{
drupal_install_schema('education_course');
drupal_install_schema('education_market');
drupal_install_schema('education_event');
}
No tables were creating at module install. Why? I had no idea: no errors to be seen anywhere in the logs. Eventually I found out about the PHP extension xdebug, which, when used in education_install revealed that drupal_install_schema failed because it could not find the routines education_course_schema, education_course_market and education_course_event. At that point the solution was quite obvious:
function education_install()
{
drupal_install_schema('education');
}
And voila, it worked!
So, I learned that drupal_install_schema does not log any error when it fails, that only one call to drupal_install_schema is required and that it installs all schemas that you return in the array, that the API documentation of drupal_install_schema is worth reading, and finally that xdebug is a very handy utility!

Managing several custom content types from one module(drupal)

Is it possible to declare and manage several custom content types inside one module? I'm creating a site that needs four custom content types and I'd like to manage them from one module instead of creating module for every content type. After some testing, I found out that it seems impossible. Because, unless hook_form and content type share the same name of module, drupal doesn't call hook_form.
Here's how I'd like to do -
function mycontent_node_info(){
return array(
'mycontent1' => array(
'name' => t('....'),
'module' => 'mycontent',
'description' => t('...),
'has_title' => TRUE,
'title_label' => t('Title'),
'has_body' => TRUE,
'body_label' => t('content body'),
),
'mycontent2' => array(
.......
),
'mycontent3' => array(
......
),
'mycontent4' => array(
......
),
);
}
function mycontent1_form(&$node){
$form['control1'] = array(
'#type' => 'select',
'#options' => array(
'0' => t('selection 1'),
'1' => t('selection 2'),
),
'#attributes' => array('id'=>'control1'),
);
$form['control2'] = array(
'#type' => 'select',
'#options' => array(
'0' => t('1'),
'1' => t('2'),
'2' => t('3'),
'3' => t('4'),
),
'#attributes' => array('id'=>'control2'),
);
return $form;
}
function mycontent2_form(&$node){
....
}
function mycontent3_form(&$node){
....
}
function mycontent4_form(&$node){
....
}
Am I doing something wrong here or is not possible and there's no alternative other than creating module for every content types. I appreciate much your help.
The prefix for all your hooks should be the name of your module, i.e. mycontent_node_info() and mycontent_form(&$node). I think the content type itself can be called whatever you want but by convention anything global that you define in a module should be prefixed with the name of the module to avoid namespace problems. So your content becomes mycontent_type1, mycontent_type2, etc... As for dealing with hook_form, I guess the way to do it is to check the type of the node passed in and act accordingly.
You might try using the Features module (http://drupal.org/project/features) to export your content types. It auto generates the code to make this work, and you can have a look at what is going wrong with your code.

Resources