function Q_before_Q_tool_render($params, &$result) { $info = $params['info']; $extra = $params['extra']; if (is_string($extra)) { $extra_id = $extra; $extra = array(); } else { $extra_id = isset($extra['id']) ? $extra['id'] : ''; } $cur_prefix = isset($extra['prefix']) ? $extra['prefix'] : Q_Html::getIdPrefix(); $tool_ids = array(); $tool_prefixes = array(); foreach ($info as $name => $options) { $tool_id = implode('_', explode('/', $name)); if (!empty($extra_id)) { $tool_id .= '-' . $extra_id; } $tool_id = $cur_prefix . $tool_id; $tool_ids[$name] = $tool_id; $tool_prefix = $tool_id . '_'; if (isset(Q::$toolWasRendered[$tool_prefix])) { trigger_error("A tool with prefix \"{$tool_prefix}\" was already rendered.", E_USER_NOTICE); } Q::$toolWasRendered[$tool_prefix] = true; $tool_prefixes[$name] = $tool_prefix; } $prev_prefix = Q_Html::pushIdPrefix($tool_prefixes, $tool_ids); }
function Q_before_Q_tool_render($params, &$result) { $info = $params['info']; $extra = $params['extra']; if (is_string($extra) or is_numeric($extra)) { $extra_id = $extra; $extra = array(); } else { $extra_id = isset($extra['id']) ? $extra['id'] : ''; } $cur_prefix = isset($extra['prefix']) ? $extra['prefix'] : Q_Html::getIdPrefix(); $tool_ids = array(); $tool_prefixes = array(); foreach ($info as $name => $options) { $tool_id = Q_Html::id($name . ($extra_id === '' ? '' : "-{$extra_id}"), $cur_prefix); $tool_ids[$name] = $tool_id; $tool_prefix = $tool_id . '_'; if (isset(Q::$toolWasRendered[$tool_prefix])) { trigger_error("A tool with prefix \"{$tool_prefix}\" was already rendered.", E_USER_NOTICE); } Q::$toolWasRendered[$tool_prefix] = true; $tool_prefixes[$name] = $tool_prefix; } $prev_prefix = Q_Html::pushIdPrefix($tool_prefixes, $tool_ids); }
/** * Gets the current content of a slot, if any. * If slot content is null, then raises an event * to try to fill the slot. If it is filled, * returns the content. Otherwise, returns null. * @method fillSlot * @static * @param {string|array} $slotName The name of the slot. * @param {boolean} [$default_slotName=null] If the slot named in $slotName returns null, * the handler corresponding to the default slot will be called, * passing it the requested slot's name in the 'slotName' parameter, * and its value will be returned instead. * Note: this does not fill the slot named $default_slotName! * That is to say, the computed value is not saved, so that * the slot's handler is called again if it is ever consulted again. * @param {string} [$prefix=null] Sets a prefix for the HTML ids of all the elements in the slot. * @return {string|null} */ static function fillSlot($slotName, $default_slotName = null, $prefix = null) { if (isset(self::$slots[$slotName])) { return self::$slots[$slotName]; } $prev_slotName = self::$slotName; self::$slotName = $slotName; if (isset($prefix)) { Q_Html::pushIdPrefix($prefix); } try { if (isset($default_slotName)) { if (!Q::canHandle("Q/response/{$slotName}")) { /** * @event Q/response/$default_slotName * @param {string} slotName * @return {string} */ $result = Q::event("Q/response/{$default_slotName}", compact('slotName')); if (isset(self::$slots[$slotName])) { // The slot was already filled, while we were rendering it // so discard the $result and return the slot's contents return self::$slots[$slotName]; } return self::$slots[$slotName] = $result; } } /** * @event Q/response/$slotName * @return {string} */ $result = Q::event("Q/response/{$slotName}"); } catch (Exception $e) { self::$slotName = $prev_slotName; if (isset($prefix)) { Q_Html::popIdPrefix(); } throw $e; } self::$slotName = $prev_slotName; if (isset($prefix)) { Q_Html::popIdPrefix(); } if (isset(self::$slots[$slotName])) { // The slot was already filled, while we were rendering it // so discard the $result and return the slot's contents return self::$slots[$slotName]; } if (isset($result)) { self::setSlot($slotName, $result); return $result; } // Otherwise, render default slot if (!isset($default_slotName)) { return null; } /** * @event Q/response/$default_slotName * @param {string} slotName * @return {string} */ return Q::event("Q/response/{$default_slotName}", compact('slotName')); }