/** * Sets a template entity with the POSTed data and validates it, setting * an alert if there are any errors. * * @param TemplateModel $template A Template entity * @return mixed FALSE if nothing was posted, void if it was an AJAX call, * or a ValidationResult object. */ private function validateTemplate(TemplateModel $template) { if (empty($_POST)) { return FALSE; } $template->set($_POST); $template->edit_date = ee()->localize->now; $template->last_author_id = ee()->session->userdata('member_id'); $result = $template->validate(); $field = ee()->input->post('ee_fv_field'); // The ajaxValidation method looks for the 'ee_fv_field' in the POST // data. Then it checks to see if the result object has an error // for that field. Then it'll return. Since we may be validating // a field on a TemplateRoute model we should check for that // befaore outputting an ajax response. if (!isset($_POST['save_modal']) && isset($field) && $template->hasProperty($field) && ($response = $this->ajaxValidation($result))) { ee()->output->send_ajax_response($response); } if ($result->failed()) { ee('CP/Alert')->makeInline('shared-form')->asIssue()->withTitle(lang('update_template_error'))->addToBody(lang('update_template_error_desc'))->now(); } else { $member_groups = ee('Model')->get('MemberGroup')->filter('site_id', ee()->config->item('site_id'))->filter('group_id', '!=', 1)->all(); $allowed_member_groups = ee()->input->post('allowed_member_groups') ?: array(); $template->NoAccess = $member_groups->filter(function ($group) use($allowed_member_groups) { return !in_array($group->group_id, $allowed_member_groups); }); } return $result; }