Allowed activity types are a property of case type
This commit is contained in:
parent
e601fde1ef
commit
fd1a0d5156
@ -8,5 +8,8 @@ opencase_entities.oc_case_type.*:
|
|||||||
label:
|
label:
|
||||||
type: label
|
type: label
|
||||||
label: 'Label'
|
label: 'Label'
|
||||||
|
allowedActivityTypes:
|
||||||
|
type: sequence
|
||||||
|
label: 'Allowed Activity Types'
|
||||||
uuid:
|
uuid:
|
||||||
type: string
|
type: string
|
||||||
|
@ -55,4 +55,10 @@ class OCCaseType extends ConfigEntityBundleBase implements OCCaseTypeInterface {
|
|||||||
*/
|
*/
|
||||||
protected $label;
|
protected $label;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activity types that can be attached to this type of case.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $allowedActivityTypes;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,17 @@ class EntityTypeRelationsWidget {
|
|||||||
'#type' => 'checkboxes',
|
'#type' => 'checkboxes',
|
||||||
'#options' => $options
|
'#options' => $options
|
||||||
);
|
);
|
||||||
|
$activity_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('oc_activity');
|
||||||
|
$options = array();
|
||||||
|
foreach($activity_types as $machine_name => $info) {
|
||||||
|
$options[$machine_name] = $info['label'];
|
||||||
|
}
|
||||||
|
$form['allowed_activity_types'] = array(
|
||||||
|
'#title' => t('Activity types'),
|
||||||
|
'#description' => t('Types of activities that can be logged against this case.'),
|
||||||
|
'#type' => 'checkboxes',
|
||||||
|
'#options' => $options
|
||||||
|
);
|
||||||
$form['actions']['submit']['#submit'][] = array($this, 'submit');
|
$form['actions']['submit']['#submit'][] = array($this, 'submit');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,6 +48,11 @@ class EntityTypeRelationsWidget {
|
|||||||
$case_type = $form['id']['#default_value'];
|
$case_type = $form['id']['#default_value'];
|
||||||
$allowedActorTypes = EntityTypeRelations::getAllowedActorTypesForCaseType($case_type);
|
$allowedActorTypes = EntityTypeRelations::getAllowedActorTypesForCaseType($case_type);
|
||||||
$form['allowed_actor_types']['#default_value'] = $allowedActorTypes;
|
$form['allowed_actor_types']['#default_value'] = $allowedActorTypes;
|
||||||
|
$caseTypeConfig = \Drupal::entityTypeManager()->getStorage('oc_case_type')->load($case_type);
|
||||||
|
$allowedActivityTypes = $caseTypeConfig->get('allowedActivityTypes');
|
||||||
|
if ($allowedActivityTypes) {
|
||||||
|
$form['allowed_activity_types']['#default_value'] = $allowedActivityTypes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,5 +72,8 @@ class EntityTypeRelationsWidget {
|
|||||||
}
|
}
|
||||||
$base_field_override->setSetting('handler_settings', ['target_bundles' => $form_state->getValue('allowed_actor_types')]);
|
$base_field_override->setSetting('handler_settings', ['target_bundles' => $form_state->getValue('allowed_actor_types')]);
|
||||||
$base_field_override->save();
|
$base_field_override->save();
|
||||||
|
$caseTypeConfig = \Drupal::entityTypeManager()->getStorage('oc_case_type')->load($case_type_machine_name);
|
||||||
|
$caseTypeConfig->set('allowedActivityTypes', $form_state->getValue('allowed_activity_types'));
|
||||||
|
$caseTypeConfig->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user