i was trying to change the node create form for my custom node type. i activated the form events and created a rule to hide the preview button and change the value of the save button to "create". rules debug output says both actions get executed, but only the preview button gets hidden, the save button value is still "save".

Comments

DieterWeb’s picture

Status: Active » Fixed

buttons use "value" as the array index for the label, not "default_value", therefore the default value action doesnt replace the button label. i've created a custom action to deal with this. here is the code for anyone who is interested:


/**
* Implementation of hook_rules_action_info().
* @ingroup rules
*/
function foo_rules_action_info() {
  return array(
    'foo_forms_action_set_button' => array(
      'label' => t('Set the value of a form button'),
      'arguments' => array(
        'form' => array('type' => 'form', 'label' => t('Form')),
        'element' => array(
          'type' => 'string',
          'label' => t('Form element ID'),
          'description' => t('The element that should be targeted.') .' '. _rules_forms_element_description(),
        ),
        'value' => array(
          'type' => 'string',
          'label' => t('Label'),
          'description' => t('The value that will be used as a button label'),
        ),
      ),
      'module' => 'Rules Forms',
    ),
  );
}

function foo_forms_action_set_button(&$form, $element, $value) {
  $form_element = &_rules_forms_get_element($form, $element);
  if (empty($form_element) || !array_key_exists('#value', $form_element)) {
    return;
  }
  
  $form_element['#value'] = t($value);
}

/**
 * Label callback for set button label action.
 */
function foo_forms_action_set_button_label($settings, $argument_labels) {
  return t("Set the label on button '@element'", array('@element' => $settings['element']));
}

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.