/** * Find and replace static value with dynamic value from created content * * @param $template, $entity, $view_mode * html string template from component * component entity * view mode of the entity * * @return * render html for entity */ public function findAndReplace($template, $entity, $view_mode = NULL) { $html = $this->getHTMLTemplate($template, $view_mode); $crawler = new HtmlPageCrawler($html); if ($crawler->filterXPath('//*[@data-menu]')->count()) { $crawler = $this->findAndReplaceValueForMenuLinks($crawler); } // get entity view display for entity. $entity_type_id = $entity->getEntityTypeId(); $bundle = $entity->bundle(); if ($entity_type_id == 'component' || $entity_type_id == 'node' && $view_mode == 'full') { $view_mode = 'default'; } $entity_display = \Drupal::entityManager()->getStorage('entity_view_display')->load($entity_type_id . '.' . $bundle . '.' . $view_mode); $html = $this->findAndReplaceValueForFields($crawler, $entity, $entity_display, $view_mode); return $html; }
/** * Filter nodes by XPath expression * * @param string $xpath XPath expression * @return HtmlPageCrawler */ public function filterXPath($xpath) { return $this->crawler->filterXPath($xpath); }