I am not sure if the variable module really adds value for me, other than having only one place where to change the default value (and that is actually a defined constant till now in my modules).

so let's take a look in the latest example where I used a variable:
I created a block showing x entries of unread something, where x needed to be configurable. so I added the configuration page for that block handling the variable configuration. Pretty straight forwarded:

<?php
define
('mymodule_unread_block_default', 5);

/**
 * Implements hook_block_info().
 */
function mymodule_block_info() {
 
$blocks['mymodule_unread_block'] = array(
   
'info' => t('Privatemsg: block of unread messages'),
  );

  return
$blocks;
}

/**
 * Implements hook_block_configure().
 */
function mymodule_block_configure($delta = '') {
 
$form = array();
  if (
$delta == 'mymodule_unread_block') {
   
$form['mymodule_unread_block'] = array(
     
'#type' => 'select',
     
'#title' => t('unread count'),
     
'#options' => array(
       
5 => '5',
       
10 => '10',
       
15 => '15',
       
20 => '20',
       
25 => '25'
      
),
     
'#description' => t('How many unread messages shall be shown'),
     
'#default_value' => variable_get('mymodule_unread_block', mymodule_unread_block_default),
    );
  }
  return
$form;
}

/**
 * Implements hook_block_save().
 */
function mymodule_block_save($delta = '', $edit = array()) {
  if (
$delta == 'mymodule_unread_block') {
   
variable_set('mymodule_unread_block', $edit['mymodule_unread_block']);
  }
  return;
}
...
?>

actually adding the variable definition would cause me to edit the variable form (if I use it for variable) at two locations, the one for block configuration and the one that defines the variable.

<?php
/**
 * implements hook_variable_info()
 */
function mymodule_variable_info() {
 
$variables['mymodule_unread_block']=array(
   
'title'=>'max unread messages',
   
'description' => t('How many unread messages shall be shown'),
   
'type' => 'number',
   
'element' => array(
     
'#type' => 'select',
     
'#title' => t('unread count'),
     
'#options' => array(
       
5 => '5',
       
10 => '10',
       
15 => '15',
       
20 => '20',
       
25 => '25'
      
),
     
'#description' => t('How many unread messages shall be shown'),
    ),
  );
  return
$variables;
}

/**
 * Implements hook_block_info().
 */
function mymodule_block_info() {
 
$blocks['mymodule_unread_block'] = array(
   
'info' => t('Privatemsg: block of unread messages'),
  );

  return
$blocks;
}

/**
 * Implements hook_block_configure().
 */
function mymodule_block_configure($delta = '') {
 
$form = array();
  if (
$delta == 'mymodule_unread_block') {
   
$form['mymodule_unread_block'] = array(
     
'#type' => 'select',
     
'#title' => t('unread count'),
     
'#options' => array(
       
5 => '5',
       
10 => '10',
       
15 => '15',
       
20 => '20',
       
25 => '25'
      
),
     
'#description' => t('How many unread messages shall be shown'),
     
'#default_value' => variable_get_value('mymodule_unread_block'),
    );
  }
  return
$form;
}

/**
 * Implements hook_block_save().
 */
function mymodule_block_save($delta = '', $edit = array()) {
  if (
$delta == 'mymodule_unread_block') {
   
variable_set('mymodule_unread_block', $edit['mymodule_unread_block']);
  }
  return;
}
...
?>

so how does variable add any more value here?
does it help be creating better features?
does it somehow help to get stuff in version control?
does variable introduce more overhead if I come to migrating my modules from d7 to d8?
what are the plans for d8?
do you still use other configuration pages/ block configurations to manage your variable value?

Comments

Jose Reyero’s picture

Status:Active» Closed (won't fix)

Now I'm wondering how reading through these issues and replying to them adds value for me.

Please feel free not to use the module. Have fun.

Andre-B’s picture

excellent reply skipping 5 questions that other module developers might/ probably have as well.

Jose Reyero’s picture

Status:Closed (won't fix)» Closed (fixed)

They were actually 6 questions, not 5 :-)

Ok, let's try...

1. Once you have defined your variable/s once, you can create multiple forms using either variable_module_form(), variable_group_form() or variable_edit_form()

2. Even if it doesn't "add value" for your specific module, it provides other modules with meta-information about your variables so they can translate them, set for each domain, etc... So let's say it adds value to the world.

3. No plans for d8 since the new config system will replace all the variable system.

Andre-B’s picture

great thanks so far, do you still use dedicated configuration forms for your module or just let variable ui handle the configuration? :)

Jose Reyero’s picture

The second:
<?php
/**
* Implements hook_menu().
*/
function i18n_menu() {
$items['admin/config/regional/i18n'] = array(
'title' => 'Multilingual settings',
'description' => 'Configure extended options for multilingual content and translations.',
'page callback' => 'drupal_get_form',
'page arguments' => array('variable_module_form', 'i18n'),
'access arguments' => array('administer site configuration'),
'weight' => 10,
);
...
return $items;
}

Jose Reyero’s picture

Issue summary:View changes

Updated issue summary.