Skip to content

Commit

Permalink
Code updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Fernandes committed Oct 3, 2024
1 parent a4dc623 commit 84a00e8
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 56 deletions.
14 changes: 0 additions & 14 deletions web/modules/custom/civictheme_dev/civictheme_dev.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

This file was deleted.

56 changes: 53 additions & 3 deletions web/modules/custom/civictheme_dev/src/Form/StyleguideForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,7 +16,7 @@
/**
* Styleguide form.
*/
class StyleguideForm extends FormBase {
class StyleguideForm extends FormBase implements ContainerInjectionInterface {

/**
* StyleguideForm constructor.
Expand All @@ -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'),
Expand All @@ -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.
Expand Down Expand Up @@ -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<int|string, mixed>
* Form element.
*/
protected function createFormElement(string $id, FormElement $element): array {
Expand Down Expand Up @@ -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<string, mixed>
* Form element.
*/
protected function createEntityAutoCompleteFormElement(array $form_element, FormElement $element): array {
$form_element['#type'] = 'entity_autocomplete';
Expand All @@ -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<string, mixed>
* Form element.
*/
protected function createOptionsFormElement(array $form_element, FormElement $element): array {
$form_element['#options'] = [
Expand All @@ -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<string, mixed>
* Form element.
*/
protected function createTableFormElement(array $form_element, FormElement $element): array {
$form_element['#header'] = ['Header 1', 'Header 2', 'Header 3'];
Expand All @@ -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<int, array>
* Form element.
*
* @phpstan-ignore-next-line
*/
protected function createImageButton(array $form_element, FormElement $element): array {
$theme_path = $this->themeHandler->getTheme('civictheme')->getPath();
Expand All @@ -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<int, array>
* Form element.
*
* @phpstan-ignore-next-line
*/
protected function createButton(array $form_element, FormElement $element): array {
$form_element['#value'] = $form_element['#title'];
Expand Down
2 changes: 1 addition & 1 deletion web/themes/contrib/civictheme/includes/form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 84a00e8

Please sign in to comment.