2

I am using Drupal 7.

I want to create an add-on module for Entity External Rating module.

In that I want to give the form to users where users can select the content types, and based on that selected content type links of twitter and facebook will be displayed. i.e if I select 'article' content type then facebook and twitter links will be displayed on that content type only.

I have created an admin file and configuration form, but i am not sure where should I store the selected values.

I have added the code below which will display the form with listing of all the content types.

function entityrating_addone_admin_settings() {
$form['entityrating_addone_content_type'] = array(
        '#type' => 'fieldset',
        '#title' => t('Select content type for Entity Rating'),
        '#description' => t('Define title excluding settings for each content type.'),
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
);

$node_types = _node_types_build()->names;
foreach ($node_types as $node_type => $node_type_label) {
    $form['entityrating_addone_content_type']['entityrating_addone_content_type_value_' . $node_type] = array(
            '#type' => 'select',
            '#title' => $node_type_label,
            '#default_value' => variable_get('entityrating_addone_content_type_value_' . $node_type, 'none'),
            '#options' => array('none' => t('None'), 'all' => t('All nodes'), 'user' => t('User defined nodes')),
    );
}
return system_settings_form($form);

}

Above code will display the list of all the content type for configuration, but i don't know where to store this values, so i can retrieve while displaying node.

6
  • The form elements saved above will al be stored in the variables table. Are you wanting to move this data or store it somewhere else? If not, then your answer is already in your code with the variable_get() default value.
    – Chapabu
    Commented Sep 11, 2012 at 10:41
  • Actually i checked the variable table but there is no data. Do you have any other way to store the list of content type. Commented Sep 11, 2012 at 10:45
  • So your default value always returns 'none' even if you've saved data?
    – Chapabu
    Commented Sep 11, 2012 at 10:46
  • I don't know, what was the problem, but I uninstalled and installed the module three time and working. I found this in variables table. Thanks for your response Commented Sep 11, 2012 at 10:49
  • And if I want to store in separate table then how to achieve it ? Do have any idea ? Commented Sep 11, 2012 at 10:55

1 Answer 1

1

The form elements saved above will all be stored in the variables table.

Are you wanting to move this data or store it somewhere else? If not, then your answer is already in your code with the variable_get() default value.

system_settings_form()

Add default buttons to a form and set its prefix.

System settings form will store your form data in the variables table and key it with the name of the form element. For example, a form element defined as $form['foo'] will be retrievable by using variable_get('foo', NULL). Because of this I always figure it's a good idea to namespace your form elements as you would functions (i.e. $form['mymodule_foo'])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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