1 | <?php |
||
36 | class BlockRegistrationManager extends BlockManager |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * @var BlockAssetManagerCollection $block_asset_manager_collection |
||
41 | */ |
||
42 | protected $block_asset_manager_collection; |
||
43 | |||
44 | |||
45 | /** |
||
46 | * BlockRegistrationManager constructor. |
||
47 | * |
||
48 | * @param BlockAssetManagerCollection $block_asset_manager_collection |
||
49 | * @param BlockCollection $blocks |
||
50 | * @param RequestInterface $request |
||
51 | */ |
||
52 | public function __construct( |
||
53 | BlockAssetManagerCollection $block_asset_manager_collection, |
||
54 | BlockCollection $blocks, |
||
55 | RequestInterface $request |
||
56 | ) { |
||
57 | $this->block_asset_manager_collection = $block_asset_manager_collection; |
||
58 | parent::__construct($blocks, $request); |
||
59 | } |
||
60 | |||
61 | |||
62 | /** |
||
63 | * Returns the name of a hookpoint to be used to call initialize() |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | public function initHook() |
||
71 | |||
72 | |||
73 | /** |
||
74 | * Perform any early setup required for block editors to functions |
||
75 | * |
||
76 | * @return void |
||
77 | * @throws Exception |
||
78 | */ |
||
79 | public function initialize() |
||
80 | { |
||
81 | $this->initializeBlocks(); |
||
82 | add_action('AHEE__EE_System__initialize', array($this, 'registerBlocks')); |
||
83 | } |
||
84 | |||
85 | |||
86 | /** |
||
87 | * @return CollectionInterface|BlockInterface[] |
||
88 | * @throws ReflectionException |
||
89 | * @throws InvalidArgumentException |
||
90 | * @throws EE_Error |
||
91 | * @throws InvalidClassException |
||
92 | * @throws InvalidDataTypeException |
||
93 | * @throws InvalidEntityException |
||
94 | * @throws InvalidFilePathException |
||
95 | * @throws InvalidIdentifierException |
||
96 | * @throws InvalidInterfaceException |
||
97 | */ |
||
98 | protected function populateBlockCollection() |
||
99 | { |
||
100 | $loader = new CollectionLoader( |
||
101 | new CollectionDetails( |
||
102 | // collection name |
||
103 | 'shortcodes', |
||
104 | // collection interface |
||
105 | 'EventEspresso\core\domain\entities\editor\BlockInterface', |
||
106 | // FQCNs for classes to add (all classes within each namespace will be loaded) |
||
107 | apply_filters( |
||
108 | 'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs', |
||
109 | array( |
||
110 | // 'EventEspresso\core\domain\entities\editor\blocks\common', |
||
111 | // 'EventEspresso\core\domain\entities\editor\blocks\editor', |
||
112 | // 'EventEspresso\core\domain\entities\editor\blocks\widgets', |
||
113 | ) |
||
114 | ), |
||
115 | // filepaths to classes to add |
||
116 | array(), |
||
117 | // file mask to use if parsing folder for files to add |
||
118 | '', |
||
119 | // what to use as identifier for collection entities |
||
120 | // using CLASS NAME prevents duplicates (works like a singleton) |
||
121 | CollectionDetails::ID_CLASS_NAME |
||
122 | ), |
||
123 | $this->blocks |
||
124 | ); |
||
125 | return $loader->getCollection(); |
||
126 | } |
||
127 | |||
128 | |||
129 | /** |
||
130 | * populates the BlockCollection and calls initialize() on all installed blocks |
||
131 | * |
||
132 | * @return void |
||
133 | * @throws Exception |
||
134 | */ |
||
135 | public function initializeBlocks() |
||
155 | |||
156 | |||
157 | /** |
||
158 | * calls registerBlock() and load assets for all installed blocks |
||
159 | * |
||
160 | * @return void |
||
161 | * @throws Exception |
||
162 | */ |
||
163 | public function registerBlocks() |
||
164 | { |
||
165 | try { |
||
166 | // cycle thru block loader folders |
||
167 | foreach ($this->blocks as $block) { |
||
168 | // perform any setup required for the block |
||
169 | $block_type = $block->registerBlock(); |
||
170 | if (! $block_type instanceof WP_Block_Type) { |
||
|
|||
171 | throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
||
172 | } |
||
173 | do_action( |
||
174 | 'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered', |
||
175 | $block, |
||
176 | $block_type |
||
177 | ); |
||
178 | } |
||
179 | } catch (Exception $exception) { |
||
180 | new ExceptionStackTraceDisplay($exception); |
||
181 | } |
||
182 | } |
||
183 | |||
184 | |||
185 | /** |
||
186 | * @since $VID:$ |
||
187 | */ |
||
188 | public function enqueueAssets() |
||
192 | } |
||
193 |