Skip to content

Commit

Permalink
Merge branch 'epic/givewp-3.0' into feature/email-save-and-close
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaHungDinh committed Aug 23, 2023
2 parents 04957b8 + 79f6960 commit f118deb
Show file tree
Hide file tree
Showing 91 changed files with 810 additions and 715 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/php-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ on:
jobs:
build:
uses: impress-org/givewp-github-actions/.github/workflows/php-compatibility.yml@master
with:
test_versions: "[ '7.2', '8.0' ]"
9 changes: 2 additions & 7 deletions .github/workflows/wordpress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
php: [ 7.0, 7.4, 8.0 ]
php: [ 7.2, 7.4, 8.0 ]
mysql: [ 'mysql:5.6', 'mysql:8.0' ]
wordpress: [ '5.0', latest ]
exclude:
- php: 7.4
wordpress: '5.0'
- php: 8.0
wordpress: '5.0'
wordpress: [ '6.0', latest ]

services:
mysql56:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"wp-cli/wp-cli-bundle": "^2.5",
"yoast/phpunit-polyfills": "^1.0",
"wordpress/wordpress": "dev-trunk",
"squizlabs/php_codesniffer": "^3.5"
"squizlabs/php_codesniffer": "^3.5",
"php-stubs/wp-cli-stubs": "^2.8"
},
"keywords": [
"wordpress",
Expand Down
90 changes: 89 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 3 additions & 11 deletions give.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
use Give\Framework\PaymentGateways\PaymentGatewayRegister;
use Give\Framework\ValidationRules\ValidationRulesServiceProvider;
use Give\Framework\WordPressShims\ServiceProvider as WordPressShimsServiceProvider;
use Give\Helpers\Language;
use Give\LegacySubscriptions\ServiceProvider as LegacySubscriptionsServiceProvider;
use Give\License\LicenseServiceProvider;
use Give\Log\LogServiceProvider;
Expand Down Expand Up @@ -361,24 +362,15 @@ private function setup_constants()
/**
* Loads the plugin language files.
*
* @unreleased Use Language class
* @since 1.0
* @access public
*
* @return void
*/
public function load_textdomain()
{
// Set filter for Give's languages directory
$give_lang_dir = dirname(plugin_basename(GIVE_PLUGIN_FILE)) . '/languages/';
$give_lang_dir = apply_filters('give_languages_directory', $give_lang_dir);

// Traditional WordPress plugin locale filter.
$locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
$locale = apply_filters('plugin_locale', $locale, 'give');

unload_textdomain('give');
load_textdomain('give', WP_LANG_DIR . '/give/give-' . $locale . '.mo');
load_plugin_textdomain('give', false, $give_lang_dir);
Language::load();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module '*.svg';
declare module '*.module.css';
declare module '*.module.scss';

declare module 'window.givewp.form.blocks';
// this makes the wp or window.wp global variable available in the eyes of TypeScript
declare var wp;
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ parameters:
- vendor/vendor-prefixed/
scanFiles:
- vendor/wordpress/wordpress/src/wp-includes/compat.php
- vendor/php-stubs/wp-cli-stubs/wp-cli-stubs.php
- vendor/php-stubs/wp-cli-stubs/wp-cli-commands-stubs.php
- vendor/php-stubs/wp-cli-stubs/wp-cli-i18n-stubs.php
excludePaths:
analyse:
- src/LegacySubscriptions/includes/ # Scan but do not analyse
Expand Down
35 changes: 28 additions & 7 deletions src/DonationForms/Actions/ConvertDonationFormBlocksToFieldsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use Give\Framework\FieldsAPI\Section;
use Give\Framework\FieldsAPI\Text;
use Give\Framework\FieldsAPI\Textarea;
use Give\Helpers\Hooks;
use WP_User;

/**
Expand All @@ -42,13 +41,18 @@ class ConvertDonationFormBlocksToFieldsApi
* @var string
*/
protected $currency;
/**
* @var array {blockClientId: {node: Node, block: BlockModel}}
*/
protected $blockNodeRelationships = [];

/**
* @since 3.0.0
*
* @return array {DonationForm, array {blockClientId: {node: Node, block: BlockModel}}}
* @throws TypeNotSupported|NameCollisionException
*/
public function __invoke(BlockCollection $blocks, int $formId): DonationForm
public function __invoke(BlockCollection $blocks, int $formId): array
{
$this->formId = $formId;
$this->currency = give_get_currency($formId);
Expand Down Expand Up @@ -78,17 +82,21 @@ static function ($node) {
$form->append($section);
}

return $form;
return [$form, $this->blockNodeRelationships];
}

/**
* @since 3.0.0
*/
protected function convertTopLevelBlockToSection(BlockModel $block, int $blockIndex): Section
{
return Section::make($block->getShortName() . '-' . $blockIndex)
$node = Section::make($block->getShortName() . '-' . $blockIndex)
->label($block->getAttribute('title'))
->description($block->getAttribute('description'));

$this->mapBlockToNodeRelationships($block, $node);

return $node;
}

/**
Expand All @@ -104,9 +112,9 @@ protected function convertInnerBlockToNode(BlockModel $block, int $blockIndex)
$node = $this->createNodeFromBlockWithUniqueAttributes($block, $blockIndex);

if ($node instanceof Node) {
$node = $this->mapGenericBlockAttributesToNode($node, $block);
$node = $this->mapGenericBlockAttributesToNode($block, $node);

Hooks::doAction('givewp_donation_form_block_converted_to_node', $node, $block);
$this->mapBlockToNodeRelationships($block, $node);

return $node;
}
Expand Down Expand Up @@ -356,7 +364,7 @@ protected function createNodeFromConsentBlock(BlockModel $block, int $blockIndex
/**
* @since 3.0.0
*/
protected function mapGenericBlockAttributesToNode(Node $node, BlockModel $block): Node
protected function mapGenericBlockAttributesToNode(BlockModel $block, Node $node): Node
{
if ('field' === $node->getNodeType()) {
// Label
Expand Down Expand Up @@ -385,4 +393,17 @@ protected function mapGenericBlockAttributesToNode(Node $node, BlockModel $block

return $node;
}

/**
* @since 3.0.0
*
* @return void
*/
private function mapBlockToNodeRelationships(BlockModel $block, Node $node)
{
$this->blockNodeRelationships[$block->clientId] = [
'block' => $block,
'node' => $node,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private function getViewUrl(DonationForm $donationForm, string $embedId): string
*
* @since 3.0.0
*/
private function loadEmbedScript()
protected function loadEmbedScript()
{
(new EnqueueScript(
'givewp-donation-form-embed',
Expand Down
4 changes: 2 additions & 2 deletions src/DonationForms/DataTransferObjects/AuthenticationData.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class AuthenticationData
*
* @since 3.0.0
*/
public static function fromRequest(array $request): AuthenticationData
public static function fromRequest(array $request): self
{
$self = new static();
$self = new self();

$self->login = $request['login'];
$self->password = $request['password'];
Expand Down
4 changes: 2 additions & 2 deletions src/DonationForms/DataTransferObjects/DonateFormRouteData.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class DonateFormRouteData implements Arrayable
*
* @since 3.0.0
*/
public static function fromRequest(array $requestData): DonateFormRouteData
public static function fromRequest(array $requestData): self
{
$self = new static();
$self = new self();
$self->formId = (int)$requestData['formId'];
$self->gatewayId = $requestData['gatewayId'];
$self->originUrl = $requestData['originUrl'];
Expand Down
4 changes: 2 additions & 2 deletions src/DonationForms/DataTransferObjects/DonateRouteData.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class DonateRouteData
*
* @since 3.0.0
*/
public static function fromRequest(array $request): DonateRouteData
public static function fromRequest(array $request): self
{
$self = new static();
$self = new self();

$self->routeSignature = $request['givewp-route-signature'];
$self->routeSignatureId = $request['givewp-route-signature-id'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DonationConfirmationReceiptViewRouteData
*
* @since 3.0.0
*/
public static function fromRequest(array $request): DonationConfirmationReceiptViewRouteData
public static function fromRequest(array $request): self
{
$self = new self();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DonationFormPreviewRouteData
*/
public static function fromRequest(array $request): self
{
$self = new static();
$self = new self();

$self->formId = (int)$request['form-id'];
$self->formSettings = !empty($request['form-settings']) ? FormSettings::fromJson(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class DonationFormQueryData
*
* @return DonationFormQueryData
*/
public static function fromObject($queryObject): DonationFormQueryData
public static function fromObject($queryObject): self
{
$self = new static();
$self = new self();
$self->id = (int)$queryObject->id;
$self->title = $queryObject->title;
$self->createdAt = Temporal::toDateTime($queryObject->createdAt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class DonationFormViewRouteData
*
* @since 3.0.0
*/
public static function fromRequest(array $request): DonationFormViewRouteData
public static function fromRequest(array $request): self
{
$self = new static();
$self = new self();

$self->formId = (int)$request['form-id'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LegacyPurchaseFormData
* @param array{donation: Donation, donor: Donation} $array
* @return LegacyPurchaseFormData
*/
public static function fromArray(array $array): LegacyPurchaseFormData
public static function fromArray(array $array): self
{
$self = new self();

Expand Down
4 changes: 2 additions & 2 deletions src/DonationForms/DataTransferObjects/UserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class UserData
*
* @since 3.0.0
*/
public static function fromUser(\WP_User $user): UserData
public static function fromUser(\WP_User $user): self
{
$self = new static();
$self = new self();

$self->firstName = $user->user_firstname;
$self->lastName = $user->user_lastname;
Expand Down
Loading

0 comments on commit f118deb

Please sign in to comment.