Skip to content

Commit

Permalink
Merge branch 'release/3.0.0' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonTheAdams committed Oct 9, 2023
2 parents 36e3b4b + a34dfd4 commit c13464c
Show file tree
Hide file tree
Showing 19 changed files with 651 additions and 33 deletions.
2 changes: 1 addition & 1 deletion give.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Description: The most robust, flexible, and intuitive way to accept donations on WordPress.
* Author: GiveWP
* Author URI: https://givewp.com/
* Version: 3.0.0-rc.6
* Version: 3.0.0-rc.7
* Requires at least: 6.0
* Requires PHP: 7.2
* Text Domain: give
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<?php

namespace Give\DonationForms\Actions;

use Give\DonationForms\DataTransferObjects\DonateControllerData;
use Give\DonationForms\Listeners\AddRedirectUrlsToGatewayData;
use Give\DonationForms\Listeners\StoreCustomFields;
use Give\DonationForms\Listeners\TemporarilyReplaceLegacySuccessPageUri;
use Give\DonationForms\Listeners\UpdateDonationLevelId;
use Give\Donations\Models\Donation;
use Give\Framework\Exceptions\Primitives\Exception;
use Give\Framework\FieldsAPI\Exceptions\NameCollisionException;
use Give\Subscriptions\Models\Subscription;

class DispatchDonateControllerDonationCreatedListeners
{
/**
* @since 3.0.0
* @throws NameCollisionException
* @throws NameCollisionException|Exception
*/
public function __invoke(DonateControllerData $formData, Donation $donation, ?Subscription $subscription)
{
(new StoreCustomFields())($formData->getDonationForm(), $donation, $subscription, $formData->getCustomFields());
(new TemporarilyReplaceLegacySuccessPageUri())($formData, $donation);
(new AddRedirectUrlsToGatewayData())($formData, $donation);
(new UpdateDonationLevelId())($formData->getDonationForm(), $donation);
}
}
42 changes: 42 additions & 0 deletions src/DonationForms/Listeners/UpdateDonationLevelId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Give\DonationForms\Listeners;

use Give\DonationForms\Models\DonationForm;
use Give\Donations\Models\Donation;
use Give\Framework\Exceptions\Primitives\Exception;
use Give\Framework\FieldsAPI\Amount;
use Give\Framework\FieldsAPI\Exceptions\NameCollisionException;

class UpdateDonationLevelId
{
/**
* if the intended donation amount matches a donation level from the amount block settings,
* this will update the donation level ID meta with the level array key,
* which is used in the donation details screen.
*
* @since 3.0.0-rc.7
*
* @throws NameCollisionException|Exception
*/
public function __invoke(DonationForm $donationForm, Donation $donation)
{
/** @var Amount $amountField */
$amountField = $donationForm->schema()->getNodeByName('amount');

if (!$amountField) {
return;
}

$donationLevel = array_search(
(float)$donation->intendedAmount()->formatToDecimal(),
$amountField->getLevels(),
true
);

if ($donationLevel !== false) {
$donation->levelId = (string)$donationLevel;
$donation->save();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ public function render(): string

$this->enqueueGlobalStyles($primaryColor, $secondaryColor);

$this->enqueueFormScripts(
$this->donation->formId,
$formDesignId
);
$this->enqueueFormScripts($formDesignId);

ob_start();
wp_print_styles();
Expand Down Expand Up @@ -166,7 +163,7 @@ public function enqueueGlobalStyles(string $primaryColor, string $secondaryColor
*
* @return void
*/
private function enqueueFormScripts(int $formId, string $formDesignId)
private function enqueueFormScripts(?string $formDesignId)
{
$handle = 'givewp-donation-form-registrars';
wp_enqueue_script(
Expand Down Expand Up @@ -196,7 +193,7 @@ private function enqueueFormScripts(int $formId, string $formDesignId)
$formDesignRegistrar = give(FormDesignRegistrar::class);

// silently fail if design is missing for some reason
if ($formDesignRegistrar->hasDesign($formDesignId)) {
if (!empty($formDesignId) && $formDesignRegistrar->hasDesign($formDesignId)) {
$design = $formDesignRegistrar->getDesign($formDesignId);

if ($design->css()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
import {__} from '@wordpress/i18n';

import {InnerBlocks, InspectorControls, RichText} from '@wordpress/block-editor';

import {InnerBlocks, InspectorControls, RichText, store as blockEditorStore} from '@wordpress/block-editor';
import {PanelBody, PanelRow, TextareaControl, TextControl} from '@wordpress/components';

import {useSelect} from '@wordpress/data';
import {BlockEditProps} from '@wordpress/blocks';
import {getBlockRegistrar} from "@givewp/form-builder/common/getWindowData";

import BaseEmptyBlockInserter from './EmptyBlockInserter';
import './styles.scss';

export default function Edit(props: BlockEditProps<any>) {
const {
attributes: {title, description},
setAttributes,
clientId,
} = props;

const isParentOfSelectedBlock = useSelect<any>(
(select) => select('core/block-editor').hasSelectedInnerBlock(props.clientId, true),
[]
const hasChildBlocks = useSelect(
(select) => {
// @ts-ignore
const {getBlockOrder} = select(blockEditorStore);

return getBlockOrder(clientId).length > 0;
},
[clientId]
);
const isSelectedOrIsInnerBlockSelected = props.isSelected || isParentOfSelectedBlock;

const EmptyBlockInserter = () => {
return (
<div className="give-section__empty-block-inserter">
{/* @ts-ignore */}
<BaseEmptyBlockInserter rootClientId={clientId} />
</div>
);
};

return (
<>
Expand All @@ -45,11 +60,12 @@ export default function Edit(props: BlockEditProps<any>) {
</header>

<InnerBlocks
allowedBlocks={
getBlockRegistrar().getAll().filter((block) => block.name !== 'givewp/section').map((block) => block.name)
}
allowedBlocks={getBlockRegistrar()
.getAll()
.filter((block) => block.name !== 'givewp/section')
.map((block) => block.name)}
template={props.attributes.innerBlocksTemplate}
renderAppender={InnerBlocks.DefaultBlockAppender}
renderAppender={hasChildBlocks ? InnerBlocks.DefaultBlockAppender : EmptyBlockInserter}
prioritizedInserterBlocks={[
'givewp/text',
'givewp/paragraph',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {Button, Tooltip} from '@wordpress/components';
import {Inserter} from '@wordpress/block-editor';
import {__, _x} from '@wordpress/i18n';

/**
* The inserter used in sections for dragging and dropping blocks or clicking to add a block.
*/
export default function EmptyBlockInserter({rootClientId}) {
return (
<Inserter
position="bottom center"
rootClientId={rootClientId}
__experimentalIsQuick
className="give-section__empty-block-inserter"
renderToggle={({onToggle, disabled, isOpen}) => {
const label = _x('Add block', 'Generic label for block inserter button', 'give');

return (
<Tooltip text={label}>
<Button
className="block-editor-button-block-appender"
onClick={onToggle}
aria-haspopup="true" // attribute wants a true value, not a boolean
aria-expanded={isOpen}
disabled={disabled}
label={label}
>
{__('Drag a block here or click to add a block', 'give')}
</Button>
</Tooltip>
);
}}
isAppender
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.give-section {
&__empty-block-inserter {
width: 100%;

.block-editor-inserter {
width: 100%;
}

.block-editor-button-block-appender {
width: 100%;
box-shadow: none;
border: dashed var(--givewp-gray-60) 2px;
padding: 3rem 0 !important;
font-size: var(--givewp-font-weight-paragraph-lg);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {WPComponent} from '@wordpress/element';
import {Component} from '@wordpress/element';
import type {
EmailNotification,
FormDesign,
Expand All @@ -14,7 +14,7 @@ type GoalTypeOption = {
value: string;
label: string;
description: string;
}
};

/**
* @since 3.0.0
Expand Down Expand Up @@ -57,7 +57,7 @@ declare const window: {
form: {
blocks: BlockRegistrar;
components: {
[key: string]: WPComponent;
[key: string]: Component;
};
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
}

&:not(.is-selected) {
.block-list-appender {
.block-editor-default-block-appender {
display: none;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ export default function normalizeFieldSettings(settings: FieldSettingsSupport |
displayInAdmin: getSupportSetting('displayInAdmin', true, true),
displayInReceipt: getSupportSetting('displayInReceipt', true, true),
defaultValue: getSupportSetting('defaultValue', false, ''),
emailTag: getSupportSetting('emailTag', false, ''),
emailTag: getSupportSetting('emailTag', true, ''),
};
}
16 changes: 16 additions & 0 deletions src/FormMigration/FormMetaDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,20 @@ public function getOfflineAttributes(): array
'offlineDonationInstructions' => $instructions,
];
}

/**
* @since 3.0.0-rc.7
*/
public function getFormFields(): array
{
return array_filter((array)give_get_meta($this->form->id, 'give-form-fields', true));
}

/**
* @since 3.0.0-rc.7
*/
public function getFormFieldsPlacement(): string
{
return give_get_meta($this->form->id, '_give_ffm_placement', true);
}
}
1 change: 1 addition & 0 deletions src/FormMigration/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function register()
Steps\DonationGoal::class,
Steps\TermsAndConditions::class,
Steps\FormGrid::class,
Steps\FormFieldManager::class,
Steps\OfflineDonations::class,
Steps\PaymentGateways::class,
Steps\EmailSettings::class,
Expand Down
2 changes: 1 addition & 1 deletion src/FormMigration/Steps/DonationOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function process()
}

/**
* @unreleased
* @since 3.0.0-rc.7
*/
private function roundAmount($amount): float
{
Expand Down
Loading

0 comments on commit c13464c

Please sign in to comment.