2

I was using the Yii2 DynamicForms extension to create dynamic fields without problems, but today when I run composer update i'm receiving the following error:

Call to undefined method Symfony\Component\DomCrawler\Crawler::rewind()

The error is pointing to the line 201 of /vendor/wbraganca/yii2-dynamicform/DynamicFormWidget.php:

private function removeItems($content)
{
    $document = new \DOMDocument('1.0', \Yii::$app->charset);
    $crawler = new Crawler();
    $crawler->addHTMLContent($content, \Yii::$app->charset);
    $root = $document->appendChild($document->createElement('_root'));
    $crawler->rewind(); // Error here
    $root->appendChild($document->importNode($crawler->current(), true));
    $domxpath = new \DOMXPath($document);
    $crawlerInverse = $domxpath->query(CssSelector::toXPath($this->widgetItem));

    foreach ($crawlerInverse as $elementToRemove) {
        $parent = $elementToRemove->parentNode;
        $parent->removeChild($elementToRemove);
    }

    $crawler->clear();
    $crawler->add($document);
    return $crawler->filter('body')->eq(0)->html();
}

This method was removed from DomCrawler?
How to solve this?

jflizandro
  • 622
  • 1
  • 8
  • 16
  • Why don't you file a bug at the bundle? – Thomas Landauer Dec 04 '15 at 12:49
  • Hi. Because the creator is no longer maintaining the extension. – jflizandro Dec 04 '15 at 12:58
  • You have something else going on. The Crawler is a Symfony component as evidenced by your error message. Crawler extends SplObjectStorage which implements the rewind method. What version of Symfony 2 do you upgrade to? Maybe check vendor/symfony/.../Crawler just to be sure nothing mysterious happened. I suppose you could even check the extension just in case the author did something really crazy like replace the crawler completely. But it all seems quite strange. – Cerad Dec 04 '15 at 13:26
  • Thank you Gerad. The new version of Crawler no longer extends the PHP SplObjectStorage. So I turned to the old version (2.8). – jflizandro Dec 04 '15 at 15:18
  • @jflizandro i am having same problem but its strange that for me extension is working fine in frontend but when i coped same code to backend its throwing this error. How to change the version of crawler? – Mike Ross Jan 08 '16 at 05:24
  • @ Mike Ross You can simply change the version of yii2-dynamicform in composer.json from "*" to "dev-master". – jflizandro Jan 08 '16 at 09:26

1 Answers1

2

An alternative solution is to get the DomCrawler back to version 2.8.

{
    "symfony/dom-crawler": "2.8",
    "symfony/css-selector": "2.8",
    "wbraganca/yii2-dynamicform": "2.0.1"
}

Taken from: https://github.com/wbraganca/yii2-dynamicform/issues/108

Paul Roub
  • 36,322
  • 27
  • 84
  • 93