diff --git a/application/src/Form/UserForm.php b/application/src/Form/UserForm.php index df22116270..26b5abc426 100644 --- a/application/src/Form/UserForm.php +++ b/application/src/Form/UserForm.php @@ -2,6 +2,7 @@ namespace Omeka\Form; use Omeka\Form\Element\ResourceSelect; +use Omeka\Form\Element\SiteSelect; use Omeka\Permissions\Acl; use Omeka\Settings\Settings; use Omeka\Settings\UserSettings; @@ -122,7 +123,9 @@ public function init() if (null === $locale) { $locale = $this->settings->get('locale'); } - $this->get('user-settings')->add([ + + $settingsFieldset = $this->get('user-settings'); + $settingsFieldset->add([ 'name' => 'locale', 'type' => 'Omeka\Form\Element\LocaleSelect', 'options' => [ @@ -135,7 +138,7 @@ public function init() 'id' => 'locale', ], ]); - $this->get('user-settings')->add([ + $settingsFieldset->add([ 'name' => 'default_resource_template', 'type' => ResourceSelect::class, 'attributes' => [ @@ -158,6 +161,21 @@ public function init() ], ], ]); + $settingsFieldset->add([ + 'name' => 'default_item_sites', + 'type' => SiteSelect::class, + 'attributes' => [ + 'value' => $userId ? $this->userSettings->get('default_item_sites', null, $userId) : [], + 'class' => 'chosen-select', + 'data-placeholder' => 'Select sites', // @translate + 'multiple' => true, + 'id' => 'default_sites', + ], + 'options' => [ + 'label' => 'Default sites for items', // @translate + 'empty_option' => '', + ], + ]); if ($this->getOption('include_password')) { if ($this->getOption('current_password')) { diff --git a/application/view/omeka/admin/item/manage-sites.phtml b/application/view/omeka/admin/item/manage-sites.phtml index 8d0ca847dd..a0ae950a75 100644 --- a/application/view/omeka/admin/item/manage-sites.phtml +++ b/application/view/omeka/admin/item/manage-sites.phtml @@ -1,14 +1,24 @@ sites() - : $this->api()->search('sites', ['assign_new_items' => true])->getContent(); +if ($item) { + $siteRepresentations = $item->sites(); +} else { + $siteRepresentations = $this->api()->search('sites', ['assign_new_items' => true])->getContent(); + + $userDefaultSites = $this->userSetting('default_item_sites'); + if (is_array($userDefaultSites)) { + $userDefaultSiteRepresentations = $this->api()->search('sites', ['id' => $userDefaultSites])->getContent(); + $siteRepresentations = array_merge($siteRepresentations, $userDefaultSiteRepresentations); + } +} + $sites = []; foreach ($siteRepresentations as $siteRepresentation) { - $sites[] = [ - 'id' => $siteRepresentation->id(), - 'title' => $siteRepresentation->title(), - 'email' => $siteRepresentation->owner(), - ]; + $id = $siteRepresentation->id(); + $sites[$id] = [ + 'id' => $id, + 'title' => $siteRepresentation->title(), + 'email' => $siteRepresentation->owner(), + ]; } $siteTemplate = ' @@ -23,7 +33,7 @@ $siteTemplate = ' '; ?> - +
@@ -44,4 +54,4 @@ $siteTemplate = ' \ No newline at end of file +
translate('Title'); ?>