You are here

function formdefaults_form_alter in Form Defaults 8

Same name and namespace in other branches
  1. 5.3 formdefaults.module \formdefaults_form_alter()
  2. 5 formdefaults.module \formdefaults_form_alter()
  3. 5.2 formdefaults.module \formdefaults_form_alter()
  4. 6.2 formdefaults.module \formdefaults_form_alter()
  5. 6 formdefaults.module \formdefaults_form_alter()
  6. 7 formdefaults.module \formdefaults_form_alter()

implements hook_form_alter

File

./formdefaults.module, line 52

Code

function formdefaults_form_alter(&$form, &$form_state, $formid) {
  $savedform = formdefaults_getform($formid);
  _formdefaults_addon_fields($savedform, $form);
  $enabled = @($_SESSION['formdefaults_enabled'] && $formid != 'formdefaults_edit');

  //If the user has the right privs, add the links to alter the form
  $formfieldsarray = array();
  if (Drupal::currentUser()
    ->hasPermission('change form labels') && $enabled) {
    $forms = @$_SESSION['formdefaults_forms'];
    foreach ($form as $fieldname => $value) {
      _formdefaults_get_field($formid, $fieldname, $form[$fieldname], $formfieldsarray);
    }
    $forms[$formid] = $formfieldsarray;
    $_SESSION['formdefaults_forms'] = $forms;
  }
  if ($savedform) {
    foreach ($form as $fieldname => $value) {
      formdefaults_alterform($formid, $fieldname, $form[$fieldname], $savedform);
    }
  }
  if ($enabled) {
    $link = Link::createFromRoute('[' . t('edit form') . ']', 'formdefaults.edit_w_formid', [
      'formid' => $formid,
    ])
      ->toString();
    $form['formdefaults_edit_form'] = array(
      '#type' => 'markup',
      '#weight' => -50,
      '#markup' => '<p>' . $link . '</p>',
    );
  }

  //drupal_set_message('<pre>'. print_r($form,1) .'</pre>');
}