usesExposed example

$form['block_hide_empty'] = [
          '#title' => $this->t('Hide block if no result/empty text'),
          '#type' => 'checkbox',
          '#description' => $this->t('Hide the block if there is no result and no empty text and no header/footer which is shown on empty result'),
          '#default_value' => $this->getOption('block_hide_empty'),
        ];
        break;

      case 'exposed_form_options':
        $this->view->initHandlers();
        if (!$this->usesExposed() && parent::usesExposed()) {
          $form['exposed_form_options']['warning'] = [
            '#weight' => -10,
            '#markup' => '<div class="messages messages--warning">' . $this->t('Exposed filters in block displays require "Use AJAX" to be set to work correctly.') . '</div>',
          ];
        }
        break;

      case 'allow':
        $form['#title'] .= $this->t('Allow settings in the block configuration');

        $options = [
          
// Call a module hook and see if it wants to present us with a     // pre-built query or instruct us not to build the query for     // some reason.     // @todo: Implement this. Use the same mechanism Panels uses.
    // Run through our handlers and ensure they have necessary information.     $this->initHandlers();

    // Let the handlers interact with each other if they really want.     $this->_preQuery();

    if ($this->display_handler->usesExposed()) {
      /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form */
      $exposed_form = $this->display_handler->getPlugin('exposed_form');
      $this->exposed_widgets = $exposed_form->renderExposedForm();
      if (!empty($this->build_info['abort'])) {
        $this->built = TRUE;
        // Don't execute the query, $form_state, but rendering will still be executed to display the empty text.         $this->executed = TRUE;
        return empty($this->build_info['fail']);
      }
    }

    
return TRUE;
    }
    // We need to know the operator, which is normally set in     // \Drupal\views\Plugin\views\filter\FilterPluginBase::acceptExposedInput(),     // before we actually call the parent version of ourselves.     if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator_id']) && isset($input[$this->options['expose']['operator_id']])) {
      $this->operator = $input[$this->options['expose']['operator_id']];
    }

    // If view is an attachment and is inheriting exposed filters, then assume     // exposed input has already been validated     if (!empty($this->view->is_attachment) && $this->view->display_handler->usesExposed()) {
      $this->validated_exposed_input = (array) $this->view->exposed_raw_input[$this->options['expose']['identifier']];
    }

    // If we're checking for EMPTY or NOT, we don't need any input, and we can     // say that our input conditions are met by just having the right operator.     if ($this->operator == 'empty' || $this->operator == 'not empty') {
      return TRUE;
    }

    // If it's non-required and there's no value don't bother filtering.     if (!$this->options['expose']['required'] && empty($this->validated_exposed_input)) {
      
break;
    }

  }

  /** * {@inheritdoc} */
  public function usesExposed() {
    // Attachment displays only use exposed widgets if they are set to inherit     // the exposed filter settings of their parent display.     if (!empty($this->options['inherit_exposed_filters']) && parent::usesExposed()) {
      return TRUE;
    }
    return FALSE;
  }

  /** * {@inheritdoc} */
  public function displaysExposed() {
    // If an attachment is set to inherit the exposed filter settings from its     // parent display, then don't render and display a second set of exposed

  public function testUseCountQuery() {
    $this->assertTrue($this->pager->useCountQuery());
  }

  /** * Tests the usesExposed() method. * * @see \Drupal\views\Plugin\views\pager\PagerPluginBase::usedExposed() */
  public function testUsesExposed() {
    $this->assertFalse($this->pager->usesExposed());
  }

  /** * Tests the hasMoreRecords() method. * * @dataProvider providerTestHasMoreRecords * * @see \Drupal\views\Plugin\views\pager\PagerPluginBase::hasMoreRecords() */
  public function testHasMoreRecords($items_per_page$total_items$current_page$has_more_records) {
    $this->pager->setItemsPerPage($items_per_page);
    
if (!isset($this->has_exposed)) {
      foreach ($this->handlers as $type => $value) {
        foreach ($this->view->$type as $handler) {
          if ($handler->canExpose() && $handler->isExposed()) {
            // One is all we need; if we find it, return TRUE.             $this->has_exposed = TRUE;
            return TRUE;
          }
        }
      }
      $pager = $this->getPlugin('pager');
      if (isset($pager) && $pager->usesExposed()) {
        $this->has_exposed = TRUE;
        return TRUE;
      }
      $this->has_exposed = FALSE;
    }

    return $this->has_exposed;
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.