BlockContainerInterface.php
2 years ago
BlockInterface.php
2 years ago
BlockTemplateInterface.php
2 years ago
ContainerInterface.php
2 years ago
BlockInterface.php
156 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Admin\BlockTemplates; |
| 4 | |
| 5 | /** |
| 6 | * Interface for block configuration used to specify blocks in BlockTemplate. |
| 7 | */ |
| 8 | interface BlockInterface { |
| 9 | /** |
| 10 | * Key for the block name in the block configuration. |
| 11 | */ |
| 12 | public const NAME_KEY = 'blockName'; |
| 13 | |
| 14 | /** |
| 15 | * Key for the block ID in the block configuration. |
| 16 | */ |
| 17 | public const ID_KEY = 'id'; |
| 18 | |
| 19 | /** |
| 20 | * Key for the internal order in the block configuration. |
| 21 | */ |
| 22 | public const ORDER_KEY = 'order'; |
| 23 | |
| 24 | /** |
| 25 | * Key for the block attributes in the block configuration. |
| 26 | */ |
| 27 | public const ATTRIBUTES_KEY = 'attributes'; |
| 28 | |
| 29 | /** |
| 30 | * Key for the block hide conditions in the block configuration. |
| 31 | */ |
| 32 | public const HIDE_CONDITIONS_KEY = 'hideConditions'; |
| 33 | |
| 34 | /** |
| 35 | * Key for the block disable conditions in the block configuration. |
| 36 | */ |
| 37 | public const DISABLE_CONDITIONS_KEY = 'disableConditions'; |
| 38 | |
| 39 | /** |
| 40 | * Get the block name. |
| 41 | */ |
| 42 | public function get_name(): string; |
| 43 | |
| 44 | /** |
| 45 | * Get the block ID. |
| 46 | */ |
| 47 | public function get_id(): string; |
| 48 | |
| 49 | /** |
| 50 | * Get the block order. |
| 51 | */ |
| 52 | public function get_order(): int; |
| 53 | |
| 54 | /** |
| 55 | * Set the block order. |
| 56 | * |
| 57 | * @param int $order The block order. |
| 58 | */ |
| 59 | public function set_order( int $order ); |
| 60 | |
| 61 | /** |
| 62 | * Get the block attributes. |
| 63 | */ |
| 64 | public function get_attributes(): array; |
| 65 | |
| 66 | /** |
| 67 | * Set the block attributes. |
| 68 | * |
| 69 | * @param array $attributes The block attributes. |
| 70 | */ |
| 71 | public function set_attributes( array $attributes ); |
| 72 | |
| 73 | /** |
| 74 | * Set a block attribute value without replacing the entire attributes object. |
| 75 | * |
| 76 | * @param string $key The attribute key. |
| 77 | * @param mixed $value The attribute value. |
| 78 | */ |
| 79 | public function set_attribute( string $key, $value ); |
| 80 | |
| 81 | /** |
| 82 | * Get the parent container that the block belongs to. |
| 83 | */ |
| 84 | public function &get_parent(): ContainerInterface; |
| 85 | |
| 86 | /** |
| 87 | * Get the root template that the block belongs to. |
| 88 | */ |
| 89 | public function &get_root_template(): BlockTemplateInterface; |
| 90 | |
| 91 | /** |
| 92 | * Remove the block from its parent. |
| 93 | */ |
| 94 | public function remove(); |
| 95 | |
| 96 | /** |
| 97 | * Check if the block is detached from its parent or root template. |
| 98 | * |
| 99 | * @return bool True if the block is detached from its parent or root template. |
| 100 | */ |
| 101 | public function is_detached(): bool; |
| 102 | |
| 103 | /** |
| 104 | * Add a hide condition to the block. |
| 105 | * |
| 106 | * The hide condition is a JavaScript-like expression that will be evaluated on the client to determine if the block should be hidden. |
| 107 | * See [@woocommerce/expression-evaluation](https://github.com/woocommerce/woocommerce/blob/trunk/packages/js/expression-evaluation/README.md) for more details. |
| 108 | * |
| 109 | * @param string $expression An expression, which if true, will hide the block. |
| 110 | * @return string The key of the hide condition, which can be used to remove the hide condition. |
| 111 | */ |
| 112 | public function add_hide_condition( string $expression ): string; |
| 113 | |
| 114 | /** |
| 115 | * Remove a hide condition from the block. |
| 116 | * |
| 117 | * @param string $key The key of the hide condition to remove. |
| 118 | */ |
| 119 | public function remove_hide_condition( string $key ); |
| 120 | |
| 121 | /** |
| 122 | * Get the hide conditions of the block. |
| 123 | */ |
| 124 | public function get_hide_conditions(): array; |
| 125 | |
| 126 | /** |
| 127 | * Add a disable condition to the block. |
| 128 | * |
| 129 | * The disable condition is a JavaScript-like expression that will be evaluated on the client to determine if the block should be disabled. |
| 130 | * See [@woocommerce/expression-evaluation](https://github.com/woocommerce/woocommerce/blob/trunk/packages/js/expression-evaluation/README.md) for more details. |
| 131 | * |
| 132 | * @param string $expression An expression, which if true, will disable the block. |
| 133 | * @return string The key of the disable condition, which can be used to remove the disable condition. |
| 134 | */ |
| 135 | public function add_disable_condition( string $expression ): string; |
| 136 | |
| 137 | /** |
| 138 | * Remove a disable condition from the block. |
| 139 | * |
| 140 | * @param string $key The key of the disable condition to remove. |
| 141 | */ |
| 142 | public function remove_disable_condition( string $key ); |
| 143 | |
| 144 | /** |
| 145 | * Get the disable conditions of the block. |
| 146 | */ |
| 147 | public function get_disable_conditions(): array; |
| 148 | |
| 149 | /** |
| 150 | * Get the block configuration as a formatted template. |
| 151 | * |
| 152 | * @return array The block configuration as a formatted template. |
| 153 | */ |
| 154 | public function get_formatted_template(): array; |
| 155 | } |
| 156 |