Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

(no description)

File Size: 154 lines (5 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

action:: (4 methods):
  __construct()
  add_callback()
  get_action_link()
  replace_placeholders()


Class: action  - X-Ref

Class to represent a report action

__construct(moodle_url $url,pix_icon $icon,array $attributes = [],bool $popup = false,?lang_string $title = null)   X-Ref
Create an instance of an action to be added to a report. Both the parameters of the URL, and the attributes parameter
support placeholders which will be replaced with appropriate row values, e.g.:

new action(new moodle_url('/', ['id' => ':id']), new pix_icon(...), ['data-id' => ':id'])

Note that all expected placeholders should be added as base fields to the report

param: moodle_url $url
param: pix_icon $icon
param: string[] $attributes Array of attributes to include in action, each will be cast to string prior to use
param: bool $popup
param: ?lang_string $title

add_callback(callable $callback)   X-Ref
Adds callback to the action. Used to verify action is available to current user, or preprocess values used in placeholders

Multiple callbacks can be added. If at least one returns false then the action will not be displayed

param: callable $callback
return: self

get_action_link(stdClass $row)   X-Ref
Return action menu link suitable for output, or null if the action cannot be displayed (because one of its callbacks
returned false, {@see add_callback})

param: stdClass $row
return: action_menu_link|null

replace_placeholders(array $values, stdClass $row)   X-Ref
Given an array of values, replace all placeholders with corresponding property of the given row

param: string[] $values
param: stdClass $row
return: array