/**
  * Returns an array of properties suitable for generating a quickforms element
  * @param backup_task|null $task
  * @return array (element, name, label, options, attributes)
  */
 public function get_element_properties(base_task $task = null, renderer_base $output = null)
 {
     // name, label, text, attributes
     $icon = $this->get_icon();
     $label = $this->get_label($task);
     if (!empty($icon)) {
         $label .= $output->render($icon);
     }
     // name, label, options, attributes
     return $this->apply_options(array('element' => 'select', 'name' => self::NAME_PREFIX . $this->name, 'label' => $label, 'options' => $this->values, 'attributes' => $this->attributes));
 }
Example #2
0
 /**
  * Returns rendered widget.
  * @param renderable $widget instance with renderable interface
  * @return string
  */
 public function render(renderable $widget)
 {
     $rendermethod = 'render_' . get_class($widget);
     if (method_exists($this, $rendermethod)) {
         return $this->{$rendermethod}($widget);
     }
     // pass to core renderer if method not found here
     return $this->output->render($widget);
 }
Example #3
0
    /**
     * Export for template.
     *
     * @param renderer_base $output The renderer.
     * @return stdClass
     */
    public function export_for_template(renderer_base $output) {
        $data = new stdClass();
        $attributes = $this->attributes;

        if (empty($attributes['id'])) {
            $attributes['id'] = html_writer::random_id('action_link');
        }
        $data->id = $attributes['id'];
        unset($attributes['id']);

        $data->disabled = !empty($attributes['disabled']);
        unset($attributes['disabled']);

        $data->text = $this->text instanceof renderable ? $output->render($this->text) : (string) $this->text;
        $data->url = $this->url ? $this->url->out(false) : '';
        $data->icon = $this->icon ? $this->icon->export_for_template($output) : null;
        $data->classes = isset($attributes['class']) ? $attributes['class'] : '';
        unset($attributes['class']);

        $data->attributes = array_map(function($key, $value) {
            return [
                'name' => $key,
                'value' => $value
            ];
        }, array_keys($attributes), $attributes);

        $data->actions = array_map(function($action) use ($output) {
            return $action->export_for_template($output);
        }, !empty($this->actions) ? $this->actions : []);
        $data->hasactions = !empty($this->actions);

        return $data;
    }