Called by HTML_QuickForm whenever form event is made on this element

@param string $event Name of event
@param mixed $arg event arguments
@param object $caller calling object
427078
function onQuickFormEvent($event, $arg, &$caller)
    {
        switch ($event) {
            case 'createElement':
                parent::onQuickFormEvent($event, $arg, $caller);
                if ($caller->isNoSubmitButton($arg[0])){
                    //need this to bypass client validation
                    //for buttons that submit but do not process the
                    //whole form.
                    $onClick = $this->getAttribute('onclick');
                    $skip = 'skipClientValidation = true;';
                    $onClick = ($onClick !== null)?$skip.' '.$onClick:$skip;
                    $this->updateAttributes(array('onclick'=>$onClick));
                }
                return true;
                break;
        }
        return parent::onQuickFormEvent($event, $arg, $caller);

    }
36440
public static function bindAndCall(callable $fn, $newThis, $args = [], $bindClass = null)
    {
        $func = \Closure::bind($fn, $newThis, $bindClass ?: get_class($newThis));
        if ($args) {
            call_user_func_array($func, $args);
        } else {
            $func(); //faster
        }
    }
589284
function onQuickFormEvent($event, $arg, &$caller) {
        $this->setMoodleForm($caller);
        switch ($event) {
            case 'updateValue':
                // Constant values override both default and submitted ones
                // default values are overriden by submitted.
                $value = $this->_findValue($caller->_constantValues);
                if (null === $value) {
                    // If no boxes were checked, then there is no value in the array
                    // yet we don't want to display default value in this case.
                    if ($caller->isSubmitted()) {
                        $value = $this->_findValue($caller->_submitValues);
                    } else {
                        $value = $this->_findValue($caller->_defaultValues);
                    }
                }
                $requestvalue=$value;
                if ($value == 0) {
                    $value = $this->_options['defaulttime'];
                    if (!$value) {
                        $value = time();
                    }
                }
                if (!is_array($value)) {
                    $calendartype = \core_calendar\type_factory::get_calendar_instance();
                    $currentdate = $calendartype->timestamp_to_date_array($value, $this->_options['timezone']);
                    // Round minutes to the previous multiple of step.
                    $currentdate['minutes'] -= $currentdate['minutes'] % $this->_options['step'];
                    $value = array(
                        'minute' => $currentdate['minutes'],
                        'hour' => $currentdate['hours'],
                        'day' => $currentdate['mday'],
                        'month' => $currentdate['mon'],
                        'year' => $currentdate['year']);
                    // If optional, default to off, unless a date was provided.
                    if ($this->_options['optional']) {
                        $value['enabled'] = $requestvalue != 0;
                    }
                } else {
                    $value['enabled'] = isset($value['enabled']);
                }
                if (null !== $value) {
                    $this->setValue($value);
                }
                break;
            case 'createElement':
                if (isset($arg[2]['optional']) && $arg[2]['optional']) {
                    // When using the function addElement, rather than createElement, we still
                    // enter this case, making this check necessary.
                    if ($this->_usedcreateelement) {
                        $caller->disabledIf($arg[0] . '[day]', $arg[0] . '[enabled]');
                        $caller->disabledIf($arg[0] . '[month]', $arg[0] . '[enabled]');
                        $caller->disabledIf($arg[0] . '[year]', $arg[0] . '[enabled]');
                        $caller->disabledIf($arg[0] . '[hour]', $arg[0] . '[enabled]');
                        $caller->disabledIf($arg[0] . '[minute]', $arg[0] . '[enabled]');
                    } else {
                        $caller->disabledIf($arg[0], $arg[0] . '[enabled]');
                    }
                }
                return parent::onQuickFormEvent($event, $arg, $caller);
                break;
            case 'addElement':
                $this->_usedcreateelement = false;
                return parent::onQuickFormEvent($event, $arg, $caller);
                break;
            default:
                return parent::onQuickFormEvent($event, $arg, $caller);
        }
    }
221881
public void callManager(final Event event, final Callback callback) {
        if (delegate instanceof DefaultCommunicationClientImpl) {
            ((DefaultCommunicationClientImpl) delegate).submit(new Runnable() {

                public void run() {
                    Object obj = callManager(event);
                    callback.call(obj);
                }
            });
        }
    }
617889
public function onQuickFormEvent($event, $arg, &$caller) {
        $this->setMoodleForm($caller);
        switch ($event) {
            case 'createElement':
                // The first argument is the name.
                $name = $arg[0];

                // Set disable actions.
                $caller->hideIf($name.'[modgrade_scale]', $name.'[modgrade_type]', 'neq', 'scale');
                $caller->hideIf($name.'[modgrade_point]', $name.'[modgrade_type]', 'neq', 'point');
                $caller->hideIf($name.'[modgrade_rescalegrades]', $name.'[modgrade_type]', 'neq', 'point');

                // Set validation rules for the sub-elements belonging to this element.
                // A handy note: the parent scope of a closure is the function in which the closure was declared.
                // Because of this using $this is safe despite the closures being called statically.
                // A nasty magic hack!
                $checkgradetypechange = function($val) {
                    // Nothing is affected by changes to the grade type if there are no grades yet.
                    if (!$this->hasgrades) {
                        return true;
                    }
                    // Check if we are changing the grade type when grades are present.
                    if (isset($val['modgrade_type']) && $val['modgrade_type'] !== $this->currentgradetype) {
                        return false;
                    }
                    return true;
                };
                $checkscalechange = function($val) {
                    // Nothing is affected by changes to the scale if there are no grades yet.
                    if (!$this->hasgrades) {
                        return true;
                    }
                    // Check if we are changing the scale type when grades are present.
                    // If modgrade_type is empty then use currentgradetype.
                    $gradetype = isset($val['modgrade_type']) ? $val['modgrade_type'] : $this->currentgradetype;
                    if ($gradetype === 'scale') {
                        if (isset($val['modgrade_scale']) && ($val['modgrade_scale'] !== $this->currentscaleid)) {
                            return false;
                        }
                    }
                    return true;
                };
                $checkmaxgradechange = function($val) {
                    // Nothing is affected by changes to the max grade if there are no grades yet.
                    if (!$this->hasgrades) {
                        return true;
                    }
                    // If we are not using ratings we can change the max grade.
                    if (!$this->useratings) {
                        return true;
                    }
                    // Check if we are changing the max grade if we are using ratings and there is a grade.
                    // If modgrade_type is empty then use currentgradetype.
                    $gradetype = isset($val['modgrade_type']) ? $val['modgrade_type'] : $this->currentgradetype;
                    if ($gradetype === 'point') {
                        if (isset($val['modgrade_point']) &&
                            grade_floats_different($this->currentgrade, $val['modgrade_point'])) {
                            return false;
                        }
                    }
                    return true;
                };
                $checkmaxgrade = function($val) {
                    // Closure to validate a max points value. See the note above about scope if this confuses you.
                    // If modgrade_type is empty then use currentgradetype.
                    $gradetype = isset($val['modgrade_type']) ? $val['modgrade_type'] : $this->currentgradetype;
                    if ($gradetype === 'point') {
                        if (isset($val['modgrade_point'])) {
                            return $this->validate_point($val['modgrade_point']);
                        }
                    }
                    return true;
                };
                $checkvalidscale = function($val) {
                    // Closure to validate a scale value. See the note above about scope if this confuses you.
                    // If modgrade_type is empty then use currentgradetype.
                    $gradetype = isset($val['modgrade_type']) ? $val['modgrade_type'] : $this->currentgradetype;
                    if ($gradetype === 'scale') {
                        if (isset($val['modgrade_scale'])) {
                            return $this->validate_scale($val['modgrade_scale']);
                        }
                    }
                    return true;
                };

                $checkrescale = function($val) {
                    // Nothing is affected by changes to grademax if there are no grades yet.
                    if (!$this->isupdate || !$this->hasgrades || !$this->canrescale) {
                        return true;
                    }
                    // Closure to validate a scale value. See the note above about scope if this confuses you.
                    // If modgrade_type is empty then use currentgradetype.
                    $gradetype = isset($val['modgrade_type']) ? $val['modgrade_type'] : $this->currentgradetype;
                    if ($gradetype === 'point' && isset($val['modgrade_point'])) {
                        // Work out if the value was actually changed in the form.
                        if (grade_floats_different($this->currentgrade, $val['modgrade_point'])) {
                            if (empty($val['modgrade_rescalegrades'])) {
                                // This was an "edit", the grademax was changed and the process existing setting was not set.
                                return false;
                            }
                        }
                    }
                    return true;
                };

                $cantchangegradetype = get_string('modgradecantchangegradetype', 'grades');
                $cantchangemaxgrade = get_string('modgradecantchangeratingmaxgrade', 'grades');
                $maxgradeexceeded = get_string('modgradeerrorbadpoint', 'grades', get_config('core', 'gradepointmax'));
                $invalidscale = get_string('modgradeerrorbadscale', 'grades');
                $cantchangescale = get_string('modgradecantchangescale', 'grades');
                $mustchooserescale = get_string('mustchooserescaleyesorno', 'grades');
                // When creating the rules the sixth arg is $force, we set it to true because otherwise the form
                // will attempt to validate the existence of the element, we don't want this because the element
                // is being created right now and doesn't actually exist as a registered element yet.
                $caller->addRule($name, $cantchangegradetype, 'callback', $checkgradetypechange, 'server', false, true);
                $caller->addRule($name, $cantchangemaxgrade, 'callback', $checkmaxgradechange, 'server', false, true);
                $caller->addRule($name, $maxgradeexceeded, 'callback', $checkmaxgrade, 'server', false, true);
                $caller->addRule($name, $invalidscale, 'callback', $checkvalidscale, 'server', false, true);
                $caller->addRule($name, $cantchangescale, 'callback', $checkscalechange, 'server', false, true);
                $caller->addRule($name, $mustchooserescale, 'callback', $checkrescale, 'server', false, true);

                break;

            case 'updateValue':
                // As this is a group element with no value of its own we are only interested in situations where the
                // default value or a constant value are being provided to the actual element.
                // In this case we expect an int that is going to translate to a scale if negative, or to max points
                // if positive.

                // Set the maximum points field to disabled if the rescale option has not been chosen and there are grades.
                $caller->disabledIf($this->getName() . '[modgrade_point]', $this->getName() .
                        '[modgrade_rescalegrades]', 'eq', '');

                // A constant value should be given as an int.
                // The default value should be an int and be either $CFG->gradepointdefault or whatever was set in set_data().
                $value = $this->_findValue($caller->_constantValues);
                if (null === $value) {
                    if ($caller->isSubmitted() && $this->_findValue($caller->_submitValues) !== null) {
                        // Submitted values are array, one value for each individual element in this group.
                        // When there is submitted data let parent::onQuickFormEvent() process it.
                        break;
                    }
                    $value = $this->_findValue($caller->_defaultValues);
                }

                if (!is_null($value) && !is_scalar($value)) {
                    // Something unexpected (likely an array of subelement values) has been given - this will be dealt
                    // with somewhere else - where exactly... likely the subelements.
                    debugging('An invalid value (type '.gettype($value).') has arrived at '.__METHOD__, DEBUG_DEVELOPER);
                    break;
                }

                // Set element state for existing data.
                // This is really a pretty hacky thing to do, when data is being set the group element is called
                // with the data first and the subelements called afterwards.
                // This means that the subelements data (inc const and default values) can be overridden by form code.
                // So - when we call this code really we can't be sure that will be the end value for the element.
                if (!empty($this->_elements)) {
                    if (!empty($value)) {
                        if ($value < 0) {
                            $this->gradetypeformelement->setValue('scale');
                            $this->scaleformelement->setValue(($value * -1));
                        } else if ($value > 0) {
                            $this->gradetypeformelement->setValue('point');
                            $maxvalue = !empty($this->currentgrade) ? (string)unformat_float($this->currentgrade) : $value;
                            $this->maxgradeformelement->setValue($maxvalue);
                        }
                    } else {
                        $this->gradetypeformelement->setValue('none');
                        $this->maxgradeformelement->setValue('');
                    }
                }
                break;
        }

        // Always let the parent do its thing!
        return parent::onQuickFormEvent($event, $arg, $caller);
    }
810006
private function bindApplicationEvent(ServiceDefinition $application, string $event, string $class, string $property, string $argument = null): void
    {
        $argument = $argument ? ', $'.$argument : '';
        $application->addSetup(
            sprintf(
                '?->?[] = function ($application%s = null) use ($dispatcher) { $dispatcher->dispatch(?, new %s($application%s)); }',
                $argument,
                $class,
                $argument
            ),
            [
                '@self',
                $property,
                $event,
            ]
        );
    }
1020380
public static void printInfo(Object caller, String format, Object... args)
	{
		Object msg = String.format(format, args);
		
		printInfo(caller,msg);
	}
140087
protected function dispatchEventToEventHandler($event, $arguments)
    {
        if ($this->eventHandler == null || ! method_exists($this->eventHandler, $method = "on{$event}")) {
            return;
        }

        try {
            $this->eventHandler->$method(...$arguments);
        } catch (Exception $e) {
            $this->handleException($e);
        } catch (Throwable $e) {
            $this->handleException(new FatalThrowableError($e));
        }
    }
223689
public function fire($event, $args)
    {
        $onEvent = $this->getConfig('events.'.$event);

        if ($onEvent instanceof Closure) {
            $onEvent($args);
        }
    }
245579
public function onQuickFormEvent($event, $arg, &$caller) {
        global $OUTPUT;

        switch ($event) {
            case 'updateValue':
                $value = $this->_findValue($caller->_constantValues);
                if (null === $value) {
                    if ($caller->isSubmitted()) {
                        $value = $this->_findValue($caller->_submitValues);
                    } else {
                        $value = (string)$this->_findValue($caller->_defaultValues);
                    }
                }
                if (!is_array($value)) {
                    $value = array('filetypes' => $value);
                }
                if ($value['filetypes'] !== null) {
                    $filetypes = $this->util->normalize_file_types($value['filetypes']);
                    if ($filetypes === ['*'] && !$this->allowall) {
                        $filetypes = [];
                    }
                    $value['descriptions'] = '<div data-filetypesdescriptions="'.$this->getAttribute('id').'">' .
                        $OUTPUT->render_from_template('core_form/filetypes-descriptions',
                            $this->util->describe_file_types($filetypes)).'</div>';
                }
                $this->setValue($value);
                return true;
                break;

        }

        return parent::onQuickFormEvent($event, $arg, $caller);
    }
1156954
public function fire(string $event, ...$args): void
    {
        if (!isset(self::$events[$event])) {
            return;
        }

        // call event handlers of the event.
        foreach ((array)self::$eventHandlers[$event] as $cb) {
            // return FALSE to stop go on handle.
            if (false === PhpHelper::call($cb, ...$args)) {
                break;
            }
        }

        // is a once event, remove it
        if (self::$events[$event]) {
            $this->off($event);
        }
    }
661899
public static function trigger(string $name, ?array $args = null)
  {
    if (!isset(self::$events[$name])) return false;

    foreach (self::$events[$name] as $event => $callback) {
      if (is_callable($callback)) {
        return call_user_func_array($callback, isset($args) ? $args : []);
      }
      else if (is_array($callback)) {
        (new Events)->triggerGroup($callback, $args);
      }
      else if (is_string($callback)) {
        $call = new $callback;
        return call_user_func_array([$call, 'persist'], $args ?? []);
      }
    }
  }
919333
public static function call(callable $callable, $args=[])
    {
        if (!is_array($args)) {
            $args = [$args];
        }

        switch (count($args)) {
            case 0:
                return call_user_func($callable);
            case 1:
                return call_user_func($callable, $args[0]);
            case 2:
                return call_user_func($callable, $args[0], $args[1]);
            case 3:
                return call_user_func($callable, $args[0], $args[1], $args[2]);
            case 4:
                return call_user_func($callable, $args[0], $args[1], $args[2], $args[3]);
        }

        return call_user_func_array($callable, $args);
    }
393573
function onQuickFormEvent($event, $arg, &$caller)
    {
        switch ($event) {
            case 'createElement':
                $caller->setType($arg[0], PARAM_TAGLIST);
                break;
        }
        return parent::onQuickFormEvent($event, $arg, $caller);
    }
1037037
protected function callListener(callable $listener, $event, array $args)
    {

        if (!$this->marks) {
            return Lambda::callFast($listener, $args);
        }

        if ($listener instanceof MatchingListener) {
            return $listener->callWithMarks($args, $this->marks);
        }

        return Lambda::callFast($listener, $args);

    }
921822
function onQuickFormEvent($event, $arg, &$caller)
    {
        switch ($event) {
            case 'createElement':
                $this->_formid = $caller->getAttribute('id');
                break;
        }
        return parent::onQuickFormEvent($event, $arg, $caller);
    }
253711
public function trigger(string $event, ...$args): EventInterface
    {
        $matches = $this->match($event);

        //if there are no events found
        if (empty($matches)) {
            //report a 404
            $this->meta = self::STATUS_NOT_FOUND;
            return $this;
        }

        $observers = [];
        foreach ($matches as $match) {
            $event = $match['pattern'];

            //if no direct observers
            if (!isset($this->observers[$event])) {
                continue;
            }

            //add args on to match
            $match['args'] = $args;

            //then loop the observers
            foreach ($this->observers[$event] as $observer) {
                //get the callback
                $callback = $observer['observer']->getCallback();
                $priority = $observer['priority'];
                //add on to match
                $match['callback'] = $callback;
                $observers[$priority][] = $match;
            }
        }

        //then sort by priority
        krsort($observers);
        if (!empty($observers)) {
            $observers = call_user_func_array('array_merge', $observers);
        }

        //call the callbacks
        foreach ($observers as $match) {
            //set the current
            $this->meta = $match;

            //if this is the same event, call the method, if the method returns false
            if (call_user_func_array($match['callback'], $args) === false) {
                //report a 308
                $this->meta = self::STATUS_INCOMPLETE;
                return $this;
            }
        }

        //report a 200
        $this->meta = self::STATUS_OK;

        return $this;
    }