protected function FormAssemblyEntityViewBuilder::splitMarkup in FormAssembly 8
Helper method to parse the markup into head and body.
Parameters
string $markup: The markup returned from formassembly.
Return value
array An array with 'head' and 'body' for expansion via list().
1 call to FormAssemblyEntityViewBuilder::splitMarkup()
- FormAssemblyEntityViewBuilder::view in src/
Entity/ FormAssemblyEntityViewBuilder.php - Builds the render array for the provided entity.
File
- src/
Entity/ FormAssemblyEntityViewBuilder.php, line 106
Class
- FormAssemblyEntityViewBuilder
- Prepares the FormAssembly entity for display.
Namespace
Drupal\formassembly\EntityCode
protected function splitMarkup($markup) {
// Now, per FormAssembly support, we'll try to find a <div> element with
// the class name "wFormContainer".
$crawler = new Crawler();
$crawler
->addContent($markup);
// Symfony's crawler will get the html inside the filtered tag.
$innerBody = $crawler
->filter('.wFormContainer')
->html();
// If we found the body wrapper div:
if (!empty($innerBody)) {
// Grab the raw html of the header.
// Just in case there's another wrapper, we get the HTML before the first
// <div>, which is probably the same <div> we just found.
$headMarkup = substr($markup, 0, stripos($markup, '<div'));
$headMarkup = trim($headMarkup);
// Process and extract attachable items from this raw markup.
$attached = $this
->attachedHead($headMarkup);
// Re-assemble the form wrapper filtered above.
$bodyMarkup = "<div class=\"wFormContainer\">{$innerBody}</div>";
}
else {
// Fall back to using the entire markup in the body.
$attached = [];
$bodyMarkup = trim($markup);
}
return [
$attached,
$bodyMarkup,
];
}