function pie_before_tool_render($params, &$result) { static $prefix_was_rendered = array(); static $temp_id = 0; $tool_name = $params['tool_name']; $pie_options = $params['pie_options']; $prefix = implode('_', explode('/', $tool_name)) . '_'; $id = isset($pie_options['id']) ? $pie_options['id'] : ''; if (!empty($id)) { $prefix = 'id' . $id . '_' . $prefix; } if (isset($pie_options['prefix'])) { $cur_prefix = $pie_options['prefix']; } else { $cur_prefix = Pie_Html::getIdPrefix(); } $tool_prefix = $cur_prefix . $prefix; if (isset($prefix_was_rendered[$tool_prefix])) { trigger_error("A tool with prefix \"{$tool_prefix}\" was already rendered.", E_USER_NOTICE); } $prefix_was_rendered[$tool_prefix] = true; $prev_prefix = Pie_Html::pushIdPrefix($tool_prefix); // other parameters: // script, notReady, id $pie_prefix = $prefix; $result = compact('pie_prefix'); }
/** * 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. * @param string|array $slot_name * The name of the slot. * @param boolean $default_slot_name * Optional. If the slot named in $slot_name returns null, * the handler corresponding to the default slot will be called, * passing it the requested slot's name in the 'slot_name' parameter, * and its value will be returned instead. * Note: this does not fill the slot named $default_slot_name! * 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 * Optional. Sets a prefix for the HTML ids of all the elements in the slot. * @return string|null */ static function fillSlot($slot_name, $default_slot_name = null, $prefix = null) { if (isset(self::$slots[$slot_name])) { return self::$slots[$slot_name]; } $prev_slot_name = self::$slotName; self::$slotName = $slot_name; if (isset($prefix)) { Pie_Html::pushIdPrefix($prefix); } try { if (isset($default_slot_name)) { if (!Pie::canHandle("pie/response/{$slot_name}")) { $result = Pie::event("pie/response/{$default_slot_name}", compact('slot_name')); if (isset(self::$slots[$slot_name])) { // The slot was already filled, while we were rendering it // so discard the $result and return the slot's contents return self::$slots[$slot_name]; } return $result; } } $result = Pie::event("pie/response/{$slot_name}"); } catch (Exception $e) { self::$slotName = $prev_slot_name; if (isset($prefix)) { Pie_Html::pieIdPrefix(); } throw $e; } self::$slotName = $prev_slot_name; if (isset($prefix)) { Pie_Html::pieIdPrefix(); } if (isset(self::$slots[$slot_name])) { // The slot was already filled, while we were rendering it // so discard the $result and return the slot's contents return self::$slots[$slot_name]; } if (isset($result)) { self::setSlot($slot_name, $result); return $result; } // Otherwise, render default slot if (!isset($default_slot_name)) { return null; } return Pie::event("pie/response/{$default_slot_name}", compact('slot_name')); }