function rules_token_form_rules_expression_edit_alter in Rules Token 8
Same name and namespace in other branches
- 2.x rules_token.module \rules_token_form_rules_expression_edit_alter()
- 1.x rules_token.module \rules_token_form_rules_expression_edit_alter()
Adding the links for tokens selection and removing of unnecessary buttons from the forms.
Implements hook_form_FORM_ID_alter().
File
- ./
rules_token.module, line 16 - Contains rules_token.module.
Code
function rules_token_form_rules_expression_edit_alter(&$form, FormStateInterface $form_state, $form_id) {
// Altering the the forms of conditions.
if (isset($form_state
->getStorage()['condition_id'])) {
$condition_id = $form_state
->getStorage()['condition_id'];
switch ($condition_id) {
case 'rules_token_compare_data_with_token':
// Altering the form of 'Compare Data with Token' condition.
// Add link for tokens selection.
$form['context_definitions']['token']['token_tree'] = [
'#theme' => 'token_tree_link',
'#token_types' => 'all',
'#show_restricted' => TRUE,
'#show_nested' => FALSE,
'#weight' => 100,
];
break;
case 'rules_token_compare_token_with_token':
// Altering the form of 'Compare Token with Token' condition.
// Add link for tokens selection.
$form['context_definitions']['token_1']['token_tree'] = [
'#theme' => 'token_tree_link',
'#token_types' => 'all',
'#show_restricted' => TRUE,
'#show_nested' => FALSE,
'#weight' => 100,
];
$form['context_definitions']['token_2']['token_tree'] = [
'#theme' => 'token_tree_link',
'#token_types' => 'all',
'#show_restricted' => TRUE,
'#show_nested' => FALSE,
'#weight' => 100,
];
}
return;
}
// Altering the form of 'Get token value' action.
if (isset($form_state
->getStorage()['action_id'])) {
if ($form_state
->getStorage()['action_id'] == 'rules_token_get_token_value') {
// Add link for tokens selection.
$form['context_definitions']['token']['token_tree'] = [
'#theme' => 'token_tree_link',
'#token_types' => 'all',
'#show_restricted' => TRUE,
'#show_nested' => FALSE,
'#weight' => 100,
];
}
}
}