Exemple #1
0
 public function getValueOptions()
 {
     if (!isset($this->valueOptions)) {
         $permissions = $this->permissionHandler->getPermissions();
         foreach ($permissions as $perm => $perm_item) {
             $provider = $perm_item['provider'];
             $display_name = $this->moduleHandler->getName($provider);
             $this->valueOptions[$display_name][$perm] = SafeMarkup::checkPlain(strip_tags($perm_item['title']));
         }
     } else {
         return $this->valueOptions;
     }
 }
 public function getValueOptions()
 {
     if (!isset($this->valueOptions)) {
         $module_info = system_get_info('module');
         $permissions = $this->permissionHandler->getPermissions();
         foreach ($permissions as $perm => $perm_item) {
             $provider = $perm_item['provider'];
             $display_name = $module_info[$provider]['name'];
             $this->valueOptions[$display_name][$perm] = String::checkPlain(strip_tags($perm_item['title']));
         }
     } else {
         return $this->valueOptions;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $role_names = array();
     $role_permissions = array();
     $admin_roles = array();
     foreach ($this->getRoles() as $role_name => $role) {
         // Retrieve role names for columns.
         $role_names[$role_name] = String::checkPlain($role->label());
         // Fetch permissions for the roles.
         $role_permissions[$role_name] = $role->getPermissions();
         $admin_roles[$role_name] = $role->isAdmin();
     }
     // Store $role_names for use when saving the data.
     $form['role_names'] = array('#type' => 'value', '#value' => $role_names);
     // Render role/permission overview:
     $options = array();
     $module_info = system_rebuild_module_data();
     $hide_descriptions = system_admin_compact_mode();
     $form['system_compact_link'] = array('#id' => FALSE, '#type' => 'system_compact_link');
     $form['permissions'] = array('#type' => 'table', '#header' => array($this->t('Permission')), '#id' => 'permissions', '#attributes' => ['class' => ['permissions']], '#sticky' => TRUE);
     foreach ($role_names as $name) {
         $form['permissions']['#header'][] = array('data' => $name, 'class' => array('checkbox'));
     }
     $permissions = $this->permissionHandler->getPermissions();
     $permissions_by_provider = array();
     foreach ($permissions as $permission_name => $permission) {
         $permissions_by_provider[$permission['provider']][$permission_name] = $permission;
     }
     foreach ($permissions_by_provider as $provider => $permissions) {
         // Module name.
         $form['permissions'][$provider] = array(array('#wrapper_attributes' => array('colspan' => count($role_names) + 1, 'class' => array('module'), 'id' => 'module-' . $provider), '#markup' => $module_info[$provider]->info['name']));
         foreach ($permissions as $perm => $perm_item) {
             // Fill in default values for the permission.
             $perm_item += array('description' => '', 'restrict access' => FALSE, 'warning' => !empty($perm_item['restrict access']) ? $this->t('Warning: Give to trusted roles only; this permission has security implications.') : '');
             $options[$perm] = $perm_item['title'];
             $form['permissions'][$perm]['description'] = array('#type' => 'inline_template', '#template' => '<div class="permission"><span class="title">{{ title }}</span>{% if description or warning %}<div class="description">{% if warning %}<em class="permission-warning">{{ warning }}</em> {% endif %}{{ description }}</div>{% endif %}</div>', '#context' => array('title' => $perm_item['title']));
             // Show the permission description.
             if (!$hide_descriptions) {
                 $form['permissions'][$perm]['description']['#context']['description'] = $perm_item['description'];
                 $form['permissions'][$perm]['description']['#context']['warning'] = $perm_item['warning'];
             }
             $options[$perm] = '';
             foreach ($role_names as $rid => $name) {
                 $form['permissions'][$perm][$rid] = array('#title' => $name . ': ' . $perm_item['title'], '#title_display' => 'invisible', '#wrapper_attributes' => array('class' => array('checkbox')), '#type' => 'checkbox', '#default_value' => in_array($perm, $role_permissions[$rid]) ? 1 : 0, '#attributes' => array('class' => array('rid-' . $rid)), '#parents' => array($rid, $perm));
                 // Show a column of disabled but checked checkboxes.
                 if ($admin_roles[$rid]) {
                     $form['permissions'][$perm][$rid]['#disabled'] = TRUE;
                     $form['permissions'][$perm][$rid]['#default_value'] = TRUE;
                 }
             }
         }
     }
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save permissions'));
     $form['#attached']['library'][] = 'user/drupal.user.permissions';
     return $form;
 }
 /**
  * Checks operation access on the field collection item's host's revisions.
  *
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  *
  * TODO: Document params
  *
  * @return string
  *   A \Drupal\Core\Access\AccessInterface constant value.
  */
 public function access(Route $route, AccountInterface $account, $field_collection_item_revision = NULL, FieldCollectionItem $field_collection_item = NULL)
 {
     if ($field_collection_item_revision) {
         $field_collection_item = field_collection_item_revision_load($field_collection_item_revision);
     }
     $permissions = $this->permissionHandler->getPermissions();
     $operation = $route->getRequirement('_access_field_collection_item_host_revisions');
     $host = $field_collection_item->getHost();
     if ($host->getEntityType()->id() == 'node') {
         return AccessResult::allowedIf($account->hasPermission($operation . ' ' . $host->getType() . ' revisions'));
     } else {
         if ($host->getEntityType()->id() == 'field_collection_item') {
             return $this->access($route, $account, $host->revision_id, $host);
         } else {
             return AccessResult::allowedIf($field_collection_item && $field_collection_item->getHost()->access($operation, $account))->cachePerPermissions();
         }
     }
 }
Exemple #5
0
 /**
  * Returns module provided permissions.
  *
  * @return array
  *   Array of permission names.
  */
 public function getPermissions()
 {
     $permissions = [];
     foreach ($this->permissionHandler->getPermissions() as $name => $permission) {
         if ($permission['provider'] === 'masquerade') {
             // Filter only module's permissions.
             $permissions[] = $name;
         }
     }
     return $permissions;
 }
 /**
  * {@inheritdoc}
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     // Build the list of all permissions grouped by module.
     $permissions = [];
     foreach ($this->permissionHandler->getPermissions() as $permission => $permission_item) {
         $provider = $permission_item['provider'];
         $display_name = $this->moduleHandler->getName($provider);
         $permissions[$display_name][$permission] = Html::escape($permission_item['title']);
     }
     $form['admin_permission'] = ['#type' => 'select', '#title' => $this->t('Admin permission'), '#description' => $this->t('Allows the current user to access the view even if the argument is a different user.'), '#options' => $permissions, '#empty_value' => '', '#default_value' => $this->options['admin_permission']];
 }
Exemple #7
0
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     // Get list of permissions
     $perms = [];
     $permissions = $this->permissionHandler->getPermissions();
     foreach ($permissions as $perm => $perm_item) {
         $provider = $perm_item['provider'];
         $display_name = $this->moduleHandler->getName($provider);
         $perms[$display_name][$perm] = strip_tags($perm_item['title']);
     }
     $form['perm'] = array('#type' => 'select', '#options' => $perms, '#title' => $this->t('Permission'), '#default_value' => $this->options['perm'], '#description' => $this->t('Only users with the selected permission flag will be able to access this display.'));
 }
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     $module_info = system_get_info('module');
     // Get list of permissions
     $perms = [];
     $permissions = $this->permissionHandler->getPermissions();
     foreach ($permissions as $perm => $perm_item) {
         $provider = $perm_item['provider'];
         $display_name = $module_info[$provider]['name'];
         $perms[$display_name][$perm] = String::checkPlain(strip_tags($perm_item['title']));
     }
     $form['perm'] = array('#type' => 'select', '#options' => $perms, '#title' => $this->t('Permission'), '#default_value' => $this->options['perm'], '#description' => $this->t('Only users with the selected permission flag will be able to access this display. Note that users with "access all views" can see any view, regardless of other permissions.'));
 }
Exemple #9
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Get anything we need form the base class.
     $form = parent::buildForm($form, $form_state);
     // Display any API key errors.
     MollomUtilities::getAdminAPIKeyStatus();
     MollomUtilities::displayMollomTestModeWarning();
     /* @var $entity \Drupal\mollom\Entity\FormInterface */
     $entity = $this->getEntity();
     $form_id = '';
     if ($entity->isNew()) {
         // Determine if the form id selection just changed.
         $input = $form_state->getUserInput();
         if (!empty($input['id'])) {
             $form_id = $input['id'];
             $mollom_form = $entity->initialize($form_id);
         } else {
             if ($query_form_id = \Drupal::request()->query->get('form_id', '')) {
                 $form_id = $query_form_id;
                 $mollom_form = $entity->initialize($form_id);
             }
         }
     } else {
         $form_id = $entity->id();
         $mollom_form = $entity->initialize();
     }
     $enabled_fields = [];
     if ($entity->isNew() && !empty($input['id'])) {
         foreach ($mollom_form['enabled_fields'] as $value) {
             $enabled_fields[] = rawurlencode($value);
         }
         // Set defaults back.
         // See https://www.drupal.org/node/1100170
         $input['checks'] = $entity->getChecks();
         $input['enabled_fields'] = $enabled_fields;
         $form_state->setUserInput($input);
     } else {
         foreach ($entity->getEnabledFields() as $value) {
             $enabled_fields[] = rawurldecode($value);
         }
     }
     // Build the form.
     if ($entity->isNew()) {
         $options = $this->getProtectableFormOptions();
         if (empty($options)) {
             return $this->redirect('entity.mollom_form.list');
         }
         $form['#attributes']['id'] = $this->getFormId();
         $form['id'] = array('#type' => 'select', '#title' => $this->t('Mollom Form'), '#maxlength' => 255, '#options' => $options, '#default_value' => $form_id, '#empty_option' => t('Select a form to configure...'), '#required' => TRUE, '#ajax' => array('callback' => array($this, 'ajaxFormHandler'), 'wrapper' => $this->getFormId()));
         // Must select the form to protect prior to continuing.
         if (empty($form_id)) {
             return $form;
         }
     } else {
         $form['label'] = array('#title' => t('Protected form'), '#type' => 'textfield', '#default_value' => $entity->label(), '#disabled' => TRUE);
     }
     // Protection mode
     $modes = array(FormInterface::MOLLOM_MODE_ANALYSIS => $this->t('@option <em>(@recommended)</em>', array('@option' => $this->t('Text analysis'), '@recommended' => $this->t('recommended'))), FormInterface::MOLLOM_MODE_CAPTCHA => t('CAPTCHA only'));
     $form['mode'] = array('#type' => 'radios', '#title' => t('Protection mode'), '#options' => $modes, '#default_value' => isset($entity->mode) ? $entity->mode : key($modes));
     $form['mode'][FormInterface::MOLLOM_MODE_ANALYSIS] = array('#description' => t('Mollom will analyze the post and will only show a CAPTCHA when it is unsure.'));
     $form['mode'][FormInterface::MOLLOM_MODE_CAPTCHA] = array('#description' => t('A CAPTCHA will be shown for every post. Only choose this if there are too few text fields to analyze.'));
     $form['mode'][FormInterface::MOLLOM_MODE_CAPTCHA]['#description'] .= '<br />' . t('Note: Page caching is disabled on all pages containing a CAPTCHA-only protected form.');
     $all_permissions = $this->permissionHandler->getPermissions();
     // Prepend Mollom's global permission to the list.
     if (empty($mollom_form['bypass access']) || !is_array($mollom_form['bypass access'])) {
         $mollom_form['bypass access'] = [];
     }
     array_unshift($mollom_form['bypass access'], 'bypass mollom protection');
     $permissions = array();
     if (isset($mollom_form['bypass access'])) {
         foreach ($mollom_form['bypass access'] as $permission) {
             $permissions[Html::getClass($permission)] = array('title' => $all_permissions[$permission]['title'], 'url' => Url::fromRoute('user.admin_permissions'), 'fragment' => 'module-' . $all_permissions[$permission]['provider']);
         }
     }
     $form['mode']['#description'] = t('The protection is omitted for users having any of the permissions: @permission-list', array('@permission-list' => \Drupal::theme()->render('links', array('links' => $permissions))));
     // Textual analysis filters.
     $form['checks'] = array('#type' => 'checkboxes', '#title' => t('Text analysis checks'), '#options' => array('spam' => t('Spam'), 'profanity' => t('Profanity')), '#default_value' => $entity->getChecks(), '#states' => array('visible' => array('[name="mode"]' => array('value' => (string) FormInterface::MOLLOM_MODE_ANALYSIS))));
     // Profanity check requires text to analyze; unlike the spam check, there
     // is no fallback in case there is no text.
     $form['checks']['profanity']['#access'] = !empty($mollom_form['elements']);
     // Form elements defined by hook_mollom_form_info() use the
     // 'parent][child' syntax, which Form API also uses internally for
     // form_set_error(), and which allows us to recurse into nested fields
     // during processing of submitted form values. However, since we are using
     // those keys also as internal values to configure the fields to use for
     // textual analysis, we need to encode them. Otherwise, a nested field key
     // would result in the following checkbox attribute:
     //   '#name' => 'mollom[enabled_fields][parent][child]'
     // This would lead to a form validation error, because it is a valid key.
     // By encoding them, we prevent this from happening:
     //   '#name' => 'mollom[enabled_fields][parent%5D%5Bchild]'
     $elements = array();
     if (isset($mollom_form['elements']) && is_array($mollom_form['elements'])) {
         foreach ($mollom_form['elements'] as $key => $value) {
             $elements[rawurlencode($key)] = $value;
         }
     }
     $enabled_field_selections = [];
     foreach ($enabled_fields as $key => $value) {
         $enabled_field_selections[rawurlencode($key)] = rawurlencode($value);
     }
     $form['enabled_fields'] = array('#type' => 'checkboxes', '#title' => t('Text fields to analyze'), '#options' => $elements, '#default_value' => $enabled_field_selections, '#description' => t('Only enable fields that accept text (not numbers). Omit fields that contain sensitive data (e.g., credit card numbers) or computed/auto-generated values, as well as author information fields (e.g., name, e-mail).'), '#access' => !empty($mollom_form['elements']), '#states' => array('visible' => array('[name="mode"]' => array('value' => (string) FormInterface::MOLLOM_MODE_ANALYSIS))));
     $form['mapping'] = array('#type' => 'value', '#value' => $mollom_form['mapping']);
     if ($entity->isNew()) {
         $form['module'] = array('#type' => 'value', '#value' => $mollom_form['module']);
         $form['label'] = array('#type' => 'value', '#value' => $mollom_form['title']);
         $form['entity'] = array('#type' => 'value', '#value' => $mollom_form['entity']);
         $form['bundle'] = array('#type' => 'value', '#value' => $mollom_form['bundle']);
     }
     $form['strictness'] = array('#type' => 'radios', '#title' => t('Text analysis strictness'), '#options' => array('normal' => t('@option <em>(@recommended)</em>', array('@option' => t('Normal'), '@recommended' => $this->t('recommended'))), 'strict' => t('Strict: Posts are more likely classified as spam'), 'relaxed' => t('Relaxed: Posts are more likely classified as ham')), '#default_value' => $entity->getStrictness(), '#states' => array('visible' => array('[name="mode"]' => array('value' => (string) FormInterface::MOLLOM_MODE_ANALYSIS))));
     $form['unsure'] = array('#type' => 'radios', '#title' => t('When text analysis is unsure'), '#default_value' => $entity->getUnsure(), '#options' => array('captcha' => t('@option <em>(@recommended)</em>', array('@option' => t('Show a CAPTCHA'), '@recommended' => $this->t('recommended'))), 'moderate' => t('Retain the post for manual moderation'), 'binary' => t('Accept the post')), '#required' => $entity->getProtectionMode() == FormInterface::MOLLOM_MODE_ANALYSIS, '#states' => array('visible' => array('[name="mode"]' => array('value' => (string) FormInterface::MOLLOM_MODE_ANALYSIS), '[name="checks[spam]"]' => array('checked' => TRUE))));
     // Only possible for forms supporting moderation of unpublished posts.
     $form['unsure']['moderate']['#access'] = !empty($mollom_form['moderation callback']);
     $form['discard'] = array('#type' => 'radios', '#title' => t('When text analysis identifies spam'), '#default_value' => $entity->getDiscard(), '#options' => array(1 => t('@option <em>(@recommended)</em>', array('@option' => t('Discard the post'), '@recommended' => $this->t('recommended'))), 0 => t('Retain the post for manual moderation')), '#required' => $entity->getProtectionMode() == FormInterface::MOLLOM_MODE_ANALYSIS, '#states' => array('visible' => array('[name="mode"]' => array('value' => (string) FormInterface::MOLLOM_MODE_ANALYSIS), '[name="checks[spam]"]' => array('checked' => TRUE))));
     // Return the form.
     return $form;
 }