You are here

function conditional_fields_effects in Conditional Fields 7.3

Builds a list of supported effects that may be applied to a dependent field when it changes from visible to invisible and viceversa. The effects may have options that will be passed as Javascript settings and used by conditional_fields.js.

Return value

An associative array of effects. Each key is an unique name for the effect. The value is an associative array:

  • label: The human readable name of the effect.
  • states: The states that can be associated with this effect.
  • options: An associative array of effect options names, field types, descriptions and default values.
1 call to conditional_fields_effects()
conditional_fields_dependency_edit_form in includes/conditional_fields.admin.inc
Dependency edit form.

File

./conditional_fields.module, line 1524
Define dependencies between fields based on their states and values.

Code

function conditional_fields_effects() {
  $effects = array(
    'show' => array(
      'label' => t('Show/Hide'),
      'states' => array(
        'visible',
        '!visible',
      ),
    ),
    'fade' => array(
      'label' => t('Fade in/Fade out'),
      'states' => array(
        'visible',
        '!visible',
      ),
      'options' => array(
        'speed' => array(
          '#type' => 'textfield',
          '#description' => t('The speed at which the animation is performed, in milliseconds.'),
          '#default_value' => 400,
        ),
      ),
    ),
    'slide' => array(
      'label' => t('Slide down/Slide up'),
      'states' => array(
        'visible',
        '!visible',
      ),
      'options' => array(
        'speed' => array(
          '#type' => 'textfield',
          '#description' => t('The speed at which the animation is performed, in milliseconds.'),
          '#default_value' => 400,
        ),
      ),
    ),
    'fill' => array(
      'label' => t('Fill field with a value'),
      'states' => array(
        '!empty',
      ),
      'options' => array(
        'value' => array(
          '#type' => 'textfield',
          '#description' => t('The value that should be given to the field when automatically filled.'),
          '#default_value' => '',
        ),
        'reset' => array(
          '#type' => 'checkbox',
          '#title' => t('Restore previous value when untriggered'),
          '#default_value' => 1,
        ),
      ),
    ),
    'empty' => array(
      'label' => t('Empty field'),
      'states' => array(
        'empty',
      ),
      'options' => array(
        'value' => array(
          '#type' => 'hidden',
          '#description' => t('The value that should be given to the field when automatically emptied.'),
          '#value' => '',
          '#default_value' => '',
        ),
        'reset' => array(
          '#type' => 'checkbox',
          '#title' => t('Restore previous value when untriggered'),
          '#default_value' => 1,
        ),
      ),
    ),
  );

  // Allow other modules to modify the effects.
  drupal_alter('conditional_fields_effects', $effects);
  return $effects;
}