Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     $sanitized_id = ArgumentPluginBase::encodeValidatorId($this->definition['id']);
     $form['restrict_roles'] = array('#type' => 'checkbox', '#title' => $this->t('Restrict user based on role'), '#default_value' => $this->options['restrict_roles']);
     $form['roles'] = array('#type' => 'checkboxes', '#title' => $this->t('Restrict to the selected roles'), '#options' => array_map(array('\\Drupal\\Component\\Utility\\SafeMarkup', 'checkPlain'), user_role_names(TRUE)), '#default_value' => $this->options['roles'], '#description' => $this->t('If no roles are selected, users from any role will be allowed.'), '#states' => array('visible' => array(':input[name="options[validate][options][' . $sanitized_id . '][restrict_roles]"]' => array('checked' => TRUE))));
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $default_role_choices = user_role_names(TRUE);
     unset($default_role_choices[DRUPAL_AUTHENTICATED_RID]);
     $roles_config = $this->config('uc_role.settings');
     if (!count($default_role_choices)) {
         $form['no_roles'] = array('#markup' => $this->t('You need to <a href=":url">create new roles</a> before any can be added as product features.', [':url' => Url::fromRoute('user.role_add', [], ['query' => ['destination' => 'admin/store/config/products']])->toString()]), '#prefix' => '<p>', '#suffix' => '</p>');
         return $form;
     }
     $form['default_role'] = array('#type' => 'select', '#title' => $this->t('Default role'), '#default_value' => $roles_config->get('default_role'), '#description' => $this->t('The default role Ubercart grants on specified products.'), '#options' => _uc_role_get_choices());
     $form['default_role_choices'] = array('#type' => 'checkboxes', '#title' => $this->t('Product roles'), '#default_value' => $roles_config->get('default_role_choices'), '#multiple' => TRUE, '#description' => $this->t('These are roles that Ubercart can grant to customers who purchase specified products. If you leave all roles unchecked, they will all be eligible for adding to a product.'), '#options' => $default_role_choices);
     $form['role_lifetime'] = array('#type' => 'fieldset', '#title' => $this->t('Default role expiration'));
     $form['role_lifetime']['default_end_expiration'] = array('#type' => 'select', '#title' => $this->t('Expiration type'), '#options' => array('rel' => $this->t('Relative to purchase date'), 'abs' => $this->t('Fixed date')), '#default_value' => $roles_config->get('default_end_expiration'));
     $form['role_lifetime']['default_length'] = array('#type' => 'textfield', '#default_value' => $roles_config->get('default_granularity') == 'never' ? NULL : $roles_config->get('default_length'), '#size' => 4, '#maxlength' => 4, '#prefix' => '<div class="expiration">', '#suffix' => '</div>', '#states' => array('visible' => array('select[name="default_end_expiration"]' => array('value' => 'rel')), 'invisible' => array('select[name="default_granularity"]' => array('value' => 'never'))));
     $form['role_lifetime']['default_granularity'] = array('#type' => 'select', '#default_value' => $roles_config->get('default_granularity'), '#options' => array('never' => $this->t('never'), 'day' => $this->t('day(s)'), 'week' => $this->t('week(s)'), 'month' => $this->t('month(s)'), 'year' => $this->t('year(s)')), '#description' => $this->t('From the time the role was purchased.'), '#prefix' => '<div class="expiration">', '#suffix' => '</div>', '#states' => array('visible' => array('select[name="default_end_expiration"]' => array('value' => 'rel'))));
     $form['role_lifetime']['absolute'] = array('#type' => 'container', '#states' => array('visible' => array('select[name="default_end_expiration"]' => array('value' => 'abs'))));
     $date = (int) $roles_config->get('default_end_time');
     $date = !empty($date) ? DrupalDateTime::createFromTimestamp($date) : DrupalDateTime::createFromTimestamp(REQUEST_TIME);
     $form['role_lifetime']['absolute']['default_end_time'] = array('#type' => 'datetime', '#description' => $this->t('Expire the role at the beginning of this day.'), '#date_date_element' => 'date', '#date_time_element' => 'none', '#default_value' => $date);
     $form['role_lifetime']['default_by_quantity'] = array('#type' => 'checkbox', '#title' => $this->t('Multiply by quantity'), '#description' => $this->t('Check if the role duration should be multiplied by the quantity purchased.'), '#default_value' => $roles_config->get('default_by_quantity'));
     $form['reminder']['reminder_length'] = array('#type' => 'textfield', '#title' => $this->t('Time before reminder'), '#default_value' => $roles_config->get('reminder_granularity') == 'never' ? NULL : $roles_config->get('reminder_length'), '#size' => 4, '#maxlength' => 4, '#prefix' => '<div class="expiration">', '#suffix' => '</div>', '#states' => array('disabled' => array('select[name="reminder_granularity"]' => array('value' => 'never'))));
     $form['reminder']['reminder_granularity'] = array('#type' => 'select', '#default_value' => $roles_config->get('reminder_granularity'), '#options' => array('never' => $this->t('never'), 'day' => $this->t('day(s)'), 'week' => $this->t('week(s)'), 'month' => $this->t('month(s)'), 'year' => $this->t('year(s)')), '#description' => $this->t('The amount of time before a role expiration takes place that a customer is notified of its expiration.'), '#prefix' => '<div class="expiration">', '#suffix' => '</div>');
     $form['default_show_expiration'] = array('#type' => 'checkbox', '#title' => $this->t('Show expirations on user page'), '#default_value' => $roles_config->get('default_show_expiration'), '#description' => $this->t('If users have any role expirations they will be displayed on their account page.'));
     return parent::buildForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function buildConfigurationForm(array $form, array &$form_state)
 {
     $roles = user_role_names(TRUE);
     unset($roles[DRUPAL_AUTHENTICATED_RID]);
     $form['rid'] = array('#type' => 'radios', '#title' => t('Role'), '#options' => $roles, '#default_value' => $this->configuration['rid'], '#required' => TRUE);
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['to']['#markup'] = $this->stateStorage->load($entity->getToState())->label();
     $row['label'] = $entity->label();
     $row['roles']['#markup'] = implode(', ', user_role_names(FALSE, 'use ' . $entity->id() . ' transition'));
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function summary()
 {
     if (!$this->configuration['roles']) {
         return $this->t('Any registered user');
     }
     $roles = array_intersect_key(user_role_names(), $this->configuration['roles']);
     return $this->t(empty($this->configuration['negate']) ? 'User is a member of @roles' : 'User is not a member of @roles', ['@roles' => count($roles) > 1 ? implode(' and ', $roles) : reset($roles)]);
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $format = $this->entity;
     $is_fallback = $format->id() == $this->config('filter.settings')->get('fallback_format');
     $form['#tree'] = TRUE;
     $form['#attached']['library'][] = 'filter/drupal.filter.admin';
     $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Name'), '#default_value' => $format->label(), '#required' => TRUE, '#weight' => -30);
     $form['format'] = array('#type' => 'machine_name', '#required' => TRUE, '#default_value' => $format->id(), '#maxlength' => 255, '#machine_name' => array('exists' => array($this, 'exists'), 'source' => array('name')), '#disabled' => !$format->isNew(), '#weight' => -20);
     // Add user role access selection.
     $form['roles'] = array('#type' => 'checkboxes', '#title' => $this->t('Roles'), '#options' => array_map('\\Drupal\\Component\\Utility\\String::checkPlain', user_role_names()), '#disabled' => $is_fallback, '#weight' => -10);
     if ($is_fallback) {
         $form['roles']['#description'] = $this->t('All roles for this text format must be enabled and cannot be changed.');
     }
     if (!$format->isNew()) {
         // If editing an existing text format, pre-select its current permissions.
         $form['roles']['#default_value'] = array_keys(filter_get_roles_by_format($format));
     } elseif ($admin_role = $this->config('user.settings')->get('admin_role')) {
         // If adding a new text format and the site has an administrative role,
         // pre-select that role so as to grant administrators access to the new
         // text format permission by default.
         $form['roles']['#default_value'] = array($admin_role);
     }
     // Create filter plugin instances for all available filters, including both
     // enabled/configured ones as well as new and not yet unconfigured ones.
     $filters = $format->filters();
     foreach ($filters as $filter_id => $filter) {
         // When a filter is missing, it is replaced by the null filter. Remove it
         // here, so that saving the form will remove the missing filter.
         if ($filter instanceof FilterNull) {
             drupal_set_message($this->t('The %filter filter is missing, and will be removed once this format is saved.', array('%filter' => $filter_id)), 'warning');
             $filters->removeInstanceID($filter_id);
         }
     }
     // Filter status.
     $form['filters']['status'] = array('#type' => 'item', '#title' => $this->t('Enabled filters'), '#prefix' => '<div id="filters-status-wrapper">', '#suffix' => '</div>', '#input' => FALSE);
     // Filter order (tabledrag).
     $form['filters']['order'] = array('#type' => 'table', '#attributes' => array('id' => 'filter-order'), '#title' => $this->t('Filter processing order'), '#tabledrag' => array(array('action' => 'order', 'relationship' => 'sibling', 'group' => 'filter-order-weight')), '#tree' => FALSE, '#input' => FALSE, '#theme_wrappers' => array('form_element'));
     // Filter settings.
     $form['filter_settings'] = array('#type' => 'vertical_tabs', '#title' => $this->t('Filter settings'));
     foreach ($filters as $name => $filter) {
         $form['filters']['status'][$name] = array('#type' => 'checkbox', '#title' => $filter->getLabel(), '#default_value' => $filter->status, '#parents' => array('filters', $name, 'status'), '#description' => $filter->getDescription(), '#weight' => $filter->weight);
         $form['filters']['order'][$name]['#attributes']['class'][] = 'draggable';
         $form['filters']['order'][$name]['#weight'] = $filter->weight;
         $form['filters']['order'][$name]['filter'] = array('#markup' => $filter->getLabel());
         $form['filters']['order'][$name]['weight'] = array('#type' => 'weight', '#title' => $this->t('Weight for @title', array('@title' => $filter->getLabel())), '#title_display' => 'invisible', '#delta' => 50, '#default_value' => $filter->weight, '#parents' => array('filters', $name, 'weight'), '#attributes' => array('class' => array('filter-order-weight')));
         // Retrieve the settings form of the filter plugin. The plugin should not be
         // aware of the text format. Therefore, it only receives a set of minimal
         // base properties to allow advanced implementations to work.
         $settings_form = array('#parents' => array('filters', $name, 'settings'), '#tree' => TRUE);
         $settings_form = $filter->settingsForm($settings_form, $form_state);
         if (!empty($settings_form)) {
             $form['filters']['settings'][$name] = array('#type' => 'details', '#title' => $filter->getLabel(), '#open' => TRUE, '#weight' => $filter->weight, '#parents' => array('filters', $name, 'settings'), '#group' => 'filter_settings');
             $form['filters']['settings'][$name] += $settings_form;
         }
     }
     return parent::form($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Get all available roles except for
     // 'anonymous user' and 'authenticated user'.
     $roles = user_role_names(TRUE);
     unset($roles[RoleInterface::AUTHENTICATED_ID]);
     // Show checkboxes with roles that can be delegated if any.
     if ($roles) {
         $config = $this->config('roleassign.settings');
         $form['roleassign_roles'] = array('#type' => 'checkboxes', '#title' => $this->t('Roles'), '#default_value' => $config->get('roleassign_roles'), '#options' => $roles, '#description' => $this->t('Select roles that should be available for assignment.'));
     }
     return parent::buildForm($form, $form_state);
 }
 /**
  *
  */
 public function createConditionElements() {
   $elements['condition_config'] = [
     '#tree' => TRUE,
   ];
   // @todo Dynamically create condition for by call ConditionPluginBase::buildConfigurationForm?
   $elements['condition_config']['roles'] = array(
     '#type' => 'checkboxes',
     '#title' => $this->t('When the user has the following roles'),
     '#options' => array_map('\Drupal\Component\Utility\Html::escape', user_role_names()),
     // '#description' => $this->t('If you select no roles, the condition will evaluate to TRUE for all users.'),.
   );
   return $elements;
 }
 /**
  * {@inheritdoc}
  *
  * Replace the configured permission with a filter by all roles that have this
  * permission.
  */
 public function query()
 {
     // @todo user_role_names() should maybe support multiple permissions.
     $rids = array();
     // Get all roles, that have the configured permissions.
     foreach ($this->value as $permission) {
         $roles = user_role_names(FALSE, $permission);
         $rids += array_keys($roles);
     }
     $rids = array_unique($rids);
     $this->value = $rids;
     // $this->value contains the role IDs that have the configured permission.
     parent::query();
 }
Exemple #10
0
 /**
  * {@inheritdoc}
  */
 public function summary()
 {
     // Use the role labels. They will be sanitized below.
     $roles = array_intersect_key(user_role_names(), $this->configuration['roles']);
     if (count($roles) > 1) {
         $roles = implode(', ', $roles);
     } else {
         $roles = reset($roles);
     }
     if (!empty($this->configuration['negate'])) {
         return $this->t('The user is not a member of @roles', array('@roles' => $roles));
     } else {
         return $this->t('The user is a member of @roles', array('@roles' => $roles));
     }
 }
Exemple #11
0
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $form['num'] = array('#type' => 'number', '#title' => $this->t('How many users would you like to generate?'), '#default_value' => $this->getSetting('num'), '#required' => TRUE, '#min' => 0);
     $form['kill'] = array('#type' => 'checkbox', '#title' => $this->t('Delete all users (except user id 1) before generating new users.'), '#default_value' => $this->getSetting('kill'));
     $options = user_role_names(TRUE);
     unset($options[DRUPAL_AUTHENTICATED_RID]);
     $form['roles'] = array('#type' => 'checkboxes', '#title' => $this->t('Which roles should the users receive?'), '#description' => $this->t('Users always receive the <em>authenticated user</em> role.'), '#options' => $options);
     $form['pass'] = array('#type' => 'textfield', '#title' => $this->t('Password to be set'), '#default_value' => $this->getSetting('pass'), '#size' => 32, '#description' => $this->t('Leave this field empty if you do not need to set a password'));
     $options = array(1 => $this->t('Now'));
     foreach (array(3600, 86400, 604800, 2592000, 31536000) as $interval) {
         $options[$interval] = $this->dateFormatter->formatInterval($interval, 1) . ' ' . $this->t('ago');
     }
     $form['time_range'] = array('#type' => 'select', '#title' => $this->t('How old should user accounts be?'), '#description' => $this->t('User ages will be distributed randomly from the current time, back to the selected time.'), '#options' => $options, '#default_value' => 604800);
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public static function settingsForm(FieldDefinitionInterface $field_definition)
 {
     $selection_handler_settings = $field_definition->getSetting('handler_settings');
     // Merge in default values.
     $selection_handler_settings += array('filter' => array('type' => '_none'));
     // Add user specific filter options.
     $form['filter']['type'] = array('#type' => 'select', '#title' => t('Filter by'), '#options' => array('_none' => t('- None -'), 'role' => t('User role')), '#ajax' => TRUE, '#limit_validation_errors' => array(), '#default_value' => $selection_handler_settings['filter']['type']);
     $form['filter']['settings'] = array('#type' => 'container', '#attributes' => array('class' => array('entity_reference-settings')), '#process' => array('_entity_reference_form_process_merge_parent'));
     if ($selection_handler_settings['filter']['type'] == 'role') {
         // Merge in default values.
         $selection_handler_settings['filter'] += array('role' => NULL);
         $form['filter']['settings']['role'] = array('#type' => 'checkboxes', '#title' => t('Restrict to the selected roles'), '#required' => TRUE, '#options' => array_diff_key(user_role_names(TRUE), array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID)), '#default_value' => $selection_handler_settings['filter']['role']);
     }
     $form += parent::settingsForm($field_definition);
     return $form;
 }
 /**
  * Implements \Drupal\Core\Form\FormInterface::buildForm().
  *
  * @param array $form
  *   The form array.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The form state.
  *
  * @return array $form
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form['#tree'] = TRUE;
     $form['config'] = ['#type' => 'fieldset', '#title' => $this->t('Options')];
     $roles = user_role_names();
     unset($roles['anonymous']);
     $form['config']['roles'] = ['#type' => 'checkboxes', '#title' => $this->t('Roles'), '#options' => $roles];
     // Special handling for the inevitable "Authenticated user" role.
     $form['config']['roles'][RoleInterface::AUTHENTICATED_ID] = array('#default_value' => TRUE, '#disabled' => TRUE);
     $form['file'] = ['#type' => 'file', '#title' => 'CSV file upload', '#upload_validators' => ['file_validate_extensions' => ['csv']]];
     $form['actions']['#type'] = 'actions';
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Import users'), '#button_type' => 'primary');
     // By default, render the form using theme_system_config_form().
     $form['#theme'] = 'system_config_form';
     return $form;
 }
Exemple #14
0
 /**
  * {@inheritdoc}
  */
 public function buildConfigurationForm(array $form, FormStateInterface $form_state)
 {
     $selection_handler_settings = $this->configuration['handler_settings'];
     // Merge in default values.
     $selection_handler_settings += array('filter' => array('type' => '_none'), 'include_anonymous' => TRUE);
     $form['include_anonymous'] = array('#type' => 'checkbox', '#title' => $this->t('Include the anonymous user.'), '#default_value' => $selection_handler_settings['include_anonymous']);
     // Add user specific filter options.
     $form['filter']['type'] = array('#type' => 'select', '#title' => $this->t('Filter by'), '#options' => array('_none' => $this->t('- None -'), 'role' => $this->t('User role')), '#ajax' => TRUE, '#limit_validation_errors' => array(), '#default_value' => $selection_handler_settings['filter']['type']);
     $form['filter']['settings'] = array('#type' => 'container', '#attributes' => array('class' => array('entity_reference-settings')), '#process' => array(array('\\Drupal\\Core\\Field\\Plugin\\Field\\FieldType\\EntityReferenceItem', 'formProcessMergeParent')));
     if ($selection_handler_settings['filter']['type'] == 'role') {
         // Merge in default values.
         $selection_handler_settings['filter'] += array('role' => NULL);
         $form['filter']['settings']['role'] = array('#type' => 'checkboxes', '#title' => $this->t('Restrict to the selected roles'), '#required' => TRUE, '#options' => array_diff_key(user_role_names(TRUE), array(RoleInterface::AUTHENTICATED_ID => RoleInterface::AUTHENTICATED_ID)), '#default_value' => $selection_handler_settings['filter']['role']);
     }
     $form += parent::buildConfigurationForm($form, $form_state);
     return $form;
 }
Exemple #15
0
 /**
  * {@inheritdoc}
  *
  * Replace the configured permission with a filter by all roles that have this
  * permission.
  */
 public function query()
 {
     // @todo user_role_names() should maybe support multiple permissions.
     $rids = array();
     // Get all role IDs that have the configured permissions.
     foreach ($this->value as $permission) {
         $roles = user_role_names(FALSE, $permission);
         // user_role_names() returns an array with the role IDs as keys, so take
         // the array keys and merge them with previously found role IDs.
         $rids = array_merge($rids, array_keys($roles));
     }
     // Remove any duplicate role IDs.
     $rids = array_unique($rids);
     $this->value = $rids;
     // $this->value contains the role IDs that have the configured permission.
     parent::query();
 }
 /**
  * Tests the user bulk form.
  */
 public function testBulkForm()
 {
     $this->drupalLogin($this->drupalCreateUser(array('administer permissions')));
     // Test submitting the page with no selection.
     $edit = array('action' => 'user_block_user_action');
     $this->drupalPostForm('test-user-bulk-form', $edit, t('Apply'));
     $this->assertText(t('No users selected.'));
     // Assign a role to a user.
     $account = entity_load('user', $this->users[0]->id());
     $roles = user_role_names(TRUE);
     unset($roles[DRUPAL_AUTHENTICATED_RID]);
     $role = key($roles);
     $this->assertFalse($account->hasRole($role), 'The user currently does not have a custom role.');
     $edit = array('user_bulk_form[1]' => TRUE, 'action' => 'user_add_role_action.' . $role);
     $this->drupalPostForm(NULL, $edit, t('Apply'));
     // Re-load the user and check their roles.
     $account = entity_load('user', $account->id(), TRUE);
     $this->assertTrue($account->hasRole($role), 'The user now has the custom role.');
     $edit = array('user_bulk_form[1]' => TRUE, 'action' => 'user_remove_role_action.' . $role);
     $this->drupalPostForm(NULL, $edit, t('Apply'));
     // Re-load the user and check their roles.
     $account = entity_load('user', $account->id(), TRUE);
     $this->assertFalse($account->hasRole($role), 'The user no longer has the custom role.');
     // Block a user using the bulk form.
     $this->assertTrue($account->isActive(), 'The user is not blocked.');
     $this->assertRaw($account->label(), 'The user is found in the table.');
     $edit = array('user_bulk_form[1]' => TRUE, 'action' => 'user_block_user_action');
     $this->drupalPostForm(NULL, $edit, t('Apply'));
     // Re-load the user and check their status.
     $account = entity_load('user', $account->id(), TRUE);
     $this->assertTrue($account->isBlocked(), 'The user is blocked.');
     $this->assertNoRaw($account->label(), 'The user is not found in the table.');
     // Remove the user status filter from the view.
     $view = Views::getView('test_user_bulk_form');
     $view->removeHandler('default', 'filter', 'status');
     $view->storage->save();
     // Ensure the anonymous user is found.
     $this->drupalGet('test-user-bulk-form');
     $this->assertText(\Drupal::config('user.settings')->get('anonymous'));
     // Attempt to block the anonymous user.
     $edit = array('user_bulk_form[0]' => TRUE, 'action' => 'user_block_user_action');
     $this->drupalPostForm(NULL, $edit, t('Apply'));
     $anonymous_account = user_load(0);
     $this->assertTrue($anonymous_account->isBlocked(), 'Ensure the anonymous user got blocked.');
 }
Exemple #17
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['username']['data'] = array('#theme' => 'username', '#account' => $entity);
     $row['status'] = $entity->isActive() ? $this->t('active') : $this->t('blocked');
     $roles = array_map('\\Drupal\\Component\\Utility\\String::checkPlain', user_role_names(TRUE));
     unset($roles[DRUPAL_AUTHENTICATED_RID]);
     $users_roles = array();
     foreach ($entity->getRoles() as $role) {
         if (isset($roles[$role])) {
             $users_roles[] = $roles[$role];
         }
     }
     asort($users_roles);
     $row['roles']['data'] = array('#theme' => 'item_list', '#items' => $users_roles);
     $row['member_for'] = format_interval(REQUEST_TIME - $entity->getCreatedTime());
     $row['access'] = $entity->access ? $this->t('@time ago', array('@time' => format_interval(REQUEST_TIME - $entity->getLastAccessedTime()))) : t('never');
     return $row + parent::buildRow($entity);
 }
Exemple #18
0
  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form, $form_state);

    $form['roles'] = array(
      '#type' => 'checkboxes',
      '#title' => $this->t('Restrict to the selected roles'),
      '#options' => array_diff_key(user_role_names(TRUE), array(RoleInterface::AUTHENTICATED_ID => RoleInterface::AUTHENTICATED_ID)),
      '#default_value' =>  $this->configuration['roles'],
      '#description' => $this->t('If none of the checkboxes is checked, allow all roles.'),
      '#element_validate' => [[get_class($this), 'elementValidateFilter']],
    );

    $form['include_blocked'] = [
      '#title' => t('Include blocked user'),
      '#type' => 'checkbox',
      '#default_value' => $this->configuration['include_blocked'],
      '#description' => t('In order to see blocked users, the requesting user must also have permissions to do so.'),
    ];

    return $form;
  }
Exemple #19
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('cas.settings');
     $form['server'] = array('#type' => 'details', '#title' => $this->t('CAS Server'), '#open' => TRUE, '#tree' => TRUE);
     $form['server']['version'] = array('#type' => 'radios', '#title' => $this->t('Version'), '#options' => array('1.0' => $this->t('1.0'), '2.0' => $this->t('2.0 or higher')), '#default_value' => $config->get('server.version'));
     $form['server']['hostname'] = array('#type' => 'textfield', '#title' => $this->t('Hostname'), '#description' => $this->t('Hostname or IP Address of the CAS server.'), '#size' => 30, '#default_value' => $config->get('server.hostname'));
     $form['server']['port'] = array('#type' => 'textfield', '#title' => $this->t('Port'), '#size' => 5, '#description' => $this->t('443 is the standard SSL port. 8443 is the standard non-root port for Tomcat.'), '#default_value' => $config->get('server.port'));
     $form['server']['path'] = array('#type' => 'textfield', '#title' => $this->t('URI'), '#description' => $this->t('If CAS is not at the root of the host, include a URI (e.g., /cas).'), '#size' => 30, '#default_value' => $config->get('server.path'));
     $form['server']['verify'] = array('#type' => 'radios', '#title' => 'SSL Verification', '#description' => $this->t('Choose an appropriate option for verifying the certificate of your CAS server.'), '#options' => array(CasHelper::CA_DEFAULT => $this->t('Verify using web server\'s default certificates.'), CasHelper::CA_NONE => $this->t('Do not verify CAS server. (Note: this should NEVER be used in production.)'), CasHelper::CA_CUSTOM => $this->t('Verify using a custom certificate in the local filesystem. Use the field below to provide path.')), '#default_value' => $config->get('server.verify'));
     $form['server']['cert'] = array('#type' => 'textfield', '#title' => $this->t('Custom Certificate Authority PEM Certificate'), '#description' => $this->t('The PEM certificate of the Certificate Authority that issued the certificate on the CAS server, used only with the custom certificate option above.'), '#default_value' => $config->get('server.cert'), '#states' => array('visible' => array(':input[name="server[verify]"]' => array('value' => CasHelper::CA_CUSTOM))));
     $form['gateway'] = array('#type' => 'details', '#title' => $this->t('Gateway Feature (Auto Login)'), '#open' => FALSE, '#tree' => TRUE, '#description' => $this->t('This implements the <a href="@cas-gateway">Gateway feature</a> of the CAS Protocol. ' . 'When enabled, Drupal will check if a visitor is already logged into your CAS server before ' . 'serving a page request. If they have an active CAS session, they will be automatically ' . 'logged into the Drupal site. This is done by quickly redirecting them to the CAS server to perform the ' . 'active session check, and then redirecting them back to page they initially requested.<br/><br/>' . 'If enabled, all pages on your site will trigger this feature. You can instead enable ' . 'this feature for only specific pages by listing them below.<br/><br/>' . '<strong>WARNING:</strong> This feature is NOT compatible with the Internal Page Cache module or external ' . 'page caching software like Varnish.', array('@cas-gateway' => 'https://wiki.jasig.org/display/CAS/gateway')));
     $form['gateway']['check_frequency'] = array('#type' => 'radios', '#title' => $this->t('Check Frequency'), '#default_value' => $config->get('gateway.check_frequency'), '#options' => array(CasHelper::CHECK_NEVER => 'Disable gateway feature', CasHelper::CHECK_ONCE => 'Once per browser session', CasHelper::CHECK_ALWAYS => 'Every page load (not recommended)'));
     $this->gatewayPaths->setConfiguration($config->get('gateway.paths'));
     $form['gateway']['paths'] = $this->gatewayPaths->buildConfigurationForm(array(), $form_state);
     $form['forced_login'] = array('#type' => 'details', '#title' => $this->t('Forced Login'), '#open' => FALSE, '#tree' => TRUE, '#description' => $this->t('Anonymous users will be forced to login through CAS when enabled. ' . 'This differs from the "gateway feature" in that it will REQUIRE that a user be logged in to their CAS ' . 'account, instead of just checking if they already are.<br/><br/>' . '<strong>WARNING:</strong> This feature is NOT compatible with the Internal Page Cache module or external ' . 'page caching software like Varnish.'));
     $form['forced_login']['enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Enable'), '#description' => $this->t('When enabled, every path will force a CAS login, unless specific pages are listed below.'), '#default_value' => $config->get('forced_login.enabled'));
     $this->forcedLoginPaths->setConfiguration($config->get('forced_login.paths'));
     $form['forced_login']['paths'] = $this->forcedLoginPaths->buildConfigurationForm(array(), $form_state);
     $form['user_accounts'] = array('#type' => 'details', '#title' => $this->t('User Account Handling'), '#open' => FALSE, '#tree' => TRUE);
     $form['user_accounts']['auto_register'] = array('#type' => 'checkbox', '#title' => $this->t('Auto Register Users'), '#description' => $this->t('Enable to automatically create local Drupal accounts for first-time CAS logins. ' . 'If disabled, users must be pre-registered before being allowed to log in.'), '#default_value' => $config->get('user_accounts.auto_register'));
     $auto_assigned_roles = $config->get('user_accounts.auto_assigned_roles');
     $form['user_accounts']['auto_assigned_roles_enable'] = array('#type' => 'checkbox', '#title' => t('Automatically assign roles on user registration'), '#default_value' => count($auto_assigned_roles) > 0, '#states' => array('invisible' => array('input[name="user_accounts[auto_register]"]' => array('checked' => FALSE))));
     $roles = user_role_names(TRUE);
     unset($roles[RoleInterface::AUTHENTICATED_ID]);
     $form['user_accounts']['auto_assigned_roles'] = array('#type' => 'select', '#multiple' => TRUE, '#title' => t('Roles'), '#description' => t('The selected roles will be automatically assigned to each CAS user on login. Use this to automatically give CAS users additional privileges or to identify CAS users to other modules.'), '#default_value' => $auto_assigned_roles, '#options' => $roles, '#states' => array('invisible' => array('input[name="user_accounts[auto_assigned_roles_enable]"]' => array('checked' => FALSE))));
     $form['logout'] = array('#type' => 'details', '#title' => $this->t('Logout Behavior'), '#open' => FALSE, '#tree' => TRUE);
     $form['logout']['cas_logout'] = array('#type' => 'checkbox', '#title' => $this->t('Drupal Logout Triggers CAS Logout'), '#description' => $this->t('When enabled, users that log out of your Drupal site will then be logged out of your CAS server as well. This is done by redirecting the user to the CAS logout page.'), '#default_value' => $config->get('logout.cas_logout'));
     $form['logout']['logout_destination'] = array('#type' => 'textfield', '#title' => $this->t('Logout destination'), '#description' => $this->t('Drupal path or URL. Enter a destination if you want the CAS Server to ' . 'redirect the user after logging out of CAS.'), '#default_value' => $config->get('logout.logout_destination'));
     $form['logout']['enable_single_logout'] = array('#type' => 'checkbox', '#title' => $this->t('Enable single log out?'), '#default_value' => $config->get('logout.enable_single_logout'), '#description' => $this->t('If enabled (and your CAS server supports it), ' . 'users will be logged out of your Drupal site when they log out of your ' . 'CAS server. NOTE: THIS WILL REMOVE A SECURITY HARDENING FEATURE ADDED ' . 'IN DRUPAL 8! Session IDs to be stored unhashed in the database.'));
     $form['proxy'] = array('#type' => 'details', '#title' => $this->t('Proxy'), '#open' => FALSE, '#tree' => TRUE, '#description' => $this->t('These options relate to the proxy feature of the CAS protocol, ' . 'including configuring this client as a proxy and configuring ' . 'this client to accept proxied connections from other clients.'));
     $form['proxy']['initialize'] = array('#type' => 'checkbox', '#title' => $this->t('Initialize this client as a proxy?'), '#description' => $this->t('Initializing this client as a proxy allows it to access ' . 'CAS-protected resources from other clients that have been ' . 'configured to accept it as a proxy.'), '#default_value' => $config->get('proxy.initialize'));
     $form['proxy']['can_be_proxied'] = array('#type' => 'checkbox', '#title' => $this->t('Allow this client to be proxied?'), '#description' => $this->t('Allow other CAS clients to access this site\'s resources via the ' . 'CAS proxy protocol. You will need to configure a list of allowed ' . 'proxies below.'), '#default_value' => $config->get('proxy.can_be_proxied'));
     $form['proxy']['proxy_chains'] = array('#type' => 'textarea', '#title' => $this->t('Allowed proxy chains'), '#description' => $this->t('A list of proxy chains to allow proxy connections from. Each line ' . 'is a chain, and each chain is a whitespace delimited list of ' . 'URLs for an allowed proxy in the chain, listed from most recent ' . '(left) to first (right). Each URL in the chain can be either a ' . 'plain URL or a URL-matching regular expression (delimited only by ' . 'slashes). Only if the proxy list returned by the CAS Server exactly ' . 'matches a chain in this list will a proxy connection be allowed.'), '#default_value' => $config->get('proxy.proxy_chains'));
     $form['debugging'] = array('#type' => 'details', '#title' => $this->t('Debugging'), '#open' => FALSE, '#tree' => TRUE, '#description' => $this->t('These options are for debugging only, and are not meant to be used ' . 'in normal production usage.'));
     $form['debugging']['log'] = array('#type' => 'checkbox', '#title' => $this->t('Log debug information?'), '#description' => $this->t('This is not meant for production sites! Enable this to log debug ' . 'information about the interactions with the CAS Server to the ' . 'Drupal log.'), '#default_value' => $config->get('debugging.log'));
     return parent::buildForm($form, $form_state);
 }
Exemple #20
0
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     $form['role'] = array('#type' => 'checkboxes', '#title' => $this->t('Role'), '#default_value' => $this->options['role'], '#options' => array_map('\\Drupal\\Component\\Utility\\Html::escape', user_role_names()), '#description' => $this->t('Only the checked roles will be able to access this display.'));
 }
Exemple #21
0
 /**
  * {@inheritdoc}
  */
 public function userAddRole(\stdClass $user, $role_name)
 {
     // Allow both machine and human role names.
     $roles = user_role_names();
     $id = array_search($role_name, $roles);
     if (FALSE !== $id) {
         $role_name = $id;
     }
     if (!($role = user_role_load($role_name))) {
         throw new \RuntimeException(sprintf('No role "%s" exists.', $role_name));
     }
     $account = \user_load($user->uid);
     $account->addRole($role->id());
     $account->save();
 }
 /**
  * {@inheritdoc}
  */
 public static function postLoad(EntityStorageInterface $storage_controller, array &$entities)
 {
     parent::postLoad($storage_controller, $entities);
     foreach ($entities as $entity) {
         $permission = $entity->getPermissionName();
         if ($permission) {
             $roles = array_keys(user_role_names(FALSE, $permission));
             $entity->setBypassRoles($roles);
         }
     }
 }
 /**
  * Options form subform for exposed filter options.
  *
  * @see buildOptionsForm()
  */
 public function buildExposeForm(&$form, FormStateInterface $form_state)
 {
     $form['#theme'] = 'views_ui_expose_filter_form';
     // #flatten will move everything from $form['expose'][$key] to $form[$key]
     // prior to rendering. That's why the preRender for it needs to run first,
     // so that when the next preRender (the one for fieldsets) runs, it gets
     // the flattened data.
     array_unshift($form['#pre_render'], array(get_class($this), 'preRenderFlattenData'));
     $form['expose']['#flatten'] = TRUE;
     if (empty($this->always_required)) {
         $form['expose']['required'] = array('#type' => 'checkbox', '#title' => $this->t('Required'), '#default_value' => $this->options['expose']['required']);
     } else {
         $form['expose']['required'] = array('#type' => 'value', '#value' => TRUE);
     }
     $form['expose']['label'] = array('#type' => 'textfield', '#default_value' => $this->options['expose']['label'], '#title' => $this->t('Label'), '#size' => 40);
     $form['expose']['description'] = array('#type' => 'textfield', '#default_value' => $this->options['expose']['description'], '#title' => $this->t('Description'), '#size' => 60);
     if (!empty($form['operator']['#type'])) {
         // Increase the width of the left (operator) column.
         $form['operator']['#prefix'] = '<div class="views-group-box views-left-40">';
         $form['operator']['#suffix'] = '</div>';
         $form['value']['#prefix'] = '<div class="views-group-box views-right-60">';
         $form['value']['#suffix'] = '</div>';
         $form['expose']['use_operator'] = array('#type' => 'checkbox', '#title' => $this->t('Expose operator'), '#description' => $this->t('Allow the user to choose the operator.'), '#default_value' => !empty($this->options['expose']['use_operator']));
         $form['expose']['operator_id'] = array('#type' => 'textfield', '#default_value' => $this->options['expose']['operator_id'], '#title' => $this->t('Operator identifier'), '#size' => 40, '#description' => $this->t('This will appear in the URL after the ? to identify this operator.'), '#states' => array('visible' => array(':input[name="options[expose][use_operator]"]' => array('checked' => TRUE))));
     } else {
         $form['expose']['operator_id'] = array('#type' => 'value', '#value' => '');
     }
     if (empty($this->alwaysMultiple)) {
         $form['expose']['multiple'] = array('#type' => 'checkbox', '#title' => $this->t('Allow multiple selections'), '#description' => $this->t('Enable to allow users to select multiple items.'), '#default_value' => $this->options['expose']['multiple']);
     }
     $form['expose']['remember'] = array('#type' => 'checkbox', '#title' => $this->t('Remember the last selection'), '#description' => $this->t('Enable to remember the last selection made by the user.'), '#default_value' => $this->options['expose']['remember']);
     $role_options = array_map('\\Drupal\\Component\\Utility\\SafeMarkup::checkPlain', user_role_names());
     $form['expose']['remember_roles'] = array('#type' => 'checkboxes', '#title' => $this->t('User roles'), '#description' => $this->t('Remember exposed selection only for the selected user role(s). If you select no roles, the exposed data will never be stored.'), '#default_value' => $this->options['expose']['remember_roles'], '#options' => $role_options, '#states' => array('invisible' => array(':input[name="options[expose][remember]"]' => array('checked' => FALSE))));
     $form['expose']['identifier'] = array('#type' => 'textfield', '#default_value' => $this->options['expose']['identifier'], '#title' => $this->t('Filter identifier'), '#size' => 40, '#description' => $this->t('This will appear in the URL after the ? to identify this filter. Cannot be blank.'));
 }
 /**
  * Tests if text format is available to a role.
  */
 function testFormatRoles()
 {
     // Get the role ID assigned to the regular user.
     $roles = $this->webUser->getRoles(TRUE);
     $rid = $roles[0];
     // Check that this role appears in the list of roles that have access to an
     // allowed text format, but does not appear in the list of roles that have
     // access to a disallowed text format.
     $this->assertTrue(in_array($rid, array_keys(filter_get_roles_by_format($this->allowedFormat))), 'A role which has access to a text format appears in the list of roles that have access to that format.');
     $this->assertFalse(in_array($rid, array_keys(filter_get_roles_by_format($this->disallowedFormat))), 'A role which does not have access to a text format does not appear in the list of roles that have access to that format.');
     // Check that the correct text format appears in the list of formats
     // available to that role.
     $this->assertTrue(in_array($this->allowedFormat->id(), array_keys(filter_get_formats_by_role($rid))), 'A text format which a role has access to appears in the list of formats available to that role.');
     $this->assertFalse(in_array($this->disallowedFormat->id(), array_keys(filter_get_formats_by_role($rid))), 'A text format which a role does not have access to does not appear in the list of formats available to that role.');
     // Check that the fallback format is always allowed.
     $this->assertEqual(filter_get_roles_by_format(FilterFormat::load(filter_fallback_format())), user_role_names(), 'All roles have access to the fallback format.');
     $this->assertTrue(in_array(filter_fallback_format(), array_keys(filter_get_formats_by_role($rid))), 'The fallback format appears in the list of allowed formats for any role.');
 }
Exemple #25
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     /** @var \Drupal\user\UserInterface $account */
     $account = $this->entity;
     $user = $this->currentUser();
     $config = \Drupal::config('user.settings');
     $form['#cache']['tags'] = $config->getCacheTags();
     $language_interface = \Drupal::languageManager()->getCurrentLanguage();
     $register = $account->isAnonymous();
     $admin = $user->hasPermission('administer users');
     // Account information.
     $form['account'] = array('#type' => 'container', '#weight' => -10);
     // The mail field is NOT required if account originally had no mail set
     // and the user performing the edit has 'administer users' permission.
     // This allows users without email address to be edited and deleted.
     // Also see \Drupal\user\Plugin\Validation\Constraint\UserMailRequired.
     $form['account']['mail'] = array('#type' => 'email', '#title' => $this->t('Email address'), '#description' => $this->t('A valid email address. All emails from the system will be sent to this address. The email address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by email.'), '#required' => !(!$account->getEmail() && $user->hasPermission('administer users')), '#default_value' => !$register ? $account->getEmail() : '');
     // Only show name field on registration form or user can change own username.
     $form['account']['name'] = array('#type' => 'textfield', '#title' => $this->t('Username'), '#maxlength' => USERNAME_MAX_LENGTH, '#description' => $this->t("Several special characters are allowed, including space, period (.), hyphen (-), apostrophe ('), underscore (_), and the @ sign."), '#required' => TRUE, '#attributes' => array('class' => array('username'), 'autocorrect' => 'off', 'autocapitalize' => 'off', 'spellcheck' => 'false'), '#default_value' => !$register ? $account->getUsername() : '', '#access' => $register || $user->id() == $account->id() && $user->hasPermission('change own username') || $admin);
     // Display password field only for existing users or when user is allowed to
     // assign a password during registration.
     if (!$register) {
         $form['account']['pass'] = array('#type' => 'password_confirm', '#size' => 25, '#description' => $this->t('To change the current user password, enter the new password in both fields.'));
         // To skip the current password field, the user must have logged in via a
         // one-time link and have the token in the URL. Store this in $form_state
         // so it persists even on subsequent Ajax requests.
         if (!$form_state->get('user_pass_reset')) {
             $user_pass_reset = $pass_reset = isset($_SESSION['pass_reset_' . $account->id()]) && \Drupal::request()->query->get('pass-reset-token') == $_SESSION['pass_reset_' . $account->id()];
             $form_state->set('user_pass_reset', $user_pass_reset);
         }
         // The user must enter their current password to change to a new one.
         if ($user->id() == $account->id()) {
             $form['account']['current_pass'] = array('#type' => 'password', '#title' => $this->t('Current password'), '#size' => 25, '#access' => !$form_state->get('user_pass_reset'), '#weight' => -5, '#attributes' => array('autocomplete' => 'off'));
             $form_state->set('user', $account);
             // The user may only change their own password without their current
             // password if they logged in via a one-time login link.
             if (!$form_state->get('user_pass_reset')) {
                 $form['account']['current_pass']['#description'] = $this->t('Required if you want to change the %mail or %pass below. <a href=":request_new_url" title="Send password reset instructions via email.">Reset your password</a>.', array('%mail' => $form['account']['mail']['#title'], '%pass' => $this->t('Password'), ':request_new_url' => $this->url('user.pass')));
             }
         }
     } elseif (!$config->get('verify_mail') || $admin) {
         $form['account']['pass'] = array('#type' => 'password_confirm', '#size' => 25, '#description' => $this->t('Provide a password for the new account in both fields.'), '#required' => TRUE);
     }
     // When not building the user registration form, prevent web browsers from
     // autofilling/prefilling the email, username, and password fields.
     if ($this->getOperation() != 'register') {
         foreach (array('mail', 'name', 'pass') as $key) {
             if (isset($form['account'][$key])) {
                 $form['account'][$key]['#attributes']['autocomplete'] = 'off';
             }
         }
     }
     if ($admin || !$register) {
         $status = $account->get('status')->value;
     } else {
         $status = $config->get('register') == USER_REGISTER_VISITORS ? 1 : 0;
     }
     $form['account']['status'] = array('#type' => 'radios', '#title' => $this->t('Status'), '#default_value' => $status, '#options' => array($this->t('Blocked'), $this->t('Active')), '#access' => $admin);
     $roles = array_map(array('\\Drupal\\Component\\Utility\\Html', 'escape'), user_role_names(TRUE));
     $form['account']['roles'] = array('#type' => 'checkboxes', '#title' => $this->t('Roles'), '#default_value' => !$register ? $account->getRoles() : array(), '#options' => $roles, '#access' => $roles && $user->hasPermission('administer permissions'));
     // Special handling for the inevitable "Authenticated user" role.
     $form['account']['roles'][RoleInterface::AUTHENTICATED_ID] = array('#default_value' => TRUE, '#disabled' => TRUE);
     $form['account']['notify'] = array('#type' => 'checkbox', '#title' => $this->t('Notify user of new account'), '#access' => $register && $admin);
     $user_preferred_langcode = $register ? $language_interface->getId() : $account->getPreferredLangcode();
     $user_preferred_admin_langcode = $register ? $language_interface->getId() : $account->getPreferredAdminLangcode(FALSE);
     // Is the user preferred language added?
     $user_language_added = FALSE;
     if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) {
         $negotiator = $this->languageManager->getNegotiator();
         $user_language_added = $negotiator && $negotiator->isNegotiationMethodEnabled(LanguageNegotiationUser::METHOD_ID, LanguageInterface::TYPE_INTERFACE);
     }
     $form['language'] = array('#type' => $this->languageManager->isMultilingual() ? 'details' : 'container', '#title' => $this->t('Language settings'), '#open' => TRUE, '#access' => !$register || $user->hasPermission('administer users'));
     $form['language']['preferred_langcode'] = array('#type' => 'language_select', '#title' => $this->t('Site language'), '#languages' => LanguageInterface::STATE_CONFIGURABLE, '#default_value' => $user_preferred_langcode, '#description' => $user_language_added ? $this->t("This account's preferred language for emails and site presentation.") : $this->t("This account's preferred language for emails."), '#pre_render' => ['user_langcode' => [$this, 'alterPreferredLangcodeDescription']]);
     // Only show the account setting for Administration pages language to users
     // if one of the detection and selection methods uses it.
     $show_admin_language = FALSE;
     if ($account->hasPermission('access administration pages') && $this->languageManager instanceof ConfigurableLanguageManagerInterface) {
         $negotiator = $this->languageManager->getNegotiator();
         $show_admin_language = $negotiator && $negotiator->isNegotiationMethodEnabled(LanguageNegotiationUserAdmin::METHOD_ID);
     }
     $form['language']['preferred_admin_langcode'] = array('#type' => 'language_select', '#title' => $this->t('Administration pages language'), '#languages' => LanguageInterface::STATE_CONFIGURABLE, '#default_value' => $user_preferred_admin_langcode, '#access' => $show_admin_language, '#empty_option' => $this->t('- No preference -'), '#empty_value' => '');
     // User entities contain both a langcode property (for identifying the
     // language of the entity data) and a preferred_langcode property (see
     // above). Rather than provide a UI forcing the user to choose both
     // separately, assume that the user profile data is in the user's preferred
     // language. This entity builder provides that synchronization. For
     // use-cases where this synchronization is not desired, a module can alter
     // or remove this item.
     $form['#entity_builders']['sync_user_langcode'] = [$this, 'syncUserLangcode'];
     return parent::form($form, $form_state, $account);
 }
  /**
   * @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;
  }
Exemple #27
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     /** @var \Drupal\user\UserInterface $account */
     $account = $this->entity;
     $user = $this->currentUser();
     $config = \Drupal::config('user.settings');
     $language_interface = \Drupal::languageManager()->getCurrentLanguage();
     $register = $account->isAnonymous();
     $admin = $user->hasPermission('administer users');
     // Account information.
     $form['account'] = array('#type' => 'container', '#weight' => -10);
     // The mail field is NOT required if account originally had no mail set
     // and the user performing the edit has 'administer users' permission.
     // This allows users without email address to be edited and deleted.
     $form['account']['mail'] = array('#type' => 'email', '#title' => $this->t('Email address'), '#description' => $this->t('A valid email address. All emails from the system will be sent to this address. The email address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by email.'), '#required' => !(!$account->getEmail() && $user->hasPermission('administer users')), '#default_value' => !$register ? $account->getEmail() : '');
     // Only show name field on registration form or user can change own username.
     $form['account']['name'] = array('#type' => 'textfield', '#title' => $this->t('Username'), '#maxlength' => USERNAME_MAX_LENGTH, '#description' => $this->t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.'), '#required' => TRUE, '#attributes' => array('class' => array('username'), 'autocorrect' => 'off', 'autocapitalize' => 'off', 'spellcheck' => 'false'), '#default_value' => !$register ? $account->getUsername() : '', '#access' => $register || $user->id() == $account->id() && $user->hasPermission('change own username') || $admin);
     // Display password field only for existing users or when user is allowed to
     // assign a password during registration.
     if (!$register) {
         $form['account']['pass'] = array('#type' => 'password_confirm', '#size' => 25, '#description' => $this->t('To change the current user password, enter the new password in both fields.'));
         // To skip the current password field, the user must have logged in via a
         // one-time link and have the token in the URL.
         $pass_reset = isset($_SESSION['pass_reset_' . $account->id()]) && \Drupal::request()->query->get('pass-reset-token') == $_SESSION['pass_reset_' . $account->id()];
         $protected_values = array();
         $current_pass_description = '';
         // The user may only change their own password without their current
         // password if they logged in via a one-time login link.
         if (!$pass_reset) {
             $protected_values['mail'] = $form['account']['mail']['#title'];
             $protected_values['pass'] = $this->t('Password');
             $request_new = l($this->t('Request new password'), 'user/password', array('attributes' => array('title' => $this->t('Request new password via email.'))));
             $current_pass_description = $this->t('Required if you want to change the %mail or %pass below. !request_new.', array('%mail' => $protected_values['mail'], '%pass' => $protected_values['pass'], '!request_new' => $request_new));
         }
         // The user must enter their current password to change to a new one.
         if ($user->id() == $account->id()) {
             $form['account']['current_pass_required_values'] = array('#type' => 'value', '#value' => $protected_values);
             $form['account']['current_pass'] = array('#type' => 'password', '#title' => $this->t('Current password'), '#size' => 25, '#access' => !empty($protected_values), '#description' => $current_pass_description, '#weight' => -5, '#attributes' => array('autocomplete' => 'off'));
             $form_state['user'] = $account;
             $form['#validate'][] = 'user_validate_current_pass';
         }
     } elseif (!$config->get('verify_mail') || $admin) {
         $form['account']['pass'] = array('#type' => 'password_confirm', '#size' => 25, '#description' => $this->t('Provide a password for the new account in both fields.'), '#required' => TRUE);
     }
     // When not building the user registration form, prevent web browsers from
     // autofilling/prefilling the email, username, and password fields.
     if ($this->getOperation() != 'register') {
         foreach (array('mail', 'name', 'pass') as $key) {
             if (isset($form['account'][$key])) {
                 $form['account'][$key]['#attributes']['autocomplete'] = 'off';
             }
         }
     }
     if ($admin) {
         $status = $account->isActive();
     } else {
         $status = $register ? $config->get('register') == USER_REGISTER_VISITORS : $account->isActive();
     }
     $form['account']['status'] = array('#type' => 'radios', '#title' => $this->t('Status'), '#default_value' => $status, '#options' => array($this->t('Blocked'), $this->t('Active')), '#access' => $admin);
     $roles = array_map(array('\\Drupal\\Component\\Utility\\String', 'checkPlain'), user_role_names(TRUE));
     // The disabled checkbox subelement for the 'authenticated user' role
     // must be generated separately and added to the checkboxes element,
     // because of a limitation in Form API not supporting a single disabled
     // checkbox within a set of checkboxes.
     // @todo This should be solved more elegantly. See issue #119038.
     $checkbox_authenticated = array('#type' => 'checkbox', '#title' => $roles[DRUPAL_AUTHENTICATED_RID], '#default_value' => TRUE, '#disabled' => TRUE);
     unset($roles[DRUPAL_AUTHENTICATED_RID]);
     $form['account']['roles'] = array('#type' => 'checkboxes', '#title' => $this->t('Roles'), '#default_value' => !$register ? $account->getRoles() : array(), '#options' => $roles, '#access' => $roles && $user->hasPermission('administer permissions'), DRUPAL_AUTHENTICATED_RID => $checkbox_authenticated);
     $form['account']['notify'] = array('#type' => 'checkbox', '#title' => $this->t('Notify user of new account'), '#access' => $register && $admin);
     // Signature.
     $form['signature_settings'] = array('#type' => 'details', '#title' => $this->t('Signature settings'), '#open' => TRUE, '#weight' => 1, '#access' => !$register && $config->get('signatures'));
     // While the details group will simply not be rendered if empty, the actual
     // signature element cannot use #access, since #type 'text_format' is not
     // available when Filter module is not installed. If the user account has an
     // existing signature value and format, then the existing field values will
     // just be re-saved to the database in case of an entity update.
     if ($this->moduleHandler->moduleExists('filter')) {
         $form['signature_settings']['signature'] = array('#type' => 'text_format', '#title' => $this->t('Signature'), '#default_value' => $account->getSignature(), '#description' => $this->t('Your signature will be publicly displayed at the end of your comments.'), '#format' => $account->getSignatureFormat());
     }
     $user_preferred_langcode = $register ? $language_interface->id : $account->getPreferredLangcode();
     $user_preferred_admin_langcode = $register ? $language_interface->id : $account->getPreferredAdminLangcode();
     // Is the user preferred language added?
     $user_language_added = FALSE;
     if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) {
         $negotiator = $this->languageManager->getNegotiator();
         $user_language_added = $negotiator && $negotiator->isNegotiationMethodEnabled(LanguageNegotiationUser::METHOD_ID, LanguageInterface::TYPE_INTERFACE);
     }
     $form['language'] = array('#type' => $this->languageManager->isMultilingual() ? 'details' : 'container', '#title' => $this->t('Language settings'), '#open' => TRUE, '#access' => !$register || $user->hasPermission('administer users'));
     $form['language']['preferred_langcode'] = array('#type' => 'language_select', '#title' => $this->t('Site language'), '#languages' => LanguageInterface::STATE_CONFIGURABLE, '#default_value' => $user_preferred_langcode, '#description' => $user_language_added ? $this->t("This account's preferred language for emails and site presentation.") : $this->t("This account's preferred language for emails."));
     // Only show the account setting for Administration pages language to users
     // if one of the detection and selection methods uses it.
     $show_admin_language = FALSE;
     if ($account->hasPermission('access administration pages') && $this->languageManager instanceof ConfigurableLanguageManagerInterface) {
         $negotiator = $this->languageManager->getNegotiator();
         $show_admin_language = $negotiator && $negotiator->isNegotiationMethodEnabled(LanguageNegotiationUserAdmin::METHOD_ID);
     }
     $form['language']['preferred_admin_langcode'] = array('#type' => 'language_select', '#title' => $this->t('Administration pages language'), '#languages' => LanguageInterface::STATE_CONFIGURABLE, '#default_value' => $user_preferred_admin_langcode, '#access' => $show_admin_language);
     // User entities contain both a langcode property (for identifying the
     // language of the entity data) and a preferred_langcode property (see
     // above). Rather than provide a UI forcing the user to choose both
     // separately, assume that the user profile data is in the user's preferred
     // language. This element provides that synchronization. For use-cases where
     // this synchronization is not desired, a module can alter or remove this
     // element.
     $form['language']['langcode'] = array('#type' => 'value', '#value_callback' => '_user_language_selector_langcode_value', '#weight' => 100);
     return parent::form($form, $form_state, $account);
 }
Exemple #28
0
 public function getValueOptions()
 {
     $this->valueOptions = user_role_names(TRUE);
     unset($this->valueOptions[RoleInterface::AUTHENTICATED_ID]);
     return $this->valueOptions;
 }
Exemple #29
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildForm($form, $form_state);
     $config = $this->config('user.settings');
     $mail_config = $this->config('user.mail');
     $site_config = $this->config('system.site');
     $form['#attached']['library'][] = 'user/drupal.user.admin';
     // Settings for anonymous users.
     $form['anonymous_settings'] = array('#type' => 'details', '#title' => $this->t('Anonymous users'), '#open' => TRUE);
     $form['anonymous_settings']['anonymous'] = array('#type' => 'textfield', '#title' => $this->t('Name'), '#default_value' => $config->get('anonymous'), '#description' => $this->t('The name used to indicate anonymous users.'), '#required' => TRUE);
     // Administrative role option.
     $form['admin_role'] = array('#type' => 'details', '#title' => $this->t('Administrator role'), '#open' => TRUE);
     // Do not allow users to set the anonymous or authenticated user roles as the
     // administrator role.
     $roles = user_role_names(TRUE);
     unset($roles[RoleInterface::AUTHENTICATED_ID]);
     $admin_roles = $this->roleStorage->getQuery()->condition('is_admin', TRUE)->execute();
     $default_value = reset($admin_roles);
     $form['admin_role']['user_admin_role'] = array('#type' => 'select', '#title' => $this->t('Administrator role'), '#empty_value' => '', '#default_value' => $default_value, '#options' => $roles, '#description' => $this->t('This role will be automatically assigned new permissions whenever a module is enabled. Changing this setting will not affect existing permissions.'), '#access' => count($admin_roles) <= 1);
     // @todo Remove this check once language settings are generalized.
     if ($this->moduleHandler->moduleExists('content_translation')) {
         $form['language'] = array('#type' => 'details', '#title' => $this->t('Language settings'), '#open' => TRUE, '#tree' => TRUE);
         $form_state->set(['content_translation', 'key'], 'language');
         $form['language'] += content_translation_enable_widget('user', 'user', $form, $form_state);
     }
     // User registration settings.
     $form['registration_cancellation'] = array('#type' => 'details', '#title' => $this->t('Registration and cancellation'), '#open' => TRUE);
     $form['registration_cancellation']['user_register'] = array('#type' => 'radios', '#title' => $this->t('Who can register accounts?'), '#default_value' => $config->get('register'), '#options' => array(USER_REGISTER_ADMINISTRATORS_ONLY => $this->t('Administrators only'), USER_REGISTER_VISITORS => $this->t('Visitors'), USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL => $this->t('Visitors, but administrator approval is required')));
     $form['registration_cancellation']['user_email_verification'] = array('#type' => 'checkbox', '#title' => $this->t('Require email verification when a visitor creates an account'), '#default_value' => $config->get('verify_mail'), '#description' => $this->t('New users will be required to validate their email address prior to logging into the site, and will be assigned a system-generated password. With this setting disabled, users will be logged in immediately upon registering, and may select their own passwords during registration.'));
     $form['registration_cancellation']['user_password_strength'] = array('#type' => 'checkbox', '#title' => $this->t('Enable password strength indicator'), '#default_value' => $config->get('password_strength'));
     $form['registration_cancellation']['user_cancel_method'] = array('#type' => 'radios', '#title' => $this->t('When cancelling a user account'), '#default_value' => $config->get('cancel_method'), '#description' => $this->t('Users with the %select-cancel-method or %administer-users <a href="@permissions-url">permissions</a> can override this default method.', array('%select-cancel-method' => $this->t('Select method for cancelling account'), '%administer-users' => $this->t('Administer users'), '@permissions-url' => $this->url('user.admin_permissions'))));
     $form['registration_cancellation']['user_cancel_method'] += user_cancel_methods();
     foreach (Element::children($form['registration_cancellation']['user_cancel_method']) as $key) {
         // All account cancellation methods that specify #access cannot be
         // configured as default method.
         // @see hook_user_cancel_methods_alter()
         if (isset($form['registration_cancellation']['user_cancel_method'][$key]['#access'])) {
             $form['registration_cancellation']['user_cancel_method'][$key]['#access'] = FALSE;
         }
     }
     // Default notifications address.
     $form['mail_notification_address'] = array('#type' => 'email', '#title' => $this->t('Notification email address'), '#default_value' => $site_config->get('mail_notification'), '#description' => $this->t("The email address to be used as the 'from' address for all account notifications listed below. If <em>'Visitors, but administrator approval is required'</em> is selected above, a notification email will also be sent to this address for any new registrations. Leave empty to use the default system email address <em>(%site-email).</em>", array('%site-email' => $site_config->get('mail'))), '#maxlength' => 180);
     $form['email'] = array('#type' => 'vertical_tabs', '#title' => $this->t('Emails'));
     // These email tokens are shared for all settings, so just define
     // the list once to help ensure they stay in sync.
     $email_token_help = $this->t('Available variables are: [site:name], [site:url], [user:name], [user:mail], [site:login-url], [site:url-brief], [user:edit-url], [user:one-time-login-url], [user:cancel-url].');
     $form['email_admin_created'] = array('#type' => 'details', '#title' => $this->t('Welcome (new user created by administrator)'), '#open' => $config->get('register') == USER_REGISTER_ADMINISTRATORS_ONLY, '#description' => $this->t('Edit the welcome email messages sent to new member accounts created by an administrator.') . ' ' . $email_token_help, '#group' => 'email');
     $form['email_admin_created']['user_mail_register_admin_created_subject'] = array('#type' => 'textfield', '#title' => $this->t('Subject'), '#default_value' => $mail_config->get('register_admin_created.subject'), '#maxlength' => 180);
     $form['email_admin_created']['user_mail_register_admin_created_body'] = array('#type' => 'textarea', '#title' => $this->t('Body'), '#default_value' => $mail_config->get('register_admin_created.body'), '#rows' => 15);
     $form['email_pending_approval'] = array('#type' => 'details', '#title' => $this->t('Welcome (awaiting approval)'), '#open' => $config->get('register') == USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL, '#description' => $this->t('Edit the welcome email messages sent to new members upon registering, when administrative approval is required.') . ' ' . $email_token_help, '#group' => 'email');
     $form['email_pending_approval']['user_mail_register_pending_approval_subject'] = array('#type' => 'textfield', '#title' => $this->t('Subject'), '#default_value' => $mail_config->get('register_pending_approval.subject'), '#maxlength' => 180);
     $form['email_pending_approval']['user_mail_register_pending_approval_body'] = array('#type' => 'textarea', '#title' => $this->t('Body'), '#default_value' => $mail_config->get('register_pending_approval.body'), '#rows' => 8);
     $form['email_pending_approval_admin'] = array('#type' => 'details', '#title' => $this->t('Admin (user awaiting approval)'), '#open' => $config->get('register') == USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL, '#description' => $this->t('Edit the email notifying the site administrator that there are new members awaiting administrative approval.') . ' ' . $email_token_help, '#group' => 'email');
     $form['email_pending_approval_admin']['register_pending_approval_admin_subject'] = array('#type' => 'textfield', '#title' => $this->t('Subject'), '#default_value' => $mail_config->get('register_pending_approval_admin.subject'), '#maxlength' => 180);
     $form['email_pending_approval_admin']['register_pending_approval_admin_body'] = array('#type' => 'textarea', '#title' => $this->t('Body'), '#default_value' => $mail_config->get('register_pending_approval_admin.body'), '#rows' => 8);
     $form['email_no_approval_required'] = array('#type' => 'details', '#title' => $this->t('Welcome (no approval required)'), '#open' => $config->get('register') == USER_REGISTER_VISITORS, '#description' => $this->t('Edit the welcome email messages sent to new members upon registering, when no administrator approval is required.') . ' ' . $email_token_help, '#group' => 'email');
     $form['email_no_approval_required']['user_mail_register_no_approval_required_subject'] = array('#type' => 'textfield', '#title' => $this->t('Subject'), '#default_value' => $mail_config->get('register_no_approval_required.subject'), '#maxlength' => 180);
     $form['email_no_approval_required']['user_mail_register_no_approval_required_body'] = array('#type' => 'textarea', '#title' => $this->t('Body'), '#default_value' => $mail_config->get('register_no_approval_required.body'), '#rows' => 15);
     $form['email_password_reset'] = array('#type' => 'details', '#title' => $this->t('Password recovery'), '#description' => $this->t('Edit the email messages sent to users who request a new password.') . ' ' . $email_token_help, '#group' => 'email', '#weight' => 10);
     $form['email_password_reset']['user_mail_password_reset_subject'] = array('#type' => 'textfield', '#title' => $this->t('Subject'), '#default_value' => $mail_config->get('password_reset.subject'), '#maxlength' => 180);
     $form['email_password_reset']['user_mail_password_reset_body'] = array('#type' => 'textarea', '#title' => $this->t('Body'), '#default_value' => $mail_config->get('password_reset.body'), '#rows' => 12);
     $form['email_activated'] = array('#type' => 'details', '#title' => $this->t('Account activation'), '#description' => $this->t('Enable and edit email messages sent to users upon account activation (when an administrator activates an account of a user who has already registered, on a site where administrative approval is required).') . ' ' . $email_token_help, '#group' => 'email');
     $form['email_activated']['user_mail_status_activated_notify'] = array('#type' => 'checkbox', '#title' => $this->t('Notify user when account is activated'), '#default_value' => $config->get('notify.status_activated'));
     $form['email_activated']['settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="user_mail_status_activated_notify"]' => array('checked' => FALSE))));
     $form['email_activated']['settings']['user_mail_status_activated_subject'] = array('#type' => 'textfield', '#title' => $this->t('Subject'), '#default_value' => $mail_config->get('status_activated.subject'), '#maxlength' => 180);
     $form['email_activated']['settings']['user_mail_status_activated_body'] = array('#type' => 'textarea', '#title' => $this->t('Body'), '#default_value' => $mail_config->get('status_activated.body'), '#rows' => 15);
     $form['email_blocked'] = array('#type' => 'details', '#title' => $this->t('Account blocked'), '#description' => $this->t('Enable and edit email messages sent to users when their accounts are blocked.') . ' ' . $email_token_help, '#group' => 'email');
     $form['email_blocked']['user_mail_status_blocked_notify'] = array('#type' => 'checkbox', '#title' => $this->t('Notify user when account is blocked'), '#default_value' => $config->get('notify.status_blocked'));
     $form['email_blocked']['settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="user_mail_status_blocked_notify"]' => array('checked' => FALSE))));
     $form['email_blocked']['settings']['user_mail_status_blocked_subject'] = array('#type' => 'textfield', '#title' => $this->t('Subject'), '#default_value' => $mail_config->get('status_blocked.subject'), '#maxlength' => 180);
     $form['email_blocked']['settings']['user_mail_status_blocked_body'] = array('#type' => 'textarea', '#title' => $this->t('Body'), '#default_value' => $mail_config->get('status_blocked.body'), '#rows' => 3);
     $form['email_cancel_confirm'] = array('#type' => 'details', '#title' => $this->t('Account cancellation confirmation'), '#description' => $this->t('Edit the email messages sent to users when they attempt to cancel their accounts.') . ' ' . $email_token_help, '#group' => 'email');
     $form['email_cancel_confirm']['user_mail_cancel_confirm_subject'] = array('#type' => 'textfield', '#title' => $this->t('Subject'), '#default_value' => $mail_config->get('cancel_confirm.subject'), '#maxlength' => 180);
     $form['email_cancel_confirm']['user_mail_cancel_confirm_body'] = array('#type' => 'textarea', '#title' => $this->t('Body'), '#default_value' => $mail_config->get('cancel_confirm.body'), '#rows' => 3);
     $form['email_canceled'] = array('#type' => 'details', '#title' => $this->t('Account canceled'), '#description' => $this->t('Enable and edit email messages sent to users when their accounts are canceled.') . ' ' . $email_token_help, '#group' => 'email');
     $form['email_canceled']['user_mail_status_canceled_notify'] = array('#type' => 'checkbox', '#title' => $this->t('Notify user when account is canceled'), '#default_value' => $config->get('notify.status_canceled'));
     $form['email_canceled']['settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="user_mail_status_canceled_notify"]' => array('checked' => FALSE))));
     $form['email_canceled']['settings']['user_mail_status_canceled_subject'] = array('#type' => 'textfield', '#title' => $this->t('Subject'), '#default_value' => $mail_config->get('status_canceled.subject'), '#maxlength' => 180);
     $form['email_canceled']['settings']['user_mail_status_canceled_body'] = array('#type' => 'textarea', '#title' => $this->t('Body'), '#default_value' => $mail_config->get('status_canceled.body'), '#rows' => 3);
     return $form;
 }
Exemple #30
0
 /**
  * Tests the user bulk form.
  */
 public function testBulkForm()
 {
     // Log in as a user without 'administer users'.
     $this->drupalLogin($this->drupalCreateUser(array('administer permissions')));
     $user_storage = $this->container->get('entity.manager')->getStorage('user');
     // Create an user which actually can change users.
     $this->drupalLogin($this->drupalCreateUser(array('administer users')));
     $this->drupalGet('test-user-bulk-form');
     $result = $this->cssSelect('#edit-action option');
     $this->assertTrue(count($result) > 0);
     // Test submitting the page with no selection.
     $edit = array('action' => 'user_block_user_action');
     $this->drupalPostForm('test-user-bulk-form', $edit, t('Apply'));
     $this->assertText(t('No users selected.'));
     // Assign a role to a user.
     $account = $user_storage->load($this->users[0]->id());
     $roles = user_role_names(TRUE);
     unset($roles[RoleInterface::AUTHENTICATED_ID]);
     $role = key($roles);
     $this->assertFalse($account->hasRole($role), 'The user currently does not have a custom role.');
     $edit = array('user_bulk_form[1]' => TRUE, 'action' => 'user_add_role_action.' . $role);
     $this->drupalPostForm(NULL, $edit, t('Apply'));
     // Re-load the user and check their roles.
     $user_storage->resetCache(array($account->id()));
     $account = $user_storage->load($account->id());
     $this->assertTrue($account->hasRole($role), 'The user now has the custom role.');
     $edit = array('user_bulk_form[1]' => TRUE, 'action' => 'user_remove_role_action.' . $role);
     $this->drupalPostForm(NULL, $edit, t('Apply'));
     // Re-load the user and check their roles.
     $user_storage->resetCache(array($account->id()));
     $account = $user_storage->load($account->id());
     $this->assertFalse($account->hasRole($role), 'The user no longer has the custom role.');
     // Block a user using the bulk form.
     $this->assertTrue($account->isActive(), 'The user is not blocked.');
     $this->assertRaw($account->label(), 'The user is found in the table.');
     $edit = array('user_bulk_form[1]' => TRUE, 'action' => 'user_block_user_action');
     $this->drupalPostForm(NULL, $edit, t('Apply'));
     // Re-load the user and check their status.
     $user_storage->resetCache(array($account->id()));
     $account = $user_storage->load($account->id());
     $this->assertTrue($account->isBlocked(), 'The user is blocked.');
     $this->assertNoRaw($account->label(), 'The user is not found in the table.');
     // Remove the user status filter from the view.
     $view = Views::getView('test_user_bulk_form');
     $view->removeHandler('default', 'filter', 'status');
     $view->storage->save();
     // Ensure the anonymous user is found.
     $this->drupalGet('test-user-bulk-form');
     $this->assertText($this->config('user.settings')->get('anonymous'));
     // Attempt to block the anonymous user.
     $edit = array('user_bulk_form[0]' => TRUE, 'action' => 'user_block_user_action');
     $this->drupalPostForm(NULL, $edit, t('Apply'));
     $anonymous_account = $user_storage->load(0);
     $this->assertTrue($anonymous_account->isBlocked(), 'Ensure the anonymous user got blocked.');
     // Test the list of available actions with a value that contains a dot.
     $this->drupalLogin($this->drupalCreateUser(array('administer permissions', 'administer views', 'administer users')));
     $action_id = 'user_add_role_action.' . $role;
     $edit = ['options[include_exclude]' => 'exclude', "options[selected_actions][{$action_id}]" => $action_id];
     $this->drupalPostForm('admin/structure/views/nojs/handler/test_user_bulk_form/default/field/user_bulk_form', $edit, t('Apply'));
     $this->drupalPostForm(NULL, [], t('Save'));
     $this->drupalGet('test-user-bulk-form');
     $this->assertNoOption('edit-action', $action_id);
     $edit['options[include_exclude]'] = 'include';
     $this->drupalPostForm('admin/structure/views/nojs/handler/test_user_bulk_form/default/field/user_bulk_form', $edit, t('Apply'));
     $this->drupalPostForm(NULL, [], t('Save'));
     $this->drupalGet('test-user-bulk-form');
     $this->assertOption('edit-action', $action_id);
 }