You are here

public static function PatternPreview::processFields in UI Patterns 8

Process fields.

Parameters

array $element: Render array.

Return value

array Render array.

Overrides Pattern::processFields

File

src/Element/PatternPreview.php, line 24

Class

PatternPreview
Renders a pattern preview element.

Namespace

Drupal\ui_patterns\Element

Code

public static function processFields(array $element) {
  $definition = UiPatterns::getPatternDefinition($element['#id']);
  $fields = [];
  foreach ($definition
    ->getFields() as $field) {
    $preview = $field
      ->getPreview();

    // Some fields are used as Twig array keys and don't need escaping.
    if ($field
      ->getEscape()) {

      // The examples are not user submitted and are safe markup.
      $preview = self::getPreviewMarkup($preview);
    }
    $fields[$field
      ->getName()] = $preview;
  }
  if (isset($definition['additional']['attributes'])) {
    $fields['attributes'] = $definition['extra']['attributes'];
  }
  $element['#fields'] = $fields;
  return parent::processFields($element);
}