You are here

function _gutenberg_get_mapping_fields in Gutenberg 8

Gets all mapping fields on the template (recursive).

2 calls to _gutenberg_get_mapping_fields()
gutenberg_entity_presave in ./gutenberg.module
Implements hook_entity_presave().
gutenberg_form_node_form_alter in ./gutenberg.module
Implements hook_form_node_form_alter().

File

./gutenberg.module, line 786
Provides integration with the Gutenberg editor.

Code

function _gutenberg_get_mapping_fields($template, &$result = []) {
  if (empty($template)) {
    return [];
  }
  foreach ($template as $key => $block) {
    if (isset($block[1]) && isset($block[1]->mappingFields)) {
      foreach ($block[1]->mappingFields as $field) {
        $item = [];
        $item['field'] = $field->field;
        if (isset($field->property)) {
          $item['property'] = $field->property;
        }
        if (isset($field->attribute)) {
          $item['attribute'] = $field->attribute;
        }
        $result[] = $item;
      }
    }
    if (isset($block[2])) {
      _gutenberg_get_mapping_fields($block[2], $result);
    }
  }
  return $result;
}