class FormTestHooks

Hook implementations for form_test.

Hierarchy

Expanded class hierarchy of FormTestHooks

File

core/modules/system/tests/modules/form_test/src/Hook/FormTestHooks.php, line 17

Namespace

Drupal\form_test\Hook
View source
class FormTestHooks {
  use StringTranslationTrait;
  public function __construct(protected ElementInfoManagerInterface $elementInfoManager) {
  }
  
  /**
   * Implements hook_form_FORM_ID_alter().
   */
  public function blockFormFormTestAlterFormAlter(&$form, FormStateInterface $form_state) : void {
    \Drupal::messenger()->addStatus('block_form_form_test_alter_form_alter() executed.');
  }
  
  /**
   * Implements hook_form_alter().
   */
  public function formAlter(&$form, FormStateInterface $form_state, $form_id) : void {
    if ($form_id == 'form_test_alter_form') {
      \Drupal::messenger()->addStatus('form_test_form_alter() executed.');
    }
  }
  
  /**
   * Implements hook_form_FORM_ID_alter().
   */
  public function formFormTestAlterFormAlter(&$form, FormStateInterface $form_state) : void {
    \Drupal::messenger()->addStatus('form_test_form_form_test_alter_form_alter() executed.');
  }
  
  /**
   * Implements hook_form_FORM_ID_alter().
   */
  public function systemFormFormTestAlterFormAlter(&$form, FormStateInterface $form_state) : void {
    \Drupal::messenger()->addStatus('system_form_form_test_alter_form_alter() executed.');
  }
  
  /**
   * Implements hook_form_FORM_ID_alter() for the registration form.
   */
  public function formUserRegisterFormAlter(&$form, FormStateInterface $form_state) : void {
    $submit = $this->elementInfoManager
      ->fromRenderable($form)
      ->createChild('test_rebuild', Submit::class);
    $submit->value = $this->t('Rebuild');
    $submit->submit = [
      [
        Callbacks::class,
        'userRegisterFormRebuild',
      ],
    ];
  }
  
  /**
   * Implements hook_form_FORM_ID_alter() for form_test_vertical_tabs_access_form().
   */
  public function formFormTestVerticalTabsAccessFormAlter(&$form, &$form_state, $form_id) : void {
    $element_object = $this->elementInfoManager
      ->fromRenderable($form);
    $element_object->getChild('vertical_tabs1')->access = FALSE;
    $element_object->getChild('vertical_tabs2')->access = FALSE;
    $element_object->getChild('tab3')->access = FALSE;
    $element_object->getChild('fieldset1')->access = FALSE;
    $element_object->getChild('container')->access = FALSE;
  }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
FormTestHooks::blockFormFormTestAlterFormAlter public function Implements hook_form_FORM_ID_alter().
FormTestHooks::formAlter public function Implements hook_form_alter().
FormTestHooks::formFormTestAlterFormAlter public function Implements hook_form_FORM_ID_alter().
FormTestHooks::formFormTestVerticalTabsAccessFormAlter public function Implements hook_form_FORM_ID_alter() for form_test_vertical_tabs_access_form().
FormTestHooks::formUserRegisterFormAlter public function Implements hook_form_FORM_ID_alter() for the registration form.
FormTestHooks::systemFormFormTestAlterFormAlter public function Implements hook_form_FORM_ID_alter().
FormTestHooks::__construct public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.