}
// Identity providers.
- $identityproviders = [];
- foreach ($authsequence as $authname) {
- $authplugin = get_auth_plugin($authname);
- $identityproviders = array_merge($identityproviders, $authplugin->loginpage_idp_list($SESSION->wantsurl));
- }
- $this->identityproviders = $identityproviders;
+ $this->identityproviders = \auth_plugin_base::get_identity_providers($authsequence);
}
/**
}
public function export_for_template(renderer_base $output) {
- global $CFG;
-
- $identityproviders = array_map(function($idp) use ($output) {
-
- if (!empty($idp['icon'])) {
- $idp['iconurl'] = $output->pix_url($idp['icon']->key, $idp['icon']->component);
- } else if ($idp['iconurl'] instanceof moodle_url) {
- $idp['iconurl'] = $idp['iconurl']->out(false);
- }
- unset($idp['icon']);
- if ($idp['url'] instanceof moodle_url) {
- $idp['url'] = $idp['url']->out(false);
- }
- return $idp;
- }, $this->identityproviders);
+
+ $identityproviders = \auth_plugin_base::prepare_identity_providers_for_output($this->identityproviders, $output);
$data = new stdClass();
$data->autofocusform = $this->autofocusform;
*/
public function postlogout_hook($user) {
}
+
+ /**
+ * Return the list of enabled identity providers.
+ *
+ * Each identity provider data contains the keys 'url' (string), 'name' (string) and 'icon' (pix_icon).
+ *
+ * @param array $authsequence site's auth sequence (list of auth plugins ordered)
+ * @return array an array of enabled identity providers
+ */
+ public static function get_identity_providers($authsequence) {
+ global $SESSION;
+
+ $identityproviders = [];
+ foreach ($authsequence as $authname) {
+ $authplugin = get_auth_plugin($authname);
+ $wantsurl = (isset($SESSION->wantsurl)) ? $SESSION->wantsurl : '';
+ $identityproviders = array_merge($identityproviders, $authplugin->loginpage_idp_list($wantsurl));
+ }
+ return $identityproviders;
+ }
+
+ /**
+ * Prepare a list of identity providers for output.
+ *
+ * @param array $identityproviders
+ * @param renderer_base $output
+ * @return array the identity providers ready for output
+ */
+ public static function prepare_identity_providers_for_output($identityproviders, renderer_base $output) {
+ $data = [];
+ foreach ($identityproviders as $idp) {
+ if (!empty($idp['icon'])) {
+ $idp['iconurl'] = $output->image_url($idp['icon']->key, $idp['icon']->component);
+ } else if ($idp['iconurl'] instanceof moodle_url) {
+ $idp['iconurl'] = $idp['iconurl']->out(false);
+ }
+ unset($idp['icon']);
+ if ($idp['url'] instanceof moodle_url) {
+ $idp['url'] = $idp['url']->out(false);
+ }
+ $data[] = $idp;
+ }
+ return $data;
+ }
}
/**
get_string('auth_fieldlock', 'auth'), '', 'unlocked', $lockoptions));
}
}
-}
\ No newline at end of file
+}
* Webservices core_course_search_courses and core_course_get_courses_by_field will always return the sortorder field.
* core_course_external::get_activities_overview has been deprecated. Please do not call this function any more.
* Changed the pix mustache template helper to accept context variables for the key, component and alt text.
+* New auth_plugin_base helper methods:
+ - get_identity_providers() - Retrieves available auth identity providers.
+ - prepare_identity_providers_for_output() - Prepares auth identity provider data for output (e.g. to templates, WS, etc.).
=== 3.2 ===