Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
/**
* Implements hook_install().
*/
function localgov_forms_feedback_form_install() {
function localgov_forms_feedback_form_install(): void {
\Drupal::messenger()->addStatus(t('You have installed the LocalGov Forms Feedback Form. This form stores the form submissions in the database. Make sure you have checked this is okay with your data protection officer, or else change the form settings to store the data somewhere else.'));
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
/**
* Implements hook_form_FORM_ID_alter().
*/
function localgov_forms_feedback_form_form_webform_submission_localgov_forms_feedback_form_add_form_alter(&$form, $form_state, $form_id) {
function localgov_forms_feedback_form_form_webform_submission_localgov_forms_feedback_form_add_form_alter(&$form, $form_state, $form_id): void {
$form['#attached']['library'][] = 'localgov_forms_feedback_form/localgov_forms_feedback_form';
}
4 changes: 2 additions & 2 deletions modules/localgov_forms_lts/localgov_forms_lts.install
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function localgov_forms_lts_install($is_syncing): void {
*
* Checks for the presence of the localgov_forms_lts database.
*/
function localgov_forms_lts_requirements($phase) {
function localgov_forms_lts_requirements($phase): array {

$requirements = [
'localgov_forms_lts' => [
Expand Down Expand Up @@ -79,7 +79,7 @@ function _localgov_forms_lts_get_webform_submission_storage_schema(): array {
/**
* Public wrapper over protected method.
*/
public function getEntitySchemaWrapper(ContentEntityTypeInterface $entity_type) {
public function getEntitySchemaWrapper(ContentEntityTypeInterface $entity_type): array {

return parent::getEntitySchema($entity_type);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/localgov_forms_lts/localgov_forms_lts.module
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function localgov_forms_lts_has_db(): bool {
/**
* Implements hook_cron().
*/
function localgov_forms_lts_cron() {
function localgov_forms_lts_cron(): void {

localgov_forms_lts_copy_recently_added_n_updated_subs();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class WebformSubmissionLtsViewController extends WebformSubmissionViewController
*
* Loads the Webform submission from Long term storage.
*/
public function viewFromLts(int $webform_sid, $view_mode = 'default', $langcode = NULL) {
public function viewFromLts(int $webform_sid, $view_mode = 'default', $langcode = NULL): array {

$webform_sub = $this->ltsStorage->load($webform_sid);
return parent::view($webform_sub, $view_mode, $langcode);
Expand All @@ -29,7 +29,7 @@ public function viewFromLts(int $webform_sid, $view_mode = 'default', $langcode
*
* Loads the Webform submission from Long term storage.
*/
public function noteViewFromLts(int $webform_sid, $view_mode = 'default', $langcode = NULL) {
public function noteViewFromLts(int $webform_sid, $view_mode = 'default', $langcode = NULL): array {

$webform_sub = $this->ltsStorage->load($webform_sid);
return [
Expand All @@ -42,7 +42,7 @@ public function noteViewFromLts(int $webform_sid, $view_mode = 'default', $langc
*
* Loads the Webform submission from Long term storage.
*/
public function titleFromLts(int $webform_sid, $duplicate = FALSE) {
public function titleFromLts(int $webform_sid, $duplicate = FALSE): string {

$webform_sub = $this->ltsStorage->load($webform_sid);
return parent::title($webform_sub, $duplicate);
Expand All @@ -51,7 +51,7 @@ public function titleFromLts(int $webform_sid, $duplicate = FALSE) {
/**
* Factory.
*/
public static function create(ContainerInterface $container) {
public static function create(ContainerInterface $container): static {

$instance = parent::create($container);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class LocalgovFormsLtsCommands extends DrushCommands {
#[CLI\Command(name: 'localgov-forms-lts:copy', aliases: ['forms-lts-copy'])]
#[CLI\Option(name: 'force', description: 'Ignore copy disablement config and copy anyway. Useful immediately after module installation.')]
#[CLI\Usage(name: 'localgov-forms-lts:copy', description: 'Copies all existing Webform submissions.')]
public function copy($options = ['force' => FALSE]) {
public function copy($options = ['force' => FALSE]): void {

if (!localgov_forms_lts_has_db()) {
$this->logger->error(dt('The LocalGov Forms LTS database must exist for this Drush command to function.'));
Expand Down Expand Up @@ -71,7 +71,7 @@ public function copy($options = ['force' => FALSE]) {
*
* Copies a fixed number of Webform submissions to LTS.
*/
public static function copyInBatch(?PluginInspectionInterface $pii_redactor_plugin, LoggerInterface $drupal_logger, &$context) {
public static function copyInBatch(?PluginInspectionInterface $pii_redactor_plugin, LoggerInterface $drupal_logger, &$context): void {

$lts_copy_obj = LtsCopy::create(\Drupal::getContainer(), $pii_redactor_plugin);
$copy_results = $lts_copy_obj->copy();
Expand Down
2 changes: 1 addition & 1 deletion modules/localgov_forms_lts/src/Form/LTSSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct(protected ?PluginManagerInterface $optionalPIIRedact
* If the PII redactor plugin manager is available, passes it to the
* constructor.
*/
public static function create(ContainerInterface $container) {
public static function create(ContainerInterface $container): static {

$pii_redactor_plugin_manager = $container->has(Constants::PII_REDACTOR_PLUGIN_MANAGER) ? $container->get(Constants::PII_REDACTOR_PLUGIN_MANAGER) : NULL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function getFromPersistentCache(?array &$ids = NULL) {
/**
* See above.
*/
protected function setPersistentCache($entities) {}
protected function setPersistentCache($entities): void {}

/**
* Customizes cache Ids for LTS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
public static function create(ContainerInterface $container): static {

$webform_sub_def = $container->get('entity_type.manager')->getDefinition('webform_submission');
return self::createInstance($container, $webform_sub_def);
Expand Down
Loading
Loading