For custom action configurations we need feature support for states attribute similar to #state of form API.
gg24 created an issue. See original summary.
#states like functionality is directly not supported when defining parameters for a rule action in hook_rules_action_info()
hook_rules_action_info()
This can be achieved by attaching a 'form_alter' callback function to our action. Eg:
/** * Implements hook_rules_action_info(). */ function rules_joke_rules_action_info() { $actions['crack_chuk_norris_joke'] = array( 'label' => 'Display a Chuck Norris Joke', 'group' => t('System'), 'parameter' => array( 'default_message' => array( 'label' => 'Default Message', 'description' => 'Message to show if joke not found.', 'type' => 'text', 'optional' => TRUE, ), 'country' => array( 'label' => 'Your Country', 'description' => 'Select your country.', 'type' => 'text', 'optional' => TRUE, 'options list' => '_get_countries', ), ), 'callbacks' => array( 'form_alter' => 'rules_joke_test_form_alter', ), ); return $actions; } /** * Get countries */ function _get_countries() { return array( 'India' => 'India', 'Pakistan' => 'Pakistan', 'Uganda' => 'Uganda' ); }
Callback method :
/** * Callback method. */ function rules_joke_test_form_alter(&$form, &$form_state, $options, RulesAbstractPlugin $element) { $form['parameter']['default_message'] += array( '#attributes' => array( 'class' => array('custom-class'), ), '#states' => array( 'invisible' => array( '#edit-parameter-country-settings-country' => array('value' => 'Pakistan'), ), ), ); }
Awesome! @jaykandari. This works for me.
Thanks!
This was answered by #2.
Comments
Comment #2
jaykandari#states like functionality is directly not supported when defining parameters for a rule action in
hook_rules_action_info()This can be achieved by attaching a 'form_alter' callback function to our action. Eg:
Callback method :
Comment #3
gg24 commentedAwesome! @jaykandari. This works for me.
Thanks!
Comment #4
tr commentedThis was answered by #2.
Comment #5
tr commented