diff --git a/Blueprints/src/BlueprintForm.php b/Blueprints/src/BlueprintForm.php index 832fdfc..1709530 100644 --- a/Blueprints/src/BlueprintForm.php +++ b/Blueprints/src/BlueprintForm.php @@ -133,6 +133,7 @@ public function load($extends = null) } // Import blueprints. + $this->deepImport($this->items); $this->deepInit($this->items); return $this; @@ -360,6 +361,37 @@ protected function deepMerge(array $a, array $b) return $a; } + + /** + * @param array $items + * @param array $path + * @return string + */ + protected function deepImport(array &$items, $path = []) + { + do { + $run_again = false; + $field = end($path) === 'fields'; + foreach ($items as $key => &$item) { + if ($field && isset($item['type'])) { + $item['name'] = $key; + } + // Handle import@ + if (strpos($key, '@') !== false && preg_match('/^(@*)?import(@\d*)?$/', $key)) { + unset($items[$key]); + $this->doImport($item, $path); + $run_again = true; + break; + } elseif (\is_array($item)) { + // Recursively initialize form. + $newPath = array_merge($path, [$key]); + $this->deepImport($item, $newPath); + } + } + unset($item); + } while ($run_again); + } + /** * @param array $items * @param array $path @@ -391,10 +423,6 @@ protected function deepInit(array &$items, $path = []) return null; } break; - case 'import': - unset($items[$key]); - $this->doImport($item, $path); - break; case 'ordering': $ordering = $item; unset($items[$key]); @@ -408,7 +436,7 @@ protected function deepInit(array &$items, $path = []) $newPath = array_merge($path, [$key]); $location = $this->deepInit($item, $newPath); - if ($location) { + if (null !== $location) { $order[$key] = $location; } elseif ($location === null) { unset($items[$key]);