Skip to content
Snippets Groups Projects
Commit a97f1706 authored by Steven Ayers's avatar Steven Ayers
Browse files

Issue #3473842 by bluegeek9: Governance setting roles should be inclusive

parent ac3678e9
No related branches found
No related tags found
1 merge request!7Issue #3473842 by bluegeek9: Governance setting roles should be inclusive
Pipeline #281518 failed
langcode: en
status: true
dependencies:
module:
- node
id: node.knowledge_governance
field_name: knowledge_governance
entity_type: node
type: boolean
settings: { }
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
langcode: en
status: true
dependencies:
module:
- node
- user
id: node.knowledge_governance_user
field_name: knowledge_governance_user
entity_type: node
type: entity_reference
settings:
target_type: user
module: core
locked: false
cardinality: -1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
langcode: en
status: true
dependencies:
module:
- node
- options
- user
enforced:
module:
- knowledge
id: node.knowledge_governance_user_role
field_name: knowledge_governance_user_role
entity_type: node
type: entity_reference
settings:
target_type: user_role
module: core
locked: false
cardinality: -1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
......@@ -344,17 +344,30 @@ function knowledge_form_node_form_alter(&$form, $form_state) {
}
if (array_key_exists('knowledge_governance_user_role', $form)) {
$governance_settings = \Drupal::config('knowledge.governance.settings');
$exclude = $governance_settings->get('roles.exclude');
$roles = $governance_settings->get('roles');
$roles = array_filter($roles);
$form['knowledge_governance_user_role']['#group'] = 'governance';
$form['knowledge_governance_user_role']['#states']['visible'] = [
':input[name="knowledge_governance"]' => ['value' => 1],
];
foreach ($exclude as $x) {
unset($form['knowledge_governance_user_role']['widget']['#options'][$x]);
$roles_remove = [];
$role_options = $form['knowledge_governance_user_role']['widget']['#options'] ?? [];
foreach ($role_options as $role => $role_label) {
$remove = !empty($roles) && !in_array($role, $roles);
if ($role == '_none') {
$remove = TRUE;
}
if ($remove) {
$roles_remove[] = $role;
}
}
foreach ($roles_remove as $role) {
unset($form['knowledge_governance_user_role']['widget']['#options'][$role]);
}
}
}
......@@ -369,7 +382,9 @@ function _knowledge_governance_form_validate(&$form, $form_state) {
if ($governance) {
$user_roles = $form_state->getValue('knowledge_governance_user_role');
$users = $form_state->getValue('knowledge_governance_user');
$users = $users['target_id'] ?? NULL;
if (empty($user_roles) && empty($users)) {
$form_state->setErrorByName('knowledge_governance_user_role', t('User or Role must have a value when Governace is Compliance.'));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment