AddToCartButton
1 year ago
Address
5 months ago
BumpLineItem
3 months ago
Button
5 months ago
BuyButton
1 year ago
Card
5 months ago
Cart
5 months ago
CartBumpLineItem
5 months ago
CartCoupon
5 months ago
CartHeader
5 months ago
CartItems
5 months ago
CartMenuButton
5 months ago
CartMessage
5 months ago
CartSubmit
5 months ago
CartSubtotal
5 months ago
Checkbox
3 months ago
CheckoutErrors
5 months ago
CheckoutForm
3 months ago
CollapsibleRow
1 week ago
CollectionPage
5 months ago
Column
5 months ago
Columns
1 week ago
ConditionalForm
5 months ago
Confirmation
5 months ago
Coupon
3 months ago
CustomerDashboardButton
5 months ago
Dashboard
3 months ago
Divider
5 months ago
Donation
5 months ago
DonationAmount
5 months ago
Email
3 months ago
ExpressPayment
3 months ago
FirstName
3 months ago
Form
3 days ago
Heading
5 months ago
Input
5 months ago
InvoiceDetails
5 months ago
InvoiceDueDate
5 months ago
InvoiceMemo
5 months ago
InvoiceNumber
5 months ago
InvoiceReceiptDownload
5 months ago
LastName
3 months ago
LineItemShipping
5 months ago
LineItems
3 days ago
LogoutButton
5 months ago
Name
3 months ago
NameYourPrice
3 months ago
OrderBumps
3 weeks ago
OrderConfirmationCustomer
5 months ago
OrderConfirmationLineItems
5 months ago
Password
5 months ago
Payment
3 months ago
Phone
1 week ago
PriceChoice
5 months ago
PriceSelector
5 months ago
Product
1 week ago
ProductCollection
1 week ago
ProductCollectionDescription
1 week ago
ProductCollectionImage
1 week ago
ProductCollectionTitle
1 week ago
ProductDonation
5 months ago
ProductDonationAmount
5 months ago
ProductDonationAmounts
5 months ago
ProductDonationCustomAmount
5 months ago
ProductDonationPrices
5 months ago
ProductDonationRecurringPrices
5 months ago
ProductItem
1 week ago
ProductItemImage
1 week ago
ProductItemList
1 week ago
ProductItemPrice
1 week ago
ProductItemTitle
1 week ago
Radio
5 months ago
RadioGroup
5 months ago
SessionDetail
5 months ago
ShippingChoices
5 months ago
StoreLogo
3 months ago
Submit
2 months ago
Subtotal
3 months ago
Switch
5 months ago
TaxIdInput
5 months ago
TaxLineItem
3 months ago
Textarea
3 months ago
Total
3 months ago
Totals
3 months ago
TrialLineItem
3 months ago
Upsell
1 week ago
VariantPriceSelector
5 months ago
BaseBlock.php
3 years ago
BlockService.php
4 years ago
BlockServiceProvider.php
6 months ago
CartBlock.php
2 years ago
BlockService.php
60 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCartBlocks\Blocks; |
| 4 | |
| 5 | use SureCartCore\Application\Application; |
| 6 | |
| 7 | /** |
| 8 | * Provide general block-related functionality. |
| 9 | */ |
| 10 | class BlockService { |
| 11 | /** |
| 12 | * View engine. |
| 13 | * |
| 14 | * @var Application |
| 15 | */ |
| 16 | protected $app = null; |
| 17 | |
| 18 | /** |
| 19 | * Constructor. |
| 20 | * |
| 21 | * @param Application $app Application Instance. |
| 22 | */ |
| 23 | public function __construct( Application $app ) { |
| 24 | $this->app = $app; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Render a block using a template |
| 29 | * |
| 30 | * @param string|string[] $views A view or array of views. |
| 31 | * @param array<string, mixed> $context Context to send. |
| 32 | * @return string View html output. |
| 33 | */ |
| 34 | public function render( $views, $context = [] ) { |
| 35 | return apply_filters( 'surecart_block_output', $this->app->views()->make( $views )->with( $context )->toString() ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Find all blocks and nested blocks by name. |
| 40 | * |
| 41 | * @param string $type Block item to filter by. |
| 42 | * @param string $name Block name. |
| 43 | * @param array $blocks Array of blocks. |
| 44 | * @return array |
| 45 | */ |
| 46 | public function filterBy( $type, $name, $blocks ) { |
| 47 | $found_blocks = []; |
| 48 | $blocks = (array) $blocks; |
| 49 | foreach ( $blocks as $block ) { |
| 50 | if ( $name === $block[ $type ] ) { |
| 51 | $found_blocks[] = $block; |
| 52 | } |
| 53 | if ( ! empty( $block['innerBlocks'] ) ) { |
| 54 | $found_blocks = array_merge( $found_blocks, $this->filterBy( $type, $name, $block['innerBlocks'] ) ); |
| 55 | } |
| 56 | } |
| 57 | return $found_blocks; |
| 58 | } |
| 59 | } |
| 60 |