public function apply($transformer, $context, $node) { $interactive = Interactive::create(); if (Type::is($context, InstantArticle::getClassName())) { $instant_article = $context; } elseif ($transformer->getInstantArticle()) { $instant_article = $transformer->getInstantArticle(); $context->disableEmptyValidation(); $context = Paragraph::create(); $context->disableEmptyValidation(); } else { $transformer->addWarning(new NoRootInstantArticleFoundWarning(null, $node)); return $context; } // Builds the interactive $iframe = $this->getProperty(self::PROPERTY_IFRAME, $node); $url = $this->getProperty(self::PROPERTY_URL, $node); if ($iframe) { $interactive->withHTML($iframe); } if ($url) { $interactive->withSource($url); } if ($iframe || $url) { $instant_article->addChild($interactive); if ($instant_article !== $context) { $instant_article->addChild($context); } } else { $transformer->addWarning(new InvalidSelector(self::PROPERTY_IFRAME, $instant_article, $node, $this)); } if ($this->getProperty(self::PROPERTY_WIDTH_COLUMN_WIDTH, $node)) { $interactive->withMargin(Interactive::COLUMN_WIDTH); } else { $interactive->withMargin(Interactive::NO_MARGIN); } $width = $this->getProperty(self::PROPERTY_WIDTH, $node); if ($width) { $interactive->withWidth($width); } $height = $this->getProperty(self::PROPERTY_HEIGHT, $node); if ($height) { $interactive->withHeight($height); } $suppress_warnings = $transformer->suppress_warnings; $transformer->suppress_warnings = true; $transformer->transform($interactive, $node); $transformer->suppress_warnings = $suppress_warnings; return $context; }
public function apply($transformer, $instant_article, $node) { $interactive = Interactive::create(); // Builds the interactive $iframe = $this->getProperty(self::PROPERTY_IFRAME, $node); $url = $this->getProperty(self::PROPERTY_URL, $node); if ($iframe) { $interactive->withHTML($iframe); } if ($url) { $interactive->withSource($url); } if ($iframe || $url) { $instant_article->addChild($interactive); } else { $transformer->addWarning(new InvalidSelector(self::PROPERTY_IFRAME, $instant_article, $node, $this)); } if ($this->getProperty(self::PROPERTY_WIDTH_COLUMN_WIDTH, $node)) { $interactive->withMargin(Interactive::COLUMN_WIDTH); } else { $interactive->withMargin(Interactive::NO_MARGIN); } $width = $this->getProperty(self::PROPERTY_WIDTH, $node); if ($width) { $interactive->withWidth($width); } $height = $this->getProperty(self::PROPERTY_HEIGHT, $node); if ($height) { $interactive->withHeight($height); } $suppress_warnings = $transformer->suppress_warnings; $transformer->suppress_warnings = true; $transformer->transform($interactive, $node); $transformer->suppress_warnings = $suppress_warnings; return $instant_article; }
public function getContextClass() { return [Map::getClassName(), Image::getClassName(), Interactive::getClassName(), Slideshow::getClassName(), SocialEmbed::getClassName(), Video::getClassName()]; }
/** * Adds new child elements to the front of this InstantArticle * * @param Element to be added to this Article. * * @return $this */ public function unshiftChild($child) { Type::enforce($child, [Ad::getClassName(), Analytics::getClassName(), AnimatedGIF::getClassName(), Audio::getClassName(), Blockquote::getClassName(), Image::getClassName(), H1::getClassName(), H2::getClassName(), Interactive::getClassName(), ListElement::getClassName(), Map::getClassName(), Paragraph::getClassName(), Pullquote::getClassName(), RelatedArticles::getClassName(), Slideshow::getClassName(), SocialEmbed::getClassName(), Video::getClassName()]); array_unshift($this->children, $child); return $this; }
public function testRenderInline() { $inline = '<h1>Some custom code</h1>' . '<script>alert("test & more test");</script>'; $interactive = Interactive::create()->withHTML($inline)->withMargin(Interactive::NO_MARGIN); $expected = '<figure class="op-interactive">' . '<iframe class="no-margin">' . '<h1>Some custom code</h1>' . '<script>alert("test & more test");</script>' . '</iframe>' . '</figure>'; $rendered = $interactive->render(); $this->assertEquals($expected, $rendered); $this->assertTrue($interactive->isValid()); }