You are here

protected function FormAssemblyEntityViewBuilder::attachedHead in FormAssembly 8

Helper method to take raw header from FormAssembly and prep for render.

Parameters

string $rawHeadMarkup: The extracted head hmtl.

Return value

array Array prepared for #attached.

1 call to FormAssemblyEntityViewBuilder::attachedHead()
FormAssemblyEntityViewBuilder::splitMarkup in src/Entity/FormAssemblyEntityViewBuilder.php
Helper method to parse the markup into head and body.

File

src/Entity/FormAssemblyEntityViewBuilder.php, line 143

Class

FormAssemblyEntityViewBuilder
Prepares the FormAssembly entity for display.

Namespace

Drupal\formassembly\Entity

Code

protected function attachedHead($rawHeadMarkup) {
  $attached = [];
  $crawler = new Crawler();
  $crawler
    ->addContent($rawHeadMarkup);
  libxml_use_internal_errors(TRUE);
  foreach ($crawler
    ->filter('script, link[type="text/css"]') as $index => $node) {
    switch ($node->tagName) {
      case 'script':
        if ($node
          ->hasAttribute('src')) {
          $attached[] = [
            '#type' => 'fa_form_external_js',
            '#src' => $node
              ->getAttribute('src'),
            '#weight' => $index,
          ];
        }
        else {
          $attached[] = [
            '#type' => 'fa_form_inline_js',
            '#value' => $node->textContent,
            '#weight' => $index,
          ];
        }
        break;
      case 'link':
        $attached[] = [
          '#type' => 'fa_form_external_css',
          '#rel' => $node
            ->getAttribute('rel'),
          '#href' => $node
            ->getAttribute('href'),
          '#weight' => $index,
        ];
        break;
    }
  }
  return $attached;
}