You are here

public function MappingFieldsHelper::getMappedFields in Gutenberg 8.2

Returns all mapping fields (recursively) on the template.

Parameters

array $template: Template to check.

Return value

array The list of mapping fields.

File

src/MappingFieldsHelper.php, line 184

Class

MappingFieldsHelper
Handles the mappingFields configuration manipulation.

Namespace

Drupal\gutenberg

Code

public function getMappedFields(array $template = NULL) {
  $result = [];
  if (empty($template)) {
    return [];
  }
  foreach ($template as $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])) {
      $result = array_merge($result, $this
        ->getMappedFields($block[2]));
    }
  }
  return $result;
}