-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DS-1656] Add a new field 'Alert Style' for Alert nodes #146
Conversation
48ad0fb
to
c8775b4
Compare
/** | ||
* Implements hook_form_FORM_ID_alter(). | ||
*/ | ||
function openy_node_alert_form_node_alert_edit_form_alter(array &$form, FormStateInterface $form_state, $form_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's apply the DRY principle here and avoid code duplication.
Something like:
$fields_to_toggle = [
'field_alert_color',
'field_alert_text_color',
'field_alert_icon_color',
];
foreach ($fields_to_toggle as $field_name) {
$form[$field_name]['widget']['#states'] = [
'visible' => [
':input[name="field_alert_style"]' => ['value' => 'classic'],
],
];
}
openy_node_alert.install
Outdated
$configs = [ | ||
'field.field.node.alert.field_alert_color' => [ | ||
'required', | ||
], | ||
'field.field.node.alert.field_alert_icon_color' => [ | ||
'required', | ||
], | ||
'field.field.node.alert.field_alert_text_color' => [ | ||
'required', | ||
] | ||
]; | ||
$config_updater = \Drupal::service('openy_upgrade_tool.param_updater'); | ||
foreach ($configs as $config_name => $params) { | ||
$config = $config_dir . $config_name . '.yml'; | ||
foreach ($params as $param) { | ||
$config_updater->update($config, $config_name, $param); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OPTIONAL:
Can also be more compact:
$configs = [
'field.field.node.alert.field_alert_color',
'field.field.node.alert.field_alert_icon_color',
'field.field.node.alert.field_alert_text_color',
];
foreach ($configs as $config_name) {
$config_file = $config_dir . $config_name . '.yml';
$config_updater->update($config_file, $config_name, 'required');
}
Thanks @aleevas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small fixes needed
The "How to check" instructions are included in the Jira issue DS-1656 .