Пример #1
0
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     // allow + for or, , for and
     $form['break_phrase'] = array('#type' => 'checkbox', '#title' => $this->t('Allow multiple values'), '#description' => $this->t('If selected, users can enter multiple values in the form of 1+2+3 (for OR) or 1,2,3 (for AND).'), '#default_value' => !empty($this->options['break_phrase']), '#fieldset' => 'more');
     $form['not'] = array('#type' => 'checkbox', '#title' => $this->t('Exclude'), '#description' => $this->t('If selected, the numbers entered for the filter will be excluded rather than limiting the view.'), '#default_value' => !empty($this->options['not']), '#fieldset' => 'more');
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL)
 {
     parent::init($view, $display, $options);
     if (!empty($this->definition['formula'])) {
         $this->formula = $this->definition['formula'];
     }
 }
Пример #3
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))));
 }
Пример #4
0
 public function query($group_by = FALSE)
 {
     $empty = FALSE;
     if (isset($this->definition['zero is null']) && $this->definition['zero is null']) {
         if (empty($this->argument)) {
             $empty = TRUE;
         }
     } else {
         if (!isset($this->argument)) {
             $empty = TRUE;
         }
     }
     if ($empty) {
         parent::ensureMyTable();
         $this->query->addWhere(0, "{$this->tableAlias}.{$this->realField}", NULL, 'IS NULL');
         return;
     }
     if (!empty($this->options['break_phrase'])) {
         if (!empty($this->definition['numeric'])) {
             $this->breakPhrase($this->argument, $this);
         } else {
             $this->breakPhraseString($this->argument, $this);
         }
     } else {
         $this->value = array($this->argument);
         $this->operator = 'or';
     }
     $this->helper->addFilter();
 }
Пример #5
0
 protected function defaultActions($which = NULL)
 {
     // Disallow summary views on this argument.
     if (!$which) {
         $actions = parent::defaultActions();
         unset($actions['summary asc']);
         unset($actions['summary desc']);
         return $actions;
     }
     if ($which != 'summary asc' && $which != 'summary desc') {
         return parent::defaultActions($which);
     }
 }
Пример #6
0
 /**
  * Override defaultActions() to remove actions that don't
  * make sense for a null argument.
  */
 protected function defaultActions($which = NULL)
 {
     if ($which) {
         if (in_array($which, array('ignore', 'not found', 'empty', 'default'))) {
             return parent::defaultActions($which);
         }
         return;
     }
     $actions = parent::defaultActions();
     unset($actions['summary asc']);
     unset($actions['summary desc']);
     return $actions;
 }
Пример #7
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']);
 }
Пример #8
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']);
     }
 }
Пример #9
0
 public function summaryName($data)
 {
     return $this->caseTransform(parent::summaryName($data), $this->options['case']);
 }
Пример #10
0
 /**
  * Provide a form to edit options for this plugin.
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     $form['contextlevel'] = array('#type' => 'textfield', '#title' => t('The context level'), '#default_value' => $this->options['contextlevel'], '#size' => 5, '#maxlength' => 10);
     parent::buildOptionsForm($form, $form_state);
 }
Пример #11
0
 /**
  * {@inheritdoc}
  */
 public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL)
 {
     parent::init($view, $display, $options);
     $this->searchType = $this->definition['search_type'];
 }