You are here

class SimpleSearchFormLazyBuilder in Simple search form 8

Service for build a simple search form.

Hierarchy

Expanded class hierarchy of SimpleSearchFormLazyBuilder

1 string reference to 'SimpleSearchFormLazyBuilder'
simple_search_form.services.yml in ./simple_search_form.services.yml
simple_search_form.services.yml
1 service uses SimpleSearchFormLazyBuilder
simple_search_form.lazy_builder in ./simple_search_form.services.yml
Drupal\simple_search_form\SimpleSearchFormLazyBuilder

File

src/SimpleSearchFormLazyBuilder.php, line 13

Namespace

Drupal\simple_search_form
View source
class SimpleSearchFormLazyBuilder implements TrustedCallbackInterface {

  /**
   * The form builder service.
   *
   * @var \Drupal\Core\Form\FormBuilderInterface
   */
  protected $formBuilder;

  /**
   * Constructs a new SimpleSearchFormLazyBuilder object.
   *
   * @param \Drupal\Core\Form\FormBuilderInterface $form_builder
   *   The form builder service.
   */
  public function __construct(FormBuilderInterface $form_builder) {
    $this->formBuilder = $form_builder;
  }

  /**
   * {@inheritdoc}
   */
  public static function trustedCallbacks() {
    return [
      'getForm',
    ];
  }

  /**
   * Lazy builder callback to build the form.
   *
   * @param string $config
   *   Simple search form configuration JSON.
   *
   * @return array
   *   A render-able form array.
   */
  public function getForm($config) {
    $config = Json::decode($config);
    $form = $this->formBuilder
      ->getForm(SimpleSearchForm::class, $config);

    // Vary caching of this block per selected $_GET parameter when decided
    // to use "Keep value in search input after form submit" feature.
    if ($config['input_keep_value']) {
      $form['#cache']['contexts'][] = 'url.query_args:' . $config['get_parameter'];
    }
    return $form;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SimpleSearchFormLazyBuilder::$formBuilder protected property The form builder service.
SimpleSearchFormLazyBuilder::getForm public function Lazy builder callback to build the form.
SimpleSearchFormLazyBuilder::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
SimpleSearchFormLazyBuilder::__construct public function Constructs a new SimpleSearchFormLazyBuilder object.
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.