addRoleAssignment( [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SITE_ADMIN], ['saveLanguageSetting', 'setContextPrimaryLocale', 'reloadLocale', 'fetchGrid', 'fetchRow'] ); } // // Implement methods from GridHandler. // /** * @copydoc GridHandler::authorize() */ public function authorize($request, &$args, $roleAssignments) { $this->addPolicy(new ContextAccessPolicy($request, $roleAssignments)); return parent::authorize($request, $args, $roleAssignments); } /** * @copydoc GridHandler::loadData() */ protected function loadData($request, $filter) { $site = $request->getSite(); $context = $request->getContext(); $allLocales = Locale::getLocales(); $supportedLocales = $site->getSupportedLocales(); $contextPrimaryLocale = $context->getPrimaryLocale(); $data = []; foreach ($supportedLocales as $locale) { $formattedLocale = Locale::getFormattedDisplayNames([$locale], $allLocales); $data[$locale] = []; $data[$locale]['code'] = $locale; $data[$locale]['name'] = array_shift($formattedLocale); $data[$locale]['supported'] = true; $data[$locale]['primary'] = ($locale == $contextPrimaryLocale); } $data = $this->addManagementData($request, $data); return $data; } // // Extended methods from LanguageGridHandler. // /** * @copydoc LanguageGridHandler::initialize() * * @param null|mixed $args */ public function initialize($request, $args = null) { parent::initialize($request, $args); $this->addNameColumn(); $this->addLocaleCodeColumn(); $this->addPrimaryColumn('contextPrimary'); $this->addManagementColumns(); } /** * Reload locale. * * @param array $args * @param Request $request * * @return JSONMessage JSON object */ public function reloadLocale($args, $request) { $context = $request->getContext(); $locale = $request->getUserVar('rowId'); $gridData = $this->getGridDataElements($request); if (empty($context) || !$request->checkCSRF() || !array_key_exists($locale, $gridData)) { return new JSONMessage(false); } $context = Services::get('context')->restoreLocaleDefaults($context, $request, $locale); $notificationManager = new NotificationManager(); $notificationManager->createTrivialNotification( $request->getUser()->getId(), PKPNotification::NOTIFICATION_TYPE_SUCCESS, ['contents' => __('notification.localeReloaded', ['locale' => $gridData[$locale]['name'], 'contextName' => $context->getLocalizedName()])] ); return \PKP\db\DAO::getDataChangedEvent($locale); } }