/**
  *
  */
 protected function get_action_replacement($tag, $entry = null, array $options = null)
 {
     global $CFG, $OUTPUT, $PAGE;
     $replacement = '';
     $view = $this->_view;
     $df = $view->df;
     $filter = $view->get_filter();
     $baseurl = new \moodle_url($view->get_baseurl(), array('sesskey' => sesskey()));
     // Add entries.
     if ($tag == '##addnewentry##' or $tag == '##addnewentries##') {
         $baseurl = new \moodle_url($view->get_baseurl());
         // Can this user registered or anonymous add entries.
         if ($view->user_is_editing() or !$view->allows_submission()) {
             return '';
         }
         $accessparams = array('dataformid' => $view->dataid, 'viewid' => $view->id);
         if (!\mod_dataform\access\entry_add::validate($accessparams)) {
             return '';
         }
         if ($tag == '##addnewentry##') {
             $baseurl->param('editentries', -1);
             $label = \html_writer::tag('span', get_string('entryaddnew', 'dataform'));
             return \html_writer::link($baseurl, $label, array('class' => 'addnewentry'));
         } else {
             $options = array_combine(range(-1, -20), range(1, 20));
             $select = new \single_select(new \moodle_url($baseurl), 'editentries', $options, null, array(0 => get_string('dots', 'dataform')), 'newentries_jump');
             $select->set_label(get_string('entryaddmultinew', 'dataform') . ' ');
             return $OUTPUT->render($select);
         }
     }
     return '';
 }
 /**
  *
  */
 protected function get_display_definition(array $entries = null)
 {
     $displaydefinition = array();
     $editnewentries = null;
     $editentries = null;
     // Display a new entry to add in its own group.
     if ($this->editentries < 0) {
         $editnewentries = $this->editentries;
         $accessparams = array('dataformid' => $this->dataid, 'viewid' => $this->id);
         if (\mod_dataform\access\entry_add::validate($accessparams)) {
             $displaydefinition['newentry'] = array();
             for ($i = -1; $i >= $editnewentries; $i--) {
                 $displaydefinition['newentry'][$i] = null;
             }
         } else {
             $editnewentries = null;
         }
     } else {
         if ($this->editentries) {
             $editentries = explode(',', $this->editentries);
             $editentries = array_combine($editentries, $editentries);
         }
     }
     // Compile entries if any.
     if ($entries) {
         $groupname = '';
         $groupdefinition = array();
         foreach ($entries as $entryid => $entry) {
             // Is this entry edited.
             if ($editthisone = $editentries ? !empty($editentries[$entryid]) : false) {
                 $accessparams = array('dataformid' => $this->dataid, 'viewid' => $this->id);
                 if (!($editthisone = \mod_dataform\access\entry_update::validate($accessparams + array('entry' => $entry)))) {
                     unset($editentries[$entryid]);
                 }
             }
             // Add to the current entries group.
             $groupdefinition[$entryid] = $editthisone;
         }
         // Collect remaining definitions (all of it if no groupby).
         $displaydefinition[$groupname] = $groupdefinition;
     }
     $this->editentries = $editentries ? implode(',', $editentries) : $editnewentries;
     return $displaydefinition;
 }