AddToCartButton
2 years ago
Address
3 years ago
BumpLineItem
3 years ago
Button
3 years ago
BuyButton
2 years ago
Card
3 years ago
Cart
3 years ago
CartBumpLineItem
3 years ago
CartCoupon
3 years ago
CartHeader
3 years ago
CartItems
3 years ago
CartMenuButton
3 years ago
CartMessage
3 years ago
CartSubmit
3 years ago
CartSubtotal
3 years ago
Checkbox
3 years ago
CheckoutErrors
3 years ago
CheckoutForm
3 years ago
CollapsibleRow
3 years ago
CollectionPage
2 years ago
Column
2 years ago
Columns
2 years ago
ConditionalForm
3 years ago
Confirmation
3 years ago
Coupon
3 years ago
CustomerDashboardButton
3 years ago
Dashboard
2 years ago
Divider
3 years ago
Donation
3 years ago
DonationAmount
3 years ago
Email
3 years ago
ExpressPayment
3 years ago
FirstName
3 years ago
Form
2 years ago
Heading
3 years ago
Input
3 years ago
LastName
3 years ago
LineItemShipping
3 years ago
LineItems
3 years ago
LogoutButton
3 years ago
Name
3 years ago
NameYourPrice
3 years ago
OrderBumps
2 years ago
OrderConfirmationCustomer
3 years ago
OrderConfirmationLineItems
3 years ago
Password
2 years ago
Payment
2 years ago
Phone
3 years ago
PriceChoice
2 years ago
PriceSelector
2 years ago
Product
2 years ago
ProductCollection
2 years ago
ProductCollectionDescription
2 years ago
ProductCollectionImage
2 years ago
ProductCollectionTitle
2 years ago
ProductItem
2 years ago
ProductItemImage
2 years ago
ProductItemList
2 years ago
ProductItemPrice
2 years ago
ProductItemTitle
2 years ago
Radio
3 years ago
RadioGroup
3 years ago
SessionDetail
3 years ago
ShippingChoices
3 years ago
StoreLogo
3 years ago
Submit
2 years ago
Subtotal
3 years ago
Switch
3 years ago
TaxIdInput
3 years ago
TaxLineItem
3 years ago
Textarea
3 years ago
Total
3 years ago
Totals
2 years ago
BaseBlock.php
3 years ago
BlockService.php
3 years ago
BlockServiceProvider.php
3 years ago
CartBlock.php
3 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 |