PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Form / LegacyConsumer / UniqueIdAttributeGenerator.php

UniqueIdAttributeGenerator.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/Form/LegacyConsumer/UniqueIdAttributeGenerator.php

57 lines 1018 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Form\LegacyConsumer;
4
5 /**
6 * @since 2.14.0
7 */
8 class UniqueIdAttributeGenerator
9 {
10 /**
11 * @var array
12 */
13 private $formCounter = [];
14
15 /**
16 * @since 2.14.0
17 *
18 * @param int $formId
19 */
20 private function increaseCounter($formId)
21 {
22 if ( ! isset($this->formCounter[$formId])) {
23 $this->formCounter[$formId] = 1;
24
25 return;
26 }
27
28 $this->formCounter[$formId]++;
29 }
30
31 /**
32 * @since 2.14.0
33 *
34 * @param int $formId
35 * @param string $fieldName
36 *
37 * @return string
38 */
39 public function getId($formId, $fieldName)
40 {
41 $id = "give-$fieldName-$formId-{$this->getCounterValue( $formId )}";
42 $this->increaseCounter($formId);
43
44 return $id;
45 }
46
47 /**
48 * @since 2.14.0
49 *
50 * @param int $formId
51 */
52 private function getCounterValue($formId)
53 {
54 return ! empty($this->formCounter[$formId]) ? $this->formCounter[$formId] : 1;
55 }
56 }
57