dpi / rng

RNG is a Drupal module enabling people to register for events.
https://www.drupal.org/project/rng
GNU General Public License v2.0
15 stars 23 forks source link

Add option to display registrant form open by default if only one exists (show_entity_create_form) #158

Open JPustkuchen opened 6 years ago

JPustkuchen commented 6 years ago

Context: When displaying an event registration form (in our case using rng_quick and rng_contact) the default form display with the many options is much too complicated and it would be good and enough to display the registrant form with its field directly / initially.

I tried to solve this using a custom module and found out that "show_entity_create_form" controls that. See:

<?php
  /**
   * Get form state for opening the create-an-entity sub-form.
   *
   * @return boolean
   *   Wther the create-an-entity sub-form is open.
   */
  public function getShowCreateEntitySubform() {
    return (bool) $this->formState->get(array_merge($this->element['#parents'], ['show_entity_create_form']));
  }

  /**
   * Set form state for opening the create-an-entity sub-form.
   *
   * @param $value
   */
  public function setShowCreateEntitySubform($value) {
    $this->formState->set(array_merge($this->element['#parents'], ['show_entity_create_form']), $value);
  }
?>

(http://cgit.drupalcode.org/rng/tree/src/RegistrantsElementUtility.php?h=8.x-1.x)

$entity_create_form = $utility->getShowCreateEntitySubform(); checks for that in src/Element/Registrants.php but the function always returns FALSE in the current implementation if the toggle button is not clicked.

It would be very helpful to have an option or open the form by default if the arity is single and there is only one type of registration allowed. This makes a lot of sense I think and would be cool for UX! :)

JPustkuchen commented 6 years ago

Drupal style patch attached to use with composer-patches for example.

rng-158-open_registrant_form_by_default_if_one_registrant_type.patch.txt