1

I'm trying to create an exclude list of sorts that is configurable via the variable admin interface. I have created lots of single value variables, but never a variable as an array where through the interface the user can "Add" another field/value like you can on nodes with "unlimited" field values.

Can this be done with the Variable module?

0

I'm not sure how well it will scale, but here is an example for a multiple variable in the Variable issue queue https://drupal.org/node/2019629

<?php
/**
 * Implements hook_variable_info().
 */
function MY_MODULE_variable_info($options) {
    // Use '[custom]' as a placeholder for the variable name.
    // It will set these properties ('type' and 'multiple') automatically.
    $variables['custom_vars_[custom]'] = array(
        'title'        =>    t('Custom multiple variable'),
        'group'        =>    'site_information',
        'repeat'    =>    array('type' => 'string', 'default' => 'some default value'),
    );
    // if you need to expose your custom variable as token
    // you have to set 'token' key as TRUE,
    // and ought to set the properties (name, description and type)
    // Notice that 'first' it is a name of variable defined in custom_variable_options().
    $variables['custom_vars_first'] = array(
                    'token' => TRUE,
                    'title' => 'Custom variable',                        // name
                    'description' => 'My first variable description',    // description
                    'type'    => 'string'                                    // type
                    );
  return $variables;
}
/**
 * Implements hook_variable_type_info().
 * @return
 *  An array of information defining variable types.
 *  The array contains a sub-array for each variable type
 *  with the variable type as the key.
 *  The possible attributes are the same as for hook_variable_info().
 */
function MY_MODULE_variable_type_info() {
    $type['custom'] = array(
        'title' => t('Custom variables'),
        'type'    => 'select',
        'options callback' => 'custom_variable_options',
    );
    return $type;
}
/**
 * Callback for custom options.
 * @return
 *  An array of variables with the variable name as the key.
 */
function custom_variable_options($variable, $options) {
  return array(
    'first'  => t('My first variable', array(), $options),
    'second' => t('My second variable', array(), $options),
    'third'  => t('My third variable', array(), $options),
  );
}

I dont think this is exactly what you want -- but may give you some ideas (it does the multiple value per "variable". I'm not sure offhand how you build a variable_form to edit the values in function custom_variable_options().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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