isSearchExecutable example

/** * {@inheritdoc} */
  public function getType() {
    return $this->getPluginId();
  }

  /** * {@inheritdoc} */
  public function execute() {
    if ($this->isSearchExecutable()) {
      $results = $this->findResults();

      if ($results) {
        return $this->prepareResults($results);
      }
    }

    return [];
  }

  /** * Queries to find search results, and sets status messages. * * This method can assume that $this->isSearchExecutable() has already been * checked and returned TRUE. * * @return \Drupal\Core\Database\StatementInterface|null * Results from search query execute() method, or NULL if the search * failed. */
/** * Execute the search. * * This is a dummy search, so when search "executes", we just return a dummy * result containing the keywords and a list of conditions. * * @return array * A structured list of search results */
  public function execute() {
    $results = [];
    if (!$this->isSearchExecutable()) {
      return $results;
    }
    return [
      [
        'link' => Url::fromRoute('test_page_test.test_page')->toString(),
        'type' => 'Dummy result type',
        'title' => 'Dummy title',
        'snippet' => new FormattableMarkup("Dummy search snippet to display. Keywords: @keywords\n\nConditions: @search_parameters", ['@keywords' => $this->keywords, '@search_parameters' => print_r($this->searchParameters, TRUE)]),
      ],
    ];
  }

  
$plugin->setSearch($keys$request->query->all()$request->attributes->all());
    }

    $build['#title'] = $plugin->suggestedTitle();
    $build['search_form'] = $this->formBuilder()->getForm(SearchPageForm::class$entity);

    // Build search results, if keywords or other search parameters are in the     // GET parameters. Note that we need to try the search if 'keys' is in     // there at all, vs. being empty, due to advanced search.     $results = [];
    if ($request->query->has('keys')) {
      if ($plugin->isSearchExecutable()) {
        // Log the search.         if ($this->config('search.settings')->get('logging')) {
          $this->logger->notice('Searched %type for %keys.', ['%keys' => $keys, '%type' => $entity->label()]);
        }

        // Collect the search results.         $results = $plugin->buildResults();
      }
      else {
        // The search not being executable means that no keywords or other         // conditions were entered.

  public function access($operation = 'view', AccountInterface $account = NULL, $return_as_object = FALSE) {
    $result = AccessResult::allowedIf(!empty($account) && $account->hasPermission('access user profiles'))->cachePerPermissions();
    return $return_as_object ? $result : $result->isAllowed();
  }

  /** * {@inheritdoc} */
  public function execute() {
    $results = [];
    if (!$this->isSearchExecutable()) {
      return $results;
    }

    // Process the keywords.     $keys = $this->keywords;
    // Escape for LIKE matching.     $keys = $this->database->escapeLike($keys);
    // Replace wildcards with MySQL/PostgreSQL wildcards.     $keys = preg_replace('!\*+!', '%', $keys);

    // Run the query to find matching users.
/** * {@inheritdoc} */
  public function getType() {
    return $this->getPluginId();
  }

  /** * {@inheritdoc} */
  public function execute() {
    if ($this->isSearchExecutable()) {
      $results = $this->findResults();

      if ($results) {
        return $this->prepareResults($results);
      }
    }

    return [];
  }

  /** * Finds the search results. * * @return \Drupal\Core\Database\StatementInterface|null * Results from search query execute() method, or NULL if the search * failed. */
Home | Imprint | This part of the site doesn't use cookies.