1 <!-- @file Documentation for the @BootstrapForm annotated discovery plugin. -->
6 - [Create a plugin](#create)
7 - [Rebuild the cache](#rebuild)
11 ## Create a plugin {#create}
13 We'll use `SearchBlockForm` implemented by this base theme as an example of
14 how to remove `#input_group_button` from `search_block_form`.
16 Replace all following instances of `THEMENAME` with the actual machine name of
19 Create a file at `./THEMENAME/src/Plugin/Form/SearchBlockForm.php` with the
25 namespace Drupal\THEMENAME\Plugin\Form;
27 use Drupal\bootstrap\Plugin\Form\SearchBlockForm as BootstrapSearchBlockForm;
28 use Drupal\bootstrap\Utility\Element;
29 use Drupal\Core\Form\FormStateInterface;
32 * Implements hook_form_FORM_ID_alter().
34 * @ingroup plugins_form
36 * @BootstrapForm("search_block_form")
38 class SearchBlockForm extends BootstrapSearchBlockForm {
43 public function alterForm(array &$form, FormStateInterface $form_state, $form_id = NULL) {
44 // Call the parent method from the base theme, if applicable (which it is
45 // in this case because Bootstrap actually implements this alter).
46 parent::alterForm($form, $form_state, $form_id);
48 // Disable #input_group_button the normal way:
49 $form['keys']['#input_group_button'] = FALSE;
55 public function alterFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL) {
56 // This method is the same as above, except the the $form argument passed is
57 // an instance of \Drupal\bootstrap\Utility\Element for easier manipulation.
58 // Using this method is preferable and considered "Best Practice".
60 // Disable #input_group_button using the $form Element object:
61 // $form->keys->setProperty('input_group_button', FALSE);.
67 public static function submitForm(array &$form, FormStateInterface $form_state) {
68 // This method is automatically called when the form is submitted.
74 public static function submitFormElement(Element $form, FormStateInterface $form_state) {
75 // This method is the same as above, except the the $form argument passed is
76 // an instance of \Drupal\bootstrap\Utility\Element for easier manipulation.
77 // Using this method is preferable and considered "Best Practice".
83 public static function validateForm(array &$form, FormStateInterface $form_state) {
84 // This method is automatically called when the form is validated.
90 public static function validateFormElement(Element $form, FormStateInterface $form_state) {
91 // This method is the same as above, except the the $form argument passed is
92 // an instance of \Drupal\bootstrap\Utility\Element for easier manipulation.
93 // Using this method is preferable and considered "Best Practice".
100 ## Rebuild the cache {#rebuild}
102 Once you have saved, you must rebuild your cache for this new plugin to be
103 discovered. This must happen anytime you make a change to the actual file name
104 or the information inside the `@BootstrapForm` annotation.
106 To rebuild your cache, navigate to `admin/config/development/performance` and
107 click the `Clear all caches` button. Or if you prefer, run `drush cr` from the
110 VoilĂ ! After this, you should have a fully functional `@BootstrapForm` plugin!