/** * Renders an action_link object. * * The provided link is renderer and the HTML returned. At the same time the * associated actions are setup in JS by {@link core_renderer::add_action_handler()} * * @param action_link $link * @return string HTML fragment */ protected function render_action_link(action_link $link) { return $this->render_from_template('core/action_link', $link->export_for_template($this)); }
/** * Export for template. * * @param renderer_base $output The renderer. * @return stdClass */ public function export_for_template(renderer_base $output) { static $instance = 1; $data = parent::export_for_template($output); $data->instance = $instance++; // Ignore what the parent did with the attributes, except for ID and class. $data->attributes = []; $attributes = $this->attributes; unset($attributes['id']); unset($attributes['class']); // Handle text being a renderable. $comparetoalt = $this->text; if ($this->text instanceof renderable) { $data->text = $this->render($this->text); $comparetoalt = ''; } $comparetoalt = (string) $comparetoalt; $data->showtext = (!$this->icon || $this->primary === false); $data->icon = null; if ($this->icon) { $icon = $this->icon; if ($this->primary || !$this->actionmenu->will_be_enhanced()) { $attributes['title'] = $data->text; } if (!$this->primary && $this->actionmenu->will_be_enhanced()) { if ((string) $icon->attributes['alt'] === $comparetoalt) { $icon->attributes['alt'] = ''; } if (isset($icon->attributes['title']) && (string) $icon->attributes['title'] === $comparetoalt) { unset($icon->attributes['title']); } } $data->icon = $icon ? $icon->export_for_template($output) : null; } $data->disabled = !empty($attributes['disabled']); unset($attributes['disabled']); $data->attributes = array_map(function($key, $value) { return [ 'name' => $key, 'value' => $value ]; }, array_keys($attributes), $attributes); return $data; }