original_string: protected static function fill_preferences_cache() {
          if (self::$preferencescache !== null) {
              return;
          }
  
          // Array of user preferences and expected types/values.
          // Every preference that can be updated directly by user should be added here.
          $preferences = array();
          $preferences['auth_forcepasswordchange'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'choices' => array(0, 1),
              'permissioncallback' => function($user, $preferencename) {
                  global $USER;
                  $systemcontext = context_system::instance();
                  return ($USER->id != $user->id && (has_capability('moodle/user:update', $systemcontext) ||
                          ($user->timecreated > time() - 10 && has_capability('moodle/user:create', $systemcontext))));
              });
          $preferences['usemodchooser'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 1,
              'choices' => array(0, 1));
          $preferences['forum_markasreadonnotification'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 1,
              'choices' => array(0, 1));
          $preferences['htmleditor'] = array('type' => PARAM_NOTAGS, 'null' => NULL_ALLOWED,
              'cleancallback' => function($value, $preferencename) {
                  if (empty($value) || !array_key_exists($value, core_component::get_plugin_list('editor'))) {
                      return null;
                  }
                  return $value;
              });
          $preferences['badgeprivacysetting'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 1,
              'choices' => array(0, 1), 'permissioncallback' => function($user, $preferencename) {
                  global $CFG, $USER;
                  return !empty($CFG->enablebadges) && $user->id == $USER->id;
              });
          $preferences['blogpagesize'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 10,
              'permissioncallback' => function($user, $preferencename) {
                  global $USER;
                  return $USER->id == $user->id && has_capability('moodle/blog:view', context_system::instance());
              });
  
          // Core components that may want to define their preferences.
          // List of core components implementing callback is hardcoded here for performance reasons.
          // TODO MDL-58184 cache list of core components implementing a function.
          $corecomponents = ['core_message', 'core_calendar'];
          foreach ($corecomponents as $component) {
              if (($pluginpreferences = component_callback($component, 'user_preferences')) && is_array($pluginpreferences)) {
                  $preferences += $pluginpreferences;
              }
          }
  
          // Plugins that may define their preferences.
          if ($pluginsfunction = get_plugins_with_function('user_preferences')) {
              foreach ($pluginsfunction as $plugintype => $plugins) {
                  foreach ($plugins as $function) {
                      if (($pluginpreferences = call_user_func($function)) && is_array($pluginpreferences)) {
                          $preferences += $pluginpreferences;
                      }
                  }
              }
          }
  
          self::$preferencescache = $preferences;
      }
code: protected static function fill_preferences_cache() {
          if (self::$preferencescache !== null) {
              return;
          }
  
          // Array of user preferences and expected types/values.
          // Every preference that can be updated directly by user should be added here.
          $preferences = array();
          $preferences['auth_forcepasswordchange'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'choices' => array(0, 1),
              'permissioncallback' => function($user, $preferencename) {
                  global $USER;
                  $systemcontext = context_system::instance();
                  return ($USER->id != $user->id && (has_capability('moodle/user:update', $systemcontext) ||
                          ($user->timecreated > time() - 10 && has_capability('moodle/user:create', $systemcontext))));
              });
          $preferences['usemodchooser'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 1,
              'choices' => array(0, 1));
          $preferences['forum_markasreadonnotification'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 1,
              'choices' => array(0, 1));
          $preferences['htmleditor'] = array('type' => PARAM_NOTAGS, 'null' => NULL_ALLOWED,
              'cleancallback' => function($value, $preferencename) {
                  if (empty($value) || !array_key_exists($value, core_component::get_plugin_list('editor'))) {
                      return null;
                  }
                  return $value;
              });
          $preferences['badgeprivacysetting'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 1,
              'choices' => array(0, 1), 'permissioncallback' => function($user, $preferencename) {
                  global $CFG, $USER;
                  return !empty($CFG->enablebadges) && $user->id == $USER->id;
              });
          $preferences['blogpagesize'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 10,
              'permissioncallback' => function($user, $preferencename) {
                  global $USER;
                  return $USER->id == $user->id && has_capability('moodle/blog:view', context_system::instance());
              });
  
          // Core components that may want to define their preferences.
          // List of core components implementing callback is hardcoded here for performance reasons.
          // TODO MDL-58184 cache list of core components implementing a function.
          $corecomponents = ['core_message', 'core_calendar'];
          foreach ($corecomponents as $component) {
              if (($pluginpreferences = component_callback($component, 'user_preferences')) && is_array($pluginpreferences)) {
                  $preferences += $pluginpreferences;
              }
          }
  
          // Plugins that may define their preferences.
          if ($pluginsfunction = get_plugins_with_function('user_preferences')) {
              foreach ($pluginsfunction as $plugintype => $plugins) {
                  foreach ($plugins as $function) {
                      if (($pluginpreferences = call_user_func($function)) && is_array($pluginpreferences)) {
                          $preferences += $pluginpreferences;
                      }
                  }
              }
          }
  
          self::$preferencescache = $preferences;
      }
code_tokens: protected static function fill_preferences_cache ( ) { if ( self :: $ preferencescache !== null ) { return ; } // Array of user preferences and expected types/values. // Every preference that can be updated directly by user should be added here. $ preferences = array ( ) ; $ preferences [ 'auth_forcepasswordchange' ] = array ( 'type' => PARAM_INT , 'null' => NULL_NOT_ALLOWED , 'choices' => array ( 0 , 1 ) , 'permissioncallback' => function ( $ user , $ preferencename ) { global $ USER ; $ systemcontext = context_system :: instance ( ) ; return ( $ USER -> id != $ user -> id && ( has_capability ( 'moodle/user:update' , $ systemcontext ) || ( $ user -> timecreated > time ( ) - 10 && has_capability ( 'moodle/user:create' , $ systemcontext ) ) ) ) ; } ) ; $ preferences [ 'usemodchooser' ] = array ( 'type' => PARAM_INT , 'null' => NULL_NOT_ALLOWED , 'default' => 1 , 'choices' => array ( 0 , 1 ) ) ; $ preferences [ 'forum_markasreadonnotification' ] = array ( 'type' => PARAM_INT , 'null' => NULL_NOT_ALLOWED , 'default' => 1 , 'choices' => array ( 0 , 1 ) ) ; $ preferences [ 'htmleditor' ] = array ( 'type' => PARAM_NOTAGS , 'null' => NULL_ALLOWED , 'cleancallback' => function ( $ value , $ preferencename ) { if ( empty ( $ value ) || ! array_key_exists ( $ value , core_component :: get_plugin_list ( 'editor' ) ) ) { return null ; } return $ value ; } ) ; $ preferences [ 'badgeprivacysetting' ] = array ( 'type' => PARAM_INT , 'null' => NULL_NOT_ALLOWED , 'default' => 1 , 'choices' => array ( 0 , 1 ) , 'permissioncallback' => function ( $ user , $ preferencename ) { global $ CFG , $ USER ; return ! empty ( $ CFG -> enablebadges ) && $ user -> id == $ USER -> id ; } ) ; $ preferences [ 'blogpagesize' ] = array ( 'type' => PARAM_INT , 'null' => NULL_NOT_ALLOWED , 'default' => 10 , 'permissioncallback' => function ( $ user , $ preferencename ) { global $ USER ; return $ USER -> id == $ user -> id && has_capability ( 'moodle/blog:view' , context_system :: instance ( ) ) ; } ) ; // Core components that may want to define their preferences. // List of core components implementing callback is hardcoded here for performance reasons. // TODO MDL-58184 cache list of core components implementing a function. $ corecomponents = [ 'core_message' , 'core_calendar' ] ; foreach ( $ corecomponents as $ component ) { if ( ( $ pluginpreferences = component_callback ( $ component , 'user_preferences' ) ) && is_array ( $ pluginpreferences ) ) { $ preferences += $ pluginpreferences ; } } // Plugins that may define their preferences. if ( $ pluginsfunction = get_plugins_with_function ( 'user_preferences' ) ) { foreach ( $ pluginsfunction as $ plugintype => $ plugins ) { foreach ( $ plugins as $ function ) { if ( ( $ pluginpreferences = call_user_func ( $ function ) ) && is_array ( $ pluginpreferences ) ) { $ preferences += $ pluginpreferences ; } } } } self :: $ preferencescache = $ preferences ; }
docstring: Definition of updateable user preferences and rules for data and access validation.
  
  array(
  'preferencename' => array(      // Either exact preference name or a regular expression.
  'null' => NULL_ALLOWED,    // Defaults to NULL_NOT_ALLOWED. Takes NULL_NOT_ALLOWED or NULL_ALLOWED.
  'type' => PARAM_TYPE,      // Expected parameter type of the user field - mandatory
  'choices' => array(1, 2..) // An array of accepted values of the user field - optional
  'default' => $CFG->setting // An default value for the field - optional
  'isregex' => false/true    // Whether the name of the preference is a regular expression (default false).
  'permissioncallback' => callable // Function accepting arguments ($user, $preferencename) that checks if current user
  // is allowed to modify this preference for given user.
  // If not specified core_user::default_preference_permission_check() will be assumed.
  'cleancallback' => callable // Custom callback for cleaning value if something more difficult than just type/choices is needed
  // accepts arguments ($value, $preferencename)
  )
  )
  
  @return void
docstring_tokens: Definition of updateable user preferences and rules for data and access validation .