Beispiel #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))));
 }
Beispiel #2
0
 /**
  * Tests the User (ID) argument validator.
  */
 function testArgumentValidateUserUid()
 {
     $account = $this->account;
     $view = Views::getView('test_view_argument_validate_user');
     $this->executeView($view);
     $this->assertTrue($view->argument['null']->validateArgument($account->id()));
     // Reset argument validation.
     $view->argument['null']->argument_validated = NULL;
     // Fail for a valid numeric, but for a user that doesn't exist
     $this->assertFalse($view->argument['null']->validateArgument(32));
     $form = $form_state = array();
     $view->argument['null']->buildOptionsForm($form, $form_state);
     $sanitized_id = ArgumentPluginBase::encodeValidatorId('entity:user');
     $this->assertTrue($form['validate']['options'][$sanitized_id]['roles']['#states']['visible'][':input[name="options[validate][options][' . $sanitized_id . '][restrict_roles]"]']['checked']);
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     $entity_type_id = $this->definition['entity_type'];
     // Derivative IDs are all entity:entity_type. Sanitized for js.
     // The ID is converted back on submission.
     $sanitized_id = ArgumentPluginBase::encodeValidatorId($this->definition['id']);
     $entity_type = $this->entityManager->getDefinition($entity_type_id);
     // If the entity has bundles, allow option to restrict to bundle(s).
     if ($entity_type->hasKey('bundle')) {
         $bundle_options = array();
         foreach ($this->entityManager->getBundleInfo($entity_type_id) as $bundle_id => $bundle_info) {
             $bundle_options[$bundle_id] = $bundle_info['label'];
         }
         $form['bundles'] = array('#title' => $entity_type->getBundleLabel() ?: $this->t('Bundles'), '#default_value' => $this->options['bundles'], '#type' => 'checkboxes', '#options' => $bundle_options, '#description' => $this->t('If none are selected, all are allowed.'));
     }
     // Offer the option to filter by access to the entity in the argument.
     $form['access'] = array('#type' => 'checkbox', '#title' => $this->t('Validate user has access to the %name', array('%name' => $entity_type->getLabel())), '#default_value' => $this->options['access']);
     $form['operation'] = array('#type' => 'radios', '#title' => $this->t('Access operation to check'), '#options' => array('view' => $this->t('View'), 'update' => $this->t('Edit'), 'delete' => $this->t('Delete')), '#default_value' => $this->options['operation'], '#states' => array('visible' => array(':input[name="options[validate][options][' . $sanitized_id . '][access]"]' => array('checked' => TRUE))));
     // If class is multiple capable give the option to validate single/multiple.
     if ($this->multipleCapable) {
         $form['multiple'] = array('#type' => 'radios', '#title' => $this->t('Multiple arguments'), '#options' => array(0 => $this->t('Single ID', array('%type' => $entity_type->getLabel())), 1 => $this->t('One or more IDs separated by , or +', array('%type' => $entity_type->getLabel()))), '#default_value' => (string) $this->options['multiple']);
     }
 }