You are here

public function WebformEntitySettingsAccessForm::form in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/EntitySettings/WebformEntitySettingsAccessForm.php \Drupal\webform\EntitySettings\WebformEntitySettingsAccessForm::form()

Gets the actual form array to be built.

Overrides WebformEntitySettingsBaseForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/EntitySettings/WebformEntitySettingsAccessForm.php, line 32

Class

WebformEntitySettingsAccessForm
Webform access settings.

Namespace

Drupal\webform\EntitySettings

Code

public function form(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\webform\WebformInterface $webform */
  $webform = $this->entity;
  $form['access']['#tree'] = TRUE;
  $access = $webform
    ->getAccessRules() + $this->accessRulesManager
    ->getDefaultAccessRules();
  $access_rules = $this->accessRulesManager
    ->getAccessRulesInfo();
  foreach ($access_rules as $access_rule => $info) {
    $form['access'][$access_rule] = [
      '#type' => $access_rule === 'create' ? 'fieldset' : 'details',
      '#title' => $info['title'],
      '#open' => $access[$access_rule]['roles'] || $access[$access_rule]['users'] ? TRUE : FALSE,
      '#description' => $info['description'],
      // Never convert description to help.
      // @see _webform_preprocess_description_help()
      '#help' => FALSE,
    ];
    $form['access'][$access_rule]['roles'] = [
      '#type' => 'webform_roles',
      '#title' => $this
        ->t('Roles'),
      '#include_anonymous' => !in_array($access_rule, [
        'update_any',
        'delete_any',
        'purge_any',
      ]) ? TRUE : FALSE,
      '#default_value' => $access[$access_rule]['roles'],
    ];
    $form['access'][$access_rule]['users'] = [
      '#type' => 'webform_users',
      '#title' => $this
        ->t('Users'),
      '#default_value' => $access[$access_rule]['users'] ? $this->entityTypeManager
        ->getStorage('user')
        ->loadMultiple($access[$access_rule]['users']) : [],
    ];
    $form['access'][$access_rule]['permissions'] = [
      '#type' => 'webform_permissions',
      '#title' => $this
        ->t('Permissions'),
      '#multiple' => TRUE,
      '#select2' => TRUE,
      '#default_value' => $access[$access_rule]['permissions'],
    ];
  }
  return parent::form($form, $form_state);
}