/** * 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; }