Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.0.0-beta9 #101

Merged
merged 14 commits into from
Jan 24, 2025
Merged
7 changes: 5 additions & 2 deletions localgov_forms.install
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
*/

use Drupal\Component\Serialization\Yaml;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\webform\Entity\WebformOptions;

/**
* Implements hook_install().
*/
function localgov_forms_install() {
function localgov_forms_install(): void {

// Override Webforms default configuration.
$config = \Drupal::configFactory()->getEditable('localgov_forms.webform.settings');
Expand All @@ -24,7 +25,7 @@ function localgov_forms_install() {
*
* Creates a Webform option for Local custodian codes.
*/
function localgov_forms_update_8001() {
function localgov_forms_update_8001(): ?TranslatableMarkup {

$has_local_custodian_codes_option = Drupal::service('entity_type.manager')->getStorage('webform_options')->load('local_custodian_codes_gb');
if ($has_local_custodian_codes_option) {
Expand All @@ -39,4 +40,6 @@ function localgov_forms_update_8001() {
$local_custodian_codes_option = Yaml::decode(file_get_contents(__DIR__ . '/config/install/webform.webform_options.local_custodian_codes_gb.yml'));
$new_local_custodian_codes_option = WebformOptions::create($local_custodian_codes_option);
$new_local_custodian_codes_option->save();

return NULL;
}
8 changes: 4 additions & 4 deletions localgov_forms.module
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use Drupal\Core\Render\Element;
/**
* Implements hook_theme().
*/
function localgov_forms_theme() {
function localgov_forms_theme(): array {
return [
// Form element: localgov_webform_uk_address.
'localgov_forms_uk_address_lookup' => [
Expand All @@ -29,7 +29,7 @@ function localgov_forms_theme() {
* Makes sub-elements available within the `content` variable. Mostly lifted
* from _template_preprocess_webform_composite().
*/
function template_preprocess_localgov_forms_uk_address_lookup(array &$variables) {
function template_preprocess_localgov_forms_uk_address_lookup(array &$variables): void {

$element = $variables['element'];
foreach (Element::children($element) as $key) {
Expand All @@ -44,14 +44,14 @@ function template_preprocess_localgov_forms_uk_address_lookup(array &$variables)
/**
* Prepares variables for the UK address element template.
*/
function template_preprocess_localgov_forms_uk_address(array &$variables) {
function template_preprocess_localgov_forms_uk_address(array &$variables): void {

template_preprocess_localgov_forms_uk_address_lookup($variables);
}

/**
* Implements hook_preprocess_hook() for hook_preprocess_webform().
*/
function localgov_forms_preprocess_webform(array &$variables) {
function localgov_forms_preprocess_webform(array &$variables): void {
$variables['#attached']['library'][] = 'localgov_forms/localgov_forms.form_errors';
}
4 changes: 2 additions & 2 deletions localgov_forms.tokens.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use Drupal\webform\Utility\WebformDateHelper;
*
* Token declarations.
*/
function localgov_forms_token_info() {
function localgov_forms_token_info(): array {

return [
'tokens' => [
Expand All @@ -42,7 +42,7 @@ function localgov_forms_token_info() {
*
* @see system_tokens()
*/
function localgov_forms_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
function localgov_forms_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata): array {

$replacements = [];

Expand Down
4 changes: 2 additions & 2 deletions modules/localgov_forms_date/css/date.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
}

.localgov-forms-date div[class*="-day"] {
margin-left: 0em;
flex: 1;
max-width: 100%;
margin-top: 0.5em;
margin-right: 0.5em;
margin-left: 0;
}

.localgov-forms-date div[class*="-month"] {
flex: 2;
margin: 0.5em;
max-width: 100%;
margin: 0.5em;
}

.localgov-forms-date div[class*="-year"] {
Expand Down
6 changes: 3 additions & 3 deletions modules/localgov_forms_date/localgov_forms_date.install
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use Drupal\Component\Serialization\Yaml;
/**
* Adds a UK short date style e.g dd-mm-yyyy.
*/
function localgov_forms_date_update_8001() {
function localgov_forms_date_update_8001(): void {
$config_id = 'core.date_format.localgov_forms_date_short_date';
$config_path = \Drupal::service('extension.list.module')->getPath('localgov_forms_date');
$uk_short_html_date_config = Yaml::decode(file_get_contents($config_path . '/config/install/' . $config_id . '.yml'));
Expand All @@ -20,7 +20,7 @@ function localgov_forms_date_update_8001() {
/**
* Adds a UK short date style e.g dd-mm-yyyy HH:mm:ss.
*/
function localgov_forms_date_update_8002() {
function localgov_forms_date_update_8002(): void {
$config_id = 'core.date_format.localgov_forms_date_datetime';
$config_path = \Drupal::service('extension.list.module')->getPath('localgov_forms_date');
$uk_html_datetime_config = Yaml::decode(file_get_contents($config_path . '/config/install/' . $config_id . '.yml'));
Expand All @@ -30,7 +30,7 @@ function localgov_forms_date_update_8002() {
/**
* Adds a UUID to LocalGov Forms Date formats.
*/
function localgov_forms_date_update_8003() {
function localgov_forms_date_update_8003(): void {
$localgov_date_formats = [
'core.date_format.localgov_forms_date_short_date',
'core.date_format.localgov_forms_date_datetime',
Expand Down
2 changes: 1 addition & 1 deletion modules/localgov_forms_date/localgov_forms_date.module
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Datetime Form preprocess function.
*/
function localgov_forms_date_preprocess_datetime_form(array &$variables) {
function localgov_forms_date_preprocess_datetime_form(array &$variables): void {
// Check that this is a localgov_forms_date form element.
if ($variables['element']['#type'] === 'localgov_forms_date') {
$variables['attributes']['class'][] = 'localgov-forms-date';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private static function restoreUnprocessedDate(array &$element) :void {
* be set in the UI which should take precedence over
* the default error message.
*/
public static function validateDatelist(&$element, FormStateInterface $form_state, &$complete_form) {
public static function validateDatelist(&$element, FormStateInterface $form_state, &$complete_form): void {
$input_exists = FALSE;
$input = NestedArray::getValue($form_state->getValues(), $element['#parents'], $input_exists);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function form(array $form, FormStateInterface $form_state) {
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
public function validateConfigurationForm(array &$form, FormStateInterface $form_state): void {
parent::validateConfigurationForm($form, $form_state);
$values = $form_state->getValues();
$values['date_part_order'] = ['day', 'month', 'year'];
Expand All @@ -77,7 +77,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
/**
* After build handler for Datelist element.
*/
public static function afterBuild(array $element, FormStateInterface $form_state) {
public static function afterBuild(array $element, FormStateInterface $form_state): array {
$element = parent::afterBuild($element, $form_state);

// Set the property of the date of birth elements.
Expand Down Expand Up @@ -112,7 +112,7 @@ public static function afterBuild(array $element, FormStateInterface $form_state
*
* @see Drupal\Webform\Plugin\WebformElement\DateBase::setDefaultValue()
*/
public function setDefaultValue(array &$element) {
public function setDefaultValue(array &$element): void {

$orig_type = $element['#type'];
$element['#type'] = 'datelist';
Expand All @@ -127,7 +127,7 @@ public function setDefaultValue(array &$element) {
* date validation error messages display in
* a UK Style format e.g dd-mm-yyyy.
*/
public static function validateDate(&$element, FormStateInterface $form_state, &$complete_form) {
public static function validateDate(&$element, FormStateInterface $form_state, &$complete_form): void {

// Adds a short date and short date time format.
$localgov_forms_short_date_format = DateFormat::load('localgov_forms_date_short_date')->getPattern();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ package: Testing
core_version_requirement: ^8.8 || ^9 || ^10

dependencies:
- webform:webform
- localgov_forms:localgov_forms_date
- webform:webform
- localgov_forms:localgov_forms_date
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DateWebformElementTest extends KernelTestBase {
/**
* Tests a webform with our date field.
*/
public function testFormSubmission() {
public function testFormSubmission(): void {

$this->passCase();
$this->failCaseWithInvalidDay();
Expand All @@ -28,7 +28,7 @@ public function testFormSubmission() {
/**
* Tests valid date.
*/
protected function passCase() {
protected function passCase(): void {

$form_state = new FormState();
$form_state->setValue('date',
Expand All @@ -42,7 +42,7 @@ protected function passCase() {
/**
* Tests date with invalid day.
*/
protected function failCaseWithInvalidDay() {
protected function failCaseWithInvalidDay(): void {

$form_state = new FormState();
$form_state->setValue('date', ['day' => '1D']);
Expand All @@ -55,7 +55,7 @@ protected function failCaseWithInvalidDay() {
/**
* Tests date with nonnumeric day.
*/
protected function failCaseWithNonNumericDay() {
protected function failCaseWithNonNumericDay(): void {

$form_state = new FormState();
$form_state->setValue('date',
Expand All @@ -69,7 +69,7 @@ protected function failCaseWithNonNumericDay() {
/**
* Tests date with invalid year.
*/
protected function failCaseWithInvalidYear() {
protected function failCaseWithInvalidYear(): void {

$form_state = new FormState();
$form_state->setValue('date',
Expand All @@ -83,7 +83,7 @@ protected function failCaseWithInvalidYear() {
/**
* {@inheritdoc}
*/
protected function setUp() :void {
protected function setUp(): void {

parent::setUp();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use Drupal\webform\WebformSubmissionInterface;
* - DRUPAL_LIBERTY_CREATE_API_USERNAME
* - DRUPAL_LIBERTY_CREATE_API_USER_KEY.
*/
function localgov_forms_example_liberty_create_integration_modules_installed($modules, $is_syncing) {
function localgov_forms_example_liberty_create_integration_modules_installed($modules, $is_syncing): void {

if (!$is_syncing && in_array('token_environment', $modules, TRUE)) {
$token_env_config = Drupal::service('config.factory')->getEditable('token_environment.settings');
Expand Down Expand Up @@ -48,7 +48,7 @@ function localgov_forms_example_liberty_create_integration_modules_installed($mo
* `[webform_submission:values:name:extracted_lastname:clear]` will resolve to
* "Bar".
*/
function localgov_forms_example_liberty_create_integration_tokens_alter(array &$replacements, array $context, BubbleableMetadata $bubbleable_metadata) {
function localgov_forms_example_liberty_create_integration_tokens_alter(array &$replacements, array $context, BubbleableMetadata $bubbleable_metadata): void {

if ($context['type'] === 'webform_submission' && !empty($context['data']['webform_submission'])) {
$firstname_extraction_tokens = array_filter($context['tokens'], fn($token) => strpos($token, ':extracted_firstname'));
Expand Down Expand Up @@ -76,7 +76,7 @@ function localgov_forms_example_liberty_create_integration_tokens_alter(array &$
* @see localgov_forms_example_liberty_create_integration_webform_handler_invoke_post_save_alter()
* @see localgov_forms_example_liberty_create_integration_webform_handler_invoke_post_load_alter()
*/
function localgov_forms_example_liberty_create_integration_token_info_alter(&$token_info) {
function localgov_forms_example_liberty_create_integration_token_info_alter(&$token_info): void {

$token_info['tokens']['webform_submission']['values:?:file_details_for_liberty_create_api'] = [
'name' => t('File detail for Liberty Create API'),
Expand All @@ -87,7 +87,7 @@ function localgov_forms_example_liberty_create_integration_token_info_alter(&$to
/**
* Implements hook_webform_handler_invoke_METHOD_NAME_alter() for hook_webform_handler_invoke_post_save_alter().
*/
function localgov_forms_example_liberty_create_integration_webform_handler_invoke_post_save_alter(WebformHandlerInterface $handler, array &$args) {
function localgov_forms_example_liberty_create_integration_webform_handler_invoke_post_save_alter(WebformHandlerInterface $handler, array &$args): void {

$handler_id = $handler->getHandlerId();
if ($handler_id === 'remote_post' || $handler_id === 'async_remote_post') {
Expand All @@ -100,7 +100,7 @@ function localgov_forms_example_liberty_create_integration_webform_handler_invok
*
* Relevant during Queue processing.
*/
function localgov_forms_example_liberty_create_integration_webform_handler_invoke_post_load_alter(WebformHandlerInterface $handler, array &$args) {
function localgov_forms_example_liberty_create_integration_webform_handler_invoke_post_load_alter(WebformHandlerInterface $handler, array &$args): void {

localgov_forms_example_liberty_create_integration_webform_handler_invoke_post_save_alter($handler, $args);
}
Expand All @@ -121,7 +121,7 @@ function localgov_forms_example_liberty_create_integration_webform_handler_invok
*
* @see Drupal\webform\Plugin\WebformHandler\RemotePostWebformHandler::getRequestData()
*/
function _localgov_forms_example_liberty_create_integration_manage_remote_post_custom_data(WebformHandlerInterface $handler) {
function _localgov_forms_example_liberty_create_integration_manage_remote_post_custom_data(WebformHandlerInterface $handler): void {

$webform_submission = $handler->getWebformSubmission();
if (!$webform_submission instanceof WebformSubmissionInterface) {
Expand Down
19 changes: 19 additions & 0 deletions modules/localgov_forms_feedback_form/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# LocalGov Forms - Feedback Form

## What is it?
This is a small module that creates a feedback for for your LocalGov Drupal website.

It asks a simple question: "Was this page helpful?".

If someone answers "Yes", they are asked if they'd like to share what is good about this page. If they answer "No", they have the opportunity to say how the page can be improved.

## How to use it.
- Install it like any other Drupal module from the "Extend" page.
- Add a block of type "Webform" to your site via the `Admin > Structure > Blocks` page.
- When the form is submitted, results will be stored in the database. They can be accessed by going to `Admin > Structure > Webforms`, clicking on the "LocalGov Forms Feedback Form", and then choosing "Results".

## Considerations
When you enable this module, the form that is created is set to store data in your website's database. This is the default datastore for webforms. However, this may not be where your data protection officer wishes you to store webform submissions. Check with your DPO before deploying this to a live site, or else edit the form configuration to store the data somewhere else - a CRM, an offsite backup, a separate database, etc.

Maintainers:
- Mark Conroy
Loading
Loading