* Gets entity metadata and all fields from the form
*
* @param array $layout
+ * The root element of the layout, in shallow/deep format.
* @return array
+ * A list of entities, keyed by named.
+ * Ex: $entities['spouse']['type'] = 'Contact';
*/
public static function getEntities($layout) {
$entities = array_column(self::getTags($layout, 'af-entity'), NULL, 'name');
/**
* Returns all tags with a certain tag name, e.g. 'af-entity'
*
- * @param array $collection
+ * @param array $element
* @param string $tagName
* @return array
*/
- public static function getTags($collection, $tagName) {
+ public static function getTags($element, $tagName) {
$results = [];
- if ($collection['#tag'] == $tagName) {
- $results[] = self::getProps($collection);
+ if ($element['#tag'] == $tagName) {
+ $results[] = self::getProps($element);
}
- foreach ($collection['#children'] ?? [] as $child) {
+ foreach ($element['#children'] ?? [] as $child) {
$results = array_merge($results, self::getTags($child, $tagName));
}
return $results;
/**
* @param array $layout
+ * The root element of the layout, in shallow/deep format.
* @param array $entities
+ * A list of entities, keyed by named.
+ * This will be updated to include 'fields'.
+ * Ex: $entities['spouse']['type'] = 'Contact';
*/
protected static function getFields($layout, &$entities) {
foreach ($layout['#children'] as $child) {
* Returns all the real properties of a collection,
* filtering out any array keys that start with a hashtag
*
- * @param array $collection
+ * @param array $element
* @return array
*/
- public static function getProps($collection) {
- return array_filter($collection, function($key) {
+ public static function getProps($element) {
+ return array_filter($element, function($key) {
return substr($key, 0, 1) !== '#';
}, ARRAY_FILTER_USE_KEY);
}