Merge branch 'MDL-76360-master' of https://github.com/laurentdavid/moodle
This commit is contained in:
@@ -71,13 +71,8 @@ class action_bar {
|
||||
debugging('Deprecated argument passed to get_fields_action_bar method', DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
$fieldselect = null;
|
||||
if ($hasfieldselect) {
|
||||
$fieldselect = $this->get_create_fields();
|
||||
}
|
||||
|
||||
$renderer = $PAGE->get_renderer('mod_data');
|
||||
$fieldsactionbar = new fields_action_bar($this->id, null, null, null, null, $fieldselect);
|
||||
$fieldsactionbar = new fields_action_bar($this->id);
|
||||
|
||||
return $renderer->render_fields_action_bar($fieldsactionbar);
|
||||
}
|
||||
@@ -100,9 +95,10 @@ class action_bar {
|
||||
/**
|
||||
* Generate the output for the create a new field action menu.
|
||||
*
|
||||
* @param bool $isprimarybutton is the action trigger a primary or secondary button?
|
||||
* @return \action_menu Action menu to create a new field
|
||||
*/
|
||||
public function get_create_fields(): \action_menu {
|
||||
public function get_create_fields(bool $isprimarybutton = false): \action_menu {
|
||||
// Get the list of possible fields (plugins).
|
||||
$plugins = \core_component::get_plugin_list('datafield');
|
||||
$menufield = [];
|
||||
@@ -112,8 +108,10 @@ class action_bar {
|
||||
asort($menufield);
|
||||
|
||||
$fieldselect = new \action_menu();
|
||||
$fieldselect->set_menu_trigger(get_string('newfield', 'mod_data'), 'btn btn-secondary');
|
||||
$fieldselectparams = ['d' => $this->id, 'mode' => 'new'];
|
||||
$triggerclasses = ['btn'];
|
||||
$triggerclasses[] = $isprimarybutton ? 'btn-primary' : 'btn-secondary';
|
||||
$fieldselect->set_menu_trigger(get_string('newfield', 'mod_data'), join(' ', $triggerclasses));
|
||||
$fieldselectparams = ['id' => $this->cmid, 'mode' => 'new'];
|
||||
foreach ($menufield as $fieldtype => $fieldname) {
|
||||
$fieldselectparams['newtype'] = $fieldtype;
|
||||
$fieldselect->add(new \action_menu_link(
|
||||
|
||||
@@ -31,9 +31,6 @@ class fields_action_bar implements templatable, renderable {
|
||||
/** @var int $id The database module id. */
|
||||
private $id;
|
||||
|
||||
/** @var \action_menu|null $fieldselect The field selector object or null. */
|
||||
private $fieldselect;
|
||||
|
||||
/**
|
||||
* The class constructor.
|
||||
*
|
||||
@@ -42,18 +39,17 @@ class fields_action_bar implements templatable, renderable {
|
||||
* @param null $unused2 This parameter has been deprecated since 4.1 and should not be used anymore.
|
||||
* @param null $unused3 This parameter has been deprecated since 4.1 and should not be used anymore.
|
||||
* @param null $unused4 This parameter has been deprecated since 4.1 and should not be used anymore.
|
||||
* @param \action_menu|null $fieldselect The field selector object or null
|
||||
* @param \action_menu|null $unused5 This parameter has been deprecated since 4.2 and should not be used anymore.
|
||||
*/
|
||||
public function __construct(int $id, $unused1 = null, $unused2 = null,
|
||||
$unused3 = null, $unused4 = null,
|
||||
?\action_menu $fieldselect = null) {
|
||||
?\action_menu $unused5 = null) {
|
||||
|
||||
if ($unused1 !== null || $unused2 !== null || $unused3 !== null || $unused4 !== null) {
|
||||
if ($unused1 !== null || $unused2 !== null || $unused3 !== null || $unused4 !== null || $unused5 !== null) {
|
||||
debugging('Deprecated argument passed to fields_action_bar constructor', DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
$this->id = $id;
|
||||
$this->fieldselect = $fieldselect;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,13 +62,9 @@ class fields_action_bar implements templatable, renderable {
|
||||
|
||||
$data = [
|
||||
'd' => $this->id,
|
||||
'tertiarytitle' => get_string('managefields', 'mod_data'),
|
||||
'title' => get_string('managefields', 'mod_data'),
|
||||
];
|
||||
|
||||
if ($this->fieldselect) {
|
||||
$data['fieldselect'] = $this->fieldselect->export_for_template($output);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -332,9 +332,12 @@ if (($mode == 'new') && (!empty($newtype))) { // Adding a new field.
|
||||
$fieldactionbar = $actionbar->get_fields_action_bar(true);
|
||||
data_print_header($course, $cm, $data, 'fields', $fieldactionbar);
|
||||
|
||||
echo $OUTPUT->box_start('mb-4');
|
||||
echo $OUTPUT->box_start();
|
||||
echo get_string('fieldshelp', 'data');
|
||||
echo $OUTPUT->box_end();
|
||||
echo $OUTPUT->box_start('d-flex flex-row-reverse');
|
||||
echo $OUTPUT->render($actionbar->get_create_fields(true));
|
||||
echo $OUTPUT->box_end();
|
||||
$table = new html_table();
|
||||
$table->head = [
|
||||
get_string('fieldname', 'data'),
|
||||
|
||||
@@ -159,10 +159,7 @@ class mod_data_renderer extends plugin_renderer_base {
|
||||
*/
|
||||
public function render_fields_action_bar(\mod_data\output\fields_action_bar $actionbar): string {
|
||||
$data = $actionbar->export_for_template($this);
|
||||
$data['title'] = get_string('nofields', 'mod_data');
|
||||
$data['intro'] = get_string('createfields', 'mod_data');
|
||||
$data['noitemsimgurl'] = $this->output->image_url('fields_zero_state', 'mod_data')->out();
|
||||
return $this->render_from_template('mod_data/fields_action_bar', $data);
|
||||
return $this->render_from_template('mod_data/action_bar', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user