Skip to content

Commit

Permalink
Resolves bundle type restriction settings via XML profile issue #1546
Browse files Browse the repository at this point in the history
  • Loading branch information
collectiveaccess committed May 5, 2024
1 parent c15804c commit b36d485
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
5 changes: 3 additions & 2 deletions app/models/ca_editor_ui_screens.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ static public function loadScreen($pm_ui, $pm_screen, $pa_options=null) {
* @param int $pn_rank Optional value that determines sort order of bundles in the screen. If omitted, placement is added to the end of the screen.
* @param array $pa_options Optional array of options. Supports the following options:
* user_id = if specified then add will fail if specified user does not have edit access for the display
* @return int Returns placement_id of newly created placement on success, false on error
* returnInstance = return newly created ca_editor_ui_bundle_placements instance instead of placement_id
* @return int|ca_editor_ui_bundle_placements Returns placement_id of newly created placement on success (or ca_editor_ui_bundle_placements instance if returnInstance option is set), false on error
*/
public function addPlacement($ps_bundle_name, $ps_placement_code, $pa_settings, $pn_rank=null, $pa_options=null) {
if (!($vn_screen_id = $this->getPrimaryKey())) { return null; }
Expand Down Expand Up @@ -315,7 +316,7 @@ public function addPlacement($ps_bundle_name, $ps_placement_code, $pa_settings,

// Dependent field visibility config relies on UI config
if ($this->getAppConfig()->get('enable_dependent_field_visibility')) { CompositeCache::flush('ca_metadata_elements_available_settings'); }
return $t_placement->getPrimaryKey();
return caGetOption('returnInstance', $pa_options, false) ? $t_placement : $t_placement->getPrimaryKey();
}
# ------------------------------------------------------
/**
Expand Down
24 changes: 13 additions & 11 deletions install/inc/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1233,17 +1233,19 @@ public function processUserInterfaces() {
}
}

$settings = $this->_processSettings(null, $placement['settings'], [
'table' => $table,
'leftTable' => $table,
'rightTable' => \Datamodel::tableExists($type) ? $type : null,
'settingsInfo' => array_merge($t_placement->getAvailableSettings(), is_array($available_bundles[$bundle]['settings']) ? $available_bundles[$bundle]['settings'] : []),
'source' => "UserInterface:{$ui_code}:Screen {$screen_idno}:Placement {$placement_code}"
]);
$this->logStatus(_t('Adding bundle %1 with code %2 for screen with code %3 and user interface with code %4', $bundle, $placement_code, $screen_idno, $ui_code));

if (!$t_ui_screens->addPlacement($bundle, $placement_code, $settings, null, ['additional_settings' => $available_bundles[$bundle]['settings']])) {
if (!($t_placement = $t_ui_screens->addPlacement($bundle, $placement_code, $settings, null, ['additional_settings' => $available_bundles[$bundle]['settings'], 'returnInstance' => true]))) {
$this->logStatus(join("; ", $t_ui_screens->getErrors()));
} else {
$settings = $this->_processSettings($t_placement, $placement['settings'], [
'table' => $table,
'leftTable' => $table,
'rightTable' => \Datamodel::tableExists($type) ? $type : null,
'settingsInfo' => array_merge($t_placement->getAvailableSettings(), is_array($available_bundles[$bundle]['settings']) ? $available_bundles[$bundle]['settings'] : []),
'source' => "UserInterface:{$ui_code}:Screen {$screen_idno}:Placement {$placement_code}"
]);
$t_placement->update();
}
}

Expand Down Expand Up @@ -2467,7 +2469,7 @@ private function _processSettings($t_instance, $settings, $options=null) {
}

$datatype = (int)$t_instance ? $t_instance->get('datatype') : null;
if ($setting_name === 'restrictToTypes' && $t_authority_instance = \AuthorityAttributeValue::elementTypeToInstance($datatype)){
if (($setting_name === 'restrictToTypes') && ($t_authority_instance = \AuthorityAttributeValue::elementTypeToInstance($datatype))){
if ($t_authority_instance instanceof \BaseModelWithAttributes && is_string($setting_value)){
$type_id = $t_authority_instance->getTypeIDForCode($setting_value);
if ($type_id){
Expand All @@ -2488,9 +2490,9 @@ private function _processSettings($t_instance, $settings, $options=null) {
} else {
// some settings allow multiple values under the same key, for instance restrict_to_types.
// in those cases $settings[$setting_name] becomes an array of values
if (isset($settings_list[$setting_name]) && (!isset($settings_info[$setting_name]) || ($settings_info[$setting_name]['multiple']))) {
if (!isset($settings_info[$setting_name]) || ($settings_info[$setting_name]['multiple'] ?? false)) {
if (!is_array($settings_list[$setting_name])) {
$settings_list[$setting_name] = array($settings_list[$setting_name]);
$settings_list[$setting_name] = [];
}
$settings_list[$setting_name][] = $setting_value;
} else {
Expand Down
4 changes: 2 additions & 2 deletions install/inc/Parsers/XMLProfileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* ----------------------------------------------------------------------
*
* Software by Whirl-i-Gig (http://www.whirl-i-gig.com)
* Copyright 2021-2023 Whirl-i-Gig
* Copyright 2021-2024 Whirl-i-Gig
*
* For more information visit http://www.CollectiveAccess.org
*
Expand Down Expand Up @@ -599,7 +599,7 @@ protected function processUIBundles($bundles) {
foreach($bundles->children() as $bundle) {
$code = self::getAttribute($bundle, "code");
$bundle_name = trim((string)$bundle->bundle);
$include_subtypes = self::getAttribute($ui, "includeSubtypes");
$include_subtypes = self::getAttribute($bundle, "includeSubtypes");

$type_restrictions = self::processTypeRestrictionStrings(self::getAttribute($bundle, "typeRestrictions"), $include_subtypes);

Expand Down

0 comments on commit b36d485

Please sign in to comment.