/** * Builds a standard list of eform permissions for a given type. * * @param \Drupal\eform\Entity\EFormType $type * The machine name of the eform type. * * @return array * An array of permission names and descriptions. */ protected function buildPermissions(EFormType $type) { $type_params = array('%type_name' => $type->label()); return array( $type->getPermission('submit') => array( 'title' => $this->t('%type_name: Submit', $type_params), ), $type->getPermission('edit own') => array( 'title' => $this->t('%type_name: Edit own submissions', $type_params), ), $type->getPermission('delete own') => array( 'title' => $this->t('%type_name: Delete own submissions', $type_params), ), // @todo Which other permissions should be supported? ); }
/** * @param array $form * @param $type * @param $default_value_message * * @return array */ public function EFormTypeElements(array $form, EFormType $type, $default_value_message = '') { // @todo Deal with default value logic and message from D7 $form['additional_settings'] = array( '#type' => 'vertical_tabs', ); $form['submission'] = array( '#type' => 'details', '#title' => $this->t('Submission form settings'), '#group' => 'additional_settings', ); $form['submission']['form_title'] = array( '#type' => 'textfield', '#title' => $this->t('Form Title'), '#default_value' => $type->getFormTitle(), '#description' => t('Title For submission form.'), ); $form['submission']['help'] = array( '#type' => 'textarea', '#title' => $this->t('Explanation or submission guidelines'), '#default_value' => $type->help, '#description' => t('This text will be displayed at the top of the page when creating or editing eform type of this type.'), ); //****************ACCESS FIELDSET SETTINGS *********************// $form['access'] = array( '#type' => 'details', '#title' => $this->t('Access settings'), //'#collapsible' => TRUE, '#group' => 'additional_settings', '#weight' => -50, ); $form['access']['form_status'] = array( '#type' => 'select', '#title' => $this->t('Form status'), '#options' => array( EFormType::STATUS_OPEN => $this->t('Open for new submissions'), EFormType::STATUS_CLOSED => $this->t('Closed form new form submissions'), ), '#default_value' => empty($type->form_status) ? EFormType::STATUS_OPEN : $type->form_status, '#description' => t('Can users submit this form? Open means the users can submit this form. Closed means the user can not submit the form.'), ); if ($type->isNew()) { $default_roles = []; } else { $default_roles = array_keys(user_role_names(NULL, $type->getPermission('submit'))); }; $form['access']['roles'] = array( '#type' => 'checkboxes', '#title' => t('Roles'), '#options' => array_map('\Drupal\Component\Utility\SafeMarkup::checkPlain', user_role_names()), '#default_value' => $default_roles, '#required' => TRUE, '#description' => t('Please select the Role(s) that can submit this form.'), ); $form['access']['resubmit_action'] = array( '#type' => 'select', '#title' => t('Resubmit action'), '#options' => array( EFormType::RESUBMIT_ACTION_NEW => t('Allow new submission'), EFormType::RESUBMIT_ACTION_OLD => t('Edit old submission'), EFormType::RESUBMIT_ACTION_DISALLOW => t("Don't allow"), EFormType::RESUBMIT_ACTION_CONFIRM => t('Goto Confirm page'), ), '#default_value' => $type->getResubmitAction() ? $type->getResubmitAction() : EFormType::RESUBMIT_ACTION_NEW, '#description' => t('Action to take if logged in user has already submitted form.'), ); $disallow_text = $type->getDisallowText(); $form['access']['disallow_text'] = array( '#type' => 'text_format', '#title' => $this->t('Disallow Text'), '#default_value' => empty($disallow_text['value']) ? '' : $disallow_text['value'], '#format' => empty($disallow_text['format']) ? NULL : $disallow_text['format'], '#description' => $this->t('This text will be displayed if the user has already submitted the form.') . $default_value_message, '#states' => array( 'visible' => array( array( ':input[name="resubmit_action"]' => array('value' => EFormType::RESUBMIT_ACTION_DISALLOW), ), ), ), ); //****************SUBMISSION PAGE FIELDSET SETTINGS *********************// $form['submission_page'] = array( '#type' => 'details', '#title' => $this->t('Submission page settings'), '#group' => 'additional_settings', '#weight' => 20, ); $form['submission_page']['preview_page'] = array( '#type' => 'checkbox', '#title' => $this->t('Preview Page'), '#default_value' => $type->preview_page, '#description' => t('Show a Preview page.'), ); $form['submission_page']['submission_page_title'] = array( '#type' => 'textfield', '#title' => $this->t('Submission Page Title'), '#default_value' => empty($type->getSubmissionPageTitle()) ? '' : $type->getSubmissionPageTitle(), '#description' => t('Page title for correct submission.') . $default_value_message, ); $submission_text = $type->getSubmissionText(); $form['submission_page']['submission_text'] = array( '#type' => 'text_format', '#title' => $this->t('Submission Text'), '#default_value' => empty($submission_text['value']) ? '' : $submission_text['value'], '#format' => empty($submission_text['format']) ? NULL : $submission_text['format'], '#description' => t('This text will be displayed to the user when a correct form is submitted.') . $default_value_message, ); $show_submitted = $type->isSubmissionShowSubmitted(); $form['submission_page']['submission_show_submitted'] = array( '#type' => 'checkbox', '#title' => t('Show submission information'), '#default_value' => !empty($show_submitted), '#description' => t('Show submitted data on submission page?'), ); //****************Views SETTINGS *********************// $view_options = $this->getViewOptions(); $form['submission_views'] = array( '#type' => 'details', '#title' => $this->t('Submission Views'), //'#collapsible' => TRUE, '#group' => 'additional_settings', '#weight' => 30, ); $form['submission_views']['admin_submissions_view'] = array( '#type' => 'select', '#title' => t('View for submissions reports'), '#description' => t('Select the View that should be used Submission reports.'), '#default_value' => $type->getAdminView(), '#options' => $view_options, ); $user_view_description = 'Select the View that should be used to show users their previous submissions.'; $user_view_description .= ' If "None" is selected then the users will not see a previous submissions link.'; $form['submission_views']['user_submissions_view'] = array( '#type' => 'select', '#title' => t('View for current user\'s submissions'), '#description' => t($user_view_description), '#default_value' => $type->getUserView(), '#options' => $view_options, ); //****************DRAFT SETTINGS FIELDSET SETTINGS *********************// $form['draft_settings'] = array( '#type' => 'details', '#title' => $this->t('Draft settings'), '#group' => 'additional_settings', '#weight' => 40, ); $form['draft_settings']['draftable'] = array( '#type' => 'checkbox', '#title' => $this->t('Draftable'), '#default_value' => $type->isDraftable(), '#description' => $this->t('Is Draftable?'), ); return $form; }
/** * Get the previous submission for the current user. * * @param \Drupal\eform\Entity\EFormType $eform_type * * @return \Drupal\Core\Entity\EntityInterface|null */ protected function getPreviousEFormSubmission(EFormType $eform_type) { $query = $this->entityStorage()->getQuery(); $query->condition('uid', $this->currentUser()->id()); $query->condition('type', $eform_type->type); if ($eform_type->isDraftable()) { $query->sort('draft', 'DESC'); } $query->sort('created', 'DESC'); $ids = $query->execute(); $id = array_shift($ids); $eform_submission = $this->entityStorage()->load($id); return $eform_submission; }
/** * @return \Drupal\eform\Entity\EFormType * Loaded EFormType */ public function getEFormType() { return EFormType::load($this->bundle()); }
/** * Determine if user would have at least 1 submission returned from View. * * Depending on the View used the user might not have submission returned. * @param \Drupal\eform\Entity\EFormType $eform_type * * @return bool */ function userHasViewSubmissions(EFormType $eform_type) { if ($view_name = $eform_type->getUserView()) { $display_ids = $this->getViewDisplays($view_name); $display_id = array_shift($display_ids); $results = views_get_view_result($view_name, $display_id, $eform_type->type); return !empty($results); } return FALSE; }
/** * User Submission Page title callback. * * @param \Drupal\eform\Entity\EFormType $eform_type * @param null $views_display_id * * @return string */ public function userSubmissionsTitle(EFormType $eform_type, $views_display_id = NULL) { return $this->t('@form_label: Your previous submissions', ['@form_label' => $eform_type->label()]); }