From 84a00e83ae2a965ac7a7c87c41f010281a95e335 Mon Sep 17 00:00:00 2001 From: Joshua Fernandes <“joshua.1234511@yahoo.in”> Date: Thu, 3 Oct 2024 16:30:11 +0530 Subject: [PATCH] Code updates. --- .../civictheme_dev/civictheme_dev.routing.yml | 14 ----- .../src/Form/IndividualElementForm.php | 38 ------------- .../src/Form/StyleguideForm.php | 56 ++++++++++++++++++- .../contrib/civictheme/includes/form.inc | 2 +- 4 files changed, 54 insertions(+), 56 deletions(-) delete mode 100644 web/modules/custom/civictheme_dev/src/Form/IndividualElementForm.php diff --git a/web/modules/custom/civictheme_dev/civictheme_dev.routing.yml b/web/modules/custom/civictheme_dev/civictheme_dev.routing.yml index caf783402..4f1caf0fc 100644 --- a/web/modules/custom/civictheme_dev/civictheme_dev.routing.yml +++ b/web/modules/custom/civictheme_dev/civictheme_dev.routing.yml @@ -12,17 +12,3 @@ civictheme_dev.admin_styleguide_form: _title: 'Styleguide Form' requirements: _permission: 'view the administration theme' -civictheme_dev.styleguide_element_form: - path: '/styleguide-element-test-form' - defaults: - _form: 'Drupal\civictheme_dev\Form\IndividualElementForm' - _title: 'Test Individual Element Form' - requirements: - _permission: 'access content' -civictheme_dev.admin_element_styleguide_form: - path: '/admin/structure/styleguide-element-test-form' - defaults: - _form: 'Drupal\civictheme_dev\Form\IndividualElementForm' - _title: 'Test Individual Element Form' - requirements: - _permission: 'view the administration theme' diff --git a/web/modules/custom/civictheme_dev/src/Form/IndividualElementForm.php b/web/modules/custom/civictheme_dev/src/Form/IndividualElementForm.php deleted file mode 100644 index aa5922f86..000000000 --- a/web/modules/custom/civictheme_dev/src/Form/IndividualElementForm.php +++ /dev/null @@ -1,38 +0,0 @@ - 'password_confirm', - ]; - } - - /** - * {@inheritDoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - // @todo Implement submitForm() method. - } - -} diff --git a/web/modules/custom/civictheme_dev/src/Form/StyleguideForm.php b/web/modules/custom/civictheme_dev/src/Form/StyleguideForm.php index dde30b9f7..3d48c6ae1 100644 --- a/web/modules/custom/civictheme_dev/src/Form/StyleguideForm.php +++ b/web/modules/custom/civictheme_dev/src/Form/StyleguideForm.php @@ -4,6 +4,7 @@ namespace Drupal\civictheme_dev\Form; +use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Extension\ThemeHandlerInterface; use Drupal\Core\Form\FormBase; @@ -15,7 +16,7 @@ /** * Styleguide form. */ -class StyleguideForm extends FormBase { +class StyleguideForm extends FormBase implements ContainerInjectionInterface { /** * StyleguideForm constructor. @@ -34,6 +35,7 @@ public function __construct(protected ElementInfoManager $elementInfoManager, pr * {@inheritdoc} */ public static function create(ContainerInterface $container): static { + // @phpstan-ignore-next-line return new static( $container->get('plugin.manager.element_info'), $container->get('entity_type.manager'), @@ -50,6 +52,8 @@ public function getFormId(): string { /** * {@inheritDoc} + * + * @phpstan-ignore-next-line */ public function buildForm(array $form, FormStateInterface $form_state): array { // Getting form element plugin manager. @@ -78,10 +82,10 @@ public function buildForm(array $form, FormStateInterface $form_state): array { * * @param string $id * Element id. - * @param array $element + * @param \Drupal\Core\Render\Element\FormElement $element * Actual element. * - * @return array + * @return array * Form element. */ protected function createFormElement(string $id, FormElement $element): array { @@ -133,12 +137,22 @@ protected function createFormElement(string $id, FormElement $element): array { /** * {@inheritDoc} + * + * @phpstan-ignore-next-line */ public function submitForm(array &$form, FormStateInterface $form_state) { } /** * Generates entity autocomplete form element. + * + * @param array $form_element + * Form element. + * @param \Drupal\Core\Render\Element\FormElement $element + * Form element. + * + * @return array + * Form element. */ protected function createEntityAutoCompleteFormElement(array $form_element, FormElement $element): array { $form_element['#type'] = 'entity_autocomplete'; @@ -152,6 +166,14 @@ protected function createEntityAutoCompleteFormElement(array $form_element, Form /** * Generates options-style form elements. + * + * @param array $form_element + * Form element. + * @param \Drupal\Core\Render\Element\FormElement $element + * Form element. + * + * @return array + * Form element. */ protected function createOptionsFormElement(array $form_element, FormElement $element): array { $form_element['#options'] = [ @@ -165,6 +187,14 @@ protected function createOptionsFormElement(array $form_element, FormElement $el /** * Create table form element helper. + * + * @param array $form_element + * Form element. + * @param \Drupal\Core\Render\Element\FormElement $element + * Form element. + * + * @return array + * Form element. */ protected function createTableFormElement(array $form_element, FormElement $element): array { $form_element['#header'] = ['Header 1', 'Header 2', 'Header 3']; @@ -190,6 +220,16 @@ protected function createTableFormElement(array $form_element, FormElement $elem /** * Create image button helper. + * + * @param array $form_element + * Form element. + * @param \Drupal\Core\Render\Element\FormElement $element + * Form element. + * + * @return array + * Form element. + * + * @phpstan-ignore-next-line */ protected function createImageButton(array $form_element, FormElement $element): array { $theme_path = $this->themeHandler->getTheme('civictheme')->getPath(); @@ -201,6 +241,16 @@ protected function createImageButton(array $form_element, FormElement $element): /** * Create button helper. + * + * @param array $form_element + * Form element. + * @param \Drupal\Core\Render\Element\FormElement $element + * Form element. + * + * @return array + * Form element. + * + * @phpstan-ignore-next-line */ protected function createButton(array $form_element, FormElement $element): array { $form_element['#value'] = $form_element['#title']; diff --git a/web/themes/contrib/civictheme/includes/form.inc b/web/themes/contrib/civictheme/includes/form.inc index da2000d4d..73cfe1220 100644 --- a/web/themes/contrib/civictheme/includes/form.inc +++ b/web/themes/contrib/civictheme/includes/form.inc @@ -100,7 +100,7 @@ function _civictheme_form_alter__non_form_elements__link(array &$element): void * * @SuppressWarnings(PHPMD.StaticAccess) */ -function _civictheme_form_preprocess_hidden_form_elements(array $variables): void { +function _civictheme_form_preprocess_hidden_form_elements(array &$variables): void { if (empty($variables['form'])) { return; }