Skip to content

Commit

Permalink
S2FRMS-40 - PHPCS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stankut committed Jun 19, 2024
1 parent 196f8e1 commit 43f795a
Show file tree
Hide file tree
Showing 25 changed files with 75 additions and 63 deletions.
2 changes: 1 addition & 1 deletion modules/os2forms_nemid/src/Element/MitidChildAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function processMitidChildAddress(&$element, FormStateInterface $f
}

/**
* Webform element validation handler for #type 'os2forms_mitid_child_address'.
* Webform element validation handler for 'os2forms_mitid_child_address'.
*/
public static function validateMitidChildAddress(&$element, FormStateInterface $form_state, &$complete_form) {
// Here you can add custom validation logic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function processMitidChildApartmentNr(&$element, FormStateInterfac
}

/**
* Webform element validation handler for #type 'os2forms_mitid_child_apartmentNr'.
* Webform element validation handler 'os2forms_mitid_child_apartmentNr'.
*/
public static function validateMitidChildApartmentNr(&$element, FormStateInterface $form_state, &$complete_form) {
// Here you can add custom validation logic.
Expand Down
2 changes: 1 addition & 1 deletion modules/os2forms_nemid/src/Element/MitidChildCoaddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function processMitidChildCoaddress(&$element, FormStateInterface
}

/**
* Webform element validation handler for #type 'os2forms_mitid_child_coaddress'.
* Webform element validation handler for 'os2forms_mitid_child_coaddress'.
*/
public static function validateMitidChildCoaddress(&$element, FormStateInterface $form_state, &$complete_form) {
// Here you can add custom validation logic.
Expand Down
2 changes: 1 addition & 1 deletion modules/os2forms_nemid/src/Element/MitidChildHouseNr.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function processMitidChildHouseNr(&$element, FormStateInterface $f
}

/**
* Webform element validation handler for #type 'os2forms_mitid_child_house_nr'.
* Webform element validation handler for 'os2forms_mitid_child_house_nr'.
*/
public static function validateMitidChildHouseNr(&$element, FormStateInterface $form_state, &$complete_form) {
// Here you can add custom validation logic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function processMitidChildKommunekode(&$element, FormStateInterfac
}

/**
* Webform element validation handler for #type 'os2forms_mitid_child_kommunekode'.
* Webform element validation handler for 'os2forms_mitid_child_kommunekode'.
*/
public static function validateMitidChildKommunekode(&$element, FormStateInterface $form_state, &$complete_form) {
// Here you can add custom validation logic.
Expand Down
17 changes: 10 additions & 7 deletions modules/os2forms_nemid/src/Element/MitidChildOtherGuardian.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ public function getInfo() {
$class = static::class;

$parentInfo = parent::getInfo() + [
'#element_validate' => [
[$class, 'validateMitidChildOtherGuardian'],
],
];
'#element_validate' => [
[$class, 'validateMitidChildOtherGuardian'],
],
];

// Adding custom #pre_render.
$parentInfo['#pre_render'] = [
[$class, 'preRenderMitidChildOtherGuardian']
[$class, 'preRenderMitidChildOtherGuardian'],
];

return $parentInfo;
}

/**
* Webform element validation handler for #type 'os2forms_mitid_child_other_guardian'.
* Webform element validation handler 'os2forms_mitid_child_other_guardian'.
*/
public static function validateMitidChildOtherGuardian(&$element, FormStateInterface $form_state, &$complete_form) {
// Here you can add custom validation logic.
Expand All @@ -49,7 +49,10 @@ public static function validateMitidChildOtherGuardian(&$element, FormStateInter
*/
public static function preRenderMitidChildOtherGuardian($element) {
$element = parent::preRenderHidden($element);
static::setAttributes($element, ['os2forms-mitid-child-other-guardian', 'js-form-type-os2forms-mitid-child-other-guardian']);
static::setAttributes($element, [
'os2forms-mitid-child-other-guardian',
'js-form-type-os2forms-mitid-child-other-guardian',
]);

return $element;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function processMitidChildPostalCode(&$element, FormStateInterface
}

/**
* Webform element validation handler for #type 'os2forms_mitid_child_postal_code'.
* Webform element validation handler for 'os2forms_mitid_child_postal_code'.
*/
public static function validateMitidChildPostalCode(&$element, FormStateInterface $form_state, &$complete_form) {
// Here you can add custom validation logic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,25 @@
use Drupal\os2forms_nemid\Service\FormsHelper;

/**
* Provides a children select ajax behaviour for MitidChildrenSelect and MitidChildrenRadios.
* Provides a children select ajax behaviour.
*
* User in MitidChildrenSelect and MitidChildrenRadios.
*/
class MitidChildrenSelectAjaxBehaviour {

/**
* Ajax function to update fields after child select.
*
* @param array $form
* Form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Form state.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* Ajax response
*
* @throws \Drupal\Component\Plugin\Exception\PluginException
*/
public static function mitidChildrenSelectAjax(array &$form, FormStateInterface $form_state) {
$response = new AjaxResponse();

Expand Down Expand Up @@ -47,46 +62,57 @@ public static function mitidChildrenSelectAjax(array &$form, FormStateInterface
$element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getName() : 'Navne- og adressebeskyttet';
$response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-name', $element));
break;

case 'os2forms_mitid_child_cpr':
$element['#value'] = $cprLookupResult->getCpr();
$response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-cpr', $element));
break;

case 'os2forms_mitid_child_address':
$element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getAddress() : 'Navne- og adressebeskyttet';
$response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-address', $element));
break;

case 'os2forms_mitid_child_apartment_nr':
$element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getApartmentNr() : 'Navne- og adressebeskyttet';
$response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-apartment-nr', $element));
break;

case 'os2forms_mitid_child_city':
$element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getCity() : 'Navne- og adressebeskyttet';
$response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-city', $element));
break;

case 'os2forms_mitid_child_coaddress':
$element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getCoName() : 'Navne- og adressebeskyttet';
$response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-coaddress', $element));
break;

case 'os2forms_mitid_child_floor':
$element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getFloor() : 'Navne- og adressebeskyttet';
$response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-floor', $element));
break;

case 'os2forms_mitid_child_house_nr':
$element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getHouseNr() : 'Navne- og adressebeskyttet';
$response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-house-nr', $element));
break;

case 'os2forms_mitid_child_kommunekode':
$element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getMunicipalityCode() : 'Navne- og adressebeskyttet';
$response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-kommunekode', $element));
break;

case 'os2forms_mitid_child_postal_code':
$element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getPostalCode() : 'Navne- og adressebeskyttet';
$response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-postal-code', $element));
break;

case 'os2forms_mitid_child_street':
$element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getStreet() : 'Navne- og adressebeskyttet';
$response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-street', $element));
break;

case 'os2forms_mitid_child_other_guardian':
$otherGuardianCpr = NULL;
$allGuardians = $cprLookupResult->getGuardians();
Expand Down Expand Up @@ -115,4 +141,5 @@ public static function mitidChildrenSelectAjax(array &$form, FormStateInterface

return $response;
}

}
18 changes: 9 additions & 9 deletions modules/os2forms_nemid/src/Element/NemidChildrenRadios.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Drupal\os2forms_nemid\Element;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\Radios;

/**
Expand All @@ -23,14 +22,15 @@ class NemidChildrenRadios extends Radios {
*/
public function getInfo() {
return parent::getInfo() + [
'#ajax' => [
'callback' => [MitidChildrenSelectAjaxBehaviour::class, 'mitidChildrenSelectAjax'],
'event' => 'change',
'progress' => [
'type' => 'throbber',
'message' => $this->t('Please wait...'),
],
'#ajax' => [
'callback' => [MitidChildrenSelectAjaxBehaviour::class, 'mitidChildrenSelectAjax'],
'event' => 'change',
'progress' => [
'type' => 'throbber',
'message' => $this->t('Please wait...'),
],
];
],
];
}

}
16 changes: 8 additions & 8 deletions modules/os2forms_nemid/src/Element/NemidChildrenSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ class NemidChildrenSelect extends Select {
*/
public function getInfo() {
return parent::getInfo() + [
'#ajax' => [
'callback' => [MitidChildrenSelectAjaxBehaviour::class, 'mitidChildrenSelectAjax'],
'event' => 'change',
'progress' => [
'type' => 'throbber',
'message' => $this->t('Please wait...'),
],
'#ajax' => [
'callback' => [MitidChildrenSelectAjaxBehaviour::class, 'mitidChildrenSelectAjax'],
'event' => 'change',
'progress' => [
'type' => 'throbber',
'message' => $this->t('Please wait...'),
],
];
],
];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Drupal\os2forms_nemid\Plugin\WebformElement;

use Drupal\webform\Plugin\WebformElementBase;

/**
* Provides a 'os2forms_mitid_child_address' element.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Drupal\os2forms_nemid\Plugin\WebformElement;

use Drupal\webform\Plugin\WebformElementBase;

/**
* Provides a 'os2forms_mitid_child_apartment_nr' element.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Drupal\os2forms_nemid\Plugin\WebformElement;

use Drupal\webform\Plugin\WebformElementBase;

/**
* Provides a 'os2forms_mitid_child_city' element.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Drupal\os2forms_nemid\Plugin\WebformElement;

use Drupal\webform\Plugin\WebformElementBase;

/**
* Provides a 'os2forms_mitid_child_coadress' element.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Drupal\os2forms_nemid\Plugin\WebformElement;

use Drupal\webform\Plugin\WebformElementBase;

/**
* Provides a 'os2forms_mitid_child_cpr' element.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public function getDefaultProperties() {
// @see \Drupal\webform\Plugin\WebformElementBase::getDefaultProperties
// @see \Drupal\webform\Plugin\WebformElementBase::getDefaultBaseProperties
$properties = parent::getDefaultProperties() + [
'multiple' => '',
'size' => '',
'minlength' => '',
'maxlength' => '',
'placeholder' => '',
'readonly' => '',
];
'multiple' => '',
'size' => '',
'minlength' => '',
'maxlength' => '',
'placeholder' => '',
'readonly' => '',
];

return $properties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Drupal\os2forms_nemid\Plugin\WebformElement;

use Drupal\webform\Plugin\WebformElementBase;

/**
* Provides a 'os2forms_mitid_child_floor' element.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Drupal\os2forms_nemid\Plugin\WebformElement;

use Drupal\webform\Plugin\WebformElementBase;

/**
* Provides a 'os2forms_mitid_child_house_nr' element.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Drupal\os2forms_nemid\Plugin\WebformElement;

use Drupal\webform\Plugin\WebformElementBase;

/**
* Provides a 'os2forms_mitid_child_kommunekode' element.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Drupal\os2forms_nemid\Plugin\WebformElement;

use Drupal\webform\Plugin\WebformElementBase;

/**
* Provides a 'os2forms_mitid_child_name' element.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
*/
class MitidChildOtherGuardian extends Hidden {

/**
* {@inheritdoc}
*/
public function getValue(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
if (isset($options['email']) || isset($options['pdf'])) {
return '';
}

return parent::getValue($element, $webform_submission, $options);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Drupal\os2forms_nemid\Plugin\WebformElement;

use Drupal\webform\Plugin\WebformElementBase;

/**
* Provides a 'os2forms_mitid_child_postal_code' element.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Drupal\os2forms_nemid\Plugin\WebformElement;

use Drupal\webform\Plugin\WebformElementBase;

/**
* Provides a 'os2forms_mitid_child_street' element.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f
}

/**
* Appends name and address protected text, if person has name/address protection.
* Appends name/address protected text, if person has name/address protection.
*
* @param CprLookupResult $cprLookupResult
* @param \Drupal\os2web_datalookup\LookupResult\CprLookupResult $cprLookupResult
* Initialized CprLooupResult.
*
* @return string
Expand Down
2 changes: 1 addition & 1 deletion modules/os2forms_nemid/src/Service/FormsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function retrieveCprLookupResult(FormStateInterface $form_state) {
* CPRLookupResult or NULL.
*/
public static function retrieveCachedCprLookupResult(FormStateInterface $form_state) {
/** @var CprLookupResult $cprLookupResult */
/** @var \Drupal\os2web_datalookup\LookupResult\CprLookupResult $cprLookupResult */
$cprLookupResult = NULL;

// Trying to fetch person data from cache.
Expand Down

0 comments on commit 43f795a

Please sign in to comment.