Ejemplo n.º 1
0
 /**
  * Returns the media inclusion tag contained in the given template.
  *
  * @param TemplateTag $template The template to search the media file tag in.
  *
  * @return UmgtMediaInclusionTag The media file inclusion tag.
  *
  * @author Christian Achatz
  * @version
  * Version 0.1, 05.06.2010<br />
  */
 protected function &getIcon(TemplateTag $template)
 {
     foreach ($template->getChildren() as &$child) {
         if ($child instanceof UmgtMediaInclusionTag) {
             return $child;
         }
     }
     return null;
 }
Ejemplo n.º 2
0
 public function transform()
 {
     /* @var $condSet UserDependentContentConditionSet */
     $condSet = $this->getServiceObject(UserDependentContentConditionSet::class);
     if ($condSet->conditionMatches($this->getContext(), $this->getAttribute('condition'), $this->getAttribute('options'))) {
         return parent::transform();
     }
     return '';
 }
 public function testConditionalPlaceHolders()
 {
     $template = new TemplateTag();
     $template->setContent('<cond:placeholder name="foo">${content}</cond:placeholder>|' . '<cond:placeholder name="bar">${content}</cond:placeholder>');
     $template->onParseTime();
     $template->onAfterAppend();
     $template->setPlaceHolders(['foo' => '1', 'bar' => '2']);
     $this->assertEquals('1|2', $template->transformTemplate());
     $template->clear();
     $this->assertEquals('|', $template->transformTemplate());
 }
Ejemplo n.º 4
0
 public function transform()
 {
     // Re-map desired model to content data attribute to ease expression and template definition.
     // Most likely, the model will be a parent document's data attribute.
     $model = ExpressionEvaluator::evaluate($this->getParentObject(), $this->getRequiredAttribute('content-mapping'));
     $this->setData('content', $model);
     // Calculate result to match against condition
     $result = ExpressionEvaluator::evaluate($this, $this->getRequiredAttribute('expression'));
     // The condition defines whether or not the content is displayed. Can be overwritten
     // by the "condition" attribute according to the TemplateCondition capabilities.
     $condition = $this->getAttribute('condition', 'notEmpty()');
     if (!TemplateCondition::applies($condition, $result)) {
         return '';
     }
     // Mark template for creating output directly as condition matches.
     $this->transformOnPlace();
     return parent::transform();
 }
Ejemplo n.º 5
0
 /**
  * Test DOM node relocation including static content and transformation.
  */
 public function testComplexUseCse()
 {
     $tag = new TemplateTag();
     $tag->setContent('<core:appendnode includestatic="true" namespace="' . __NAMESPACE__ . '\\templates" template="include_complex" />');
     $tag->onParseTime();
     $tag->onAfterAppend();
     $expected = 'static text';
     // fill template with place holder
     /* @var $template TemplateTag */
     $template = $tag->getChildNode('name', 'test', Template::class);
     $template->setPlaceHolder('test', $expected);
     $template->transformOnPlace();
     $tag->setPlaceHolder('test', $expected);
     $actual = $tag->transformTemplate();
     // 6 = 4 static + 1 template place holder + 1 place holder
     $this->assertTrue(substr_count($actual, $expected) === 6);
 }
    /**
     * @return TemplateTag
     */
    private function getTemplate()
    {
        $doc = new TemplateTag();
        $doc->setContent('<cond:template content-mapping="teaser" expression="content->displayIt()" condition="true()">
   <h2 class="...">${content->getHeadline()}</h2>
   <cond:template content-mapping="content" expression="content->getSubHeadline()" condition="notEmpty()">
      <h3 class="...">${content->getSubHeadline()}</h3>
   </cond:template>
   <p>${content->getText()}</p>
   <cond:template content-mapping="content->getMoreLink()" expression="content" condition="notEmpty()">
      <a href="${content->getUrl()}">${content->getLabel()}</a>
   </cond:template>
</cond:template>');
        $doc->onParseTime();
        $doc->onAfterAppend();
        $doc->transformOnPlace();
        return $doc;
    }
 /**
  * @return DomNode
  */
 protected function getDocument()
 {
     $doc = new TemplateTag();
     $doc->setContent('<cond:placeholder name="name" condition="empty()">
      <p>No entry available.</p>
   </cond:placeholder>
   <cond:placeholder name="name" condition="notEmpty()">
      <p>Name: ${content}</p>
   </cond:placeholder>');
     $doc->onParseTime();
     $doc->onAfterAppend();
     $doc->transformOnPlace();
     return $doc;
 }
Ejemplo n.º 8
0
 /**
  * Complex use case within a template. Checks whether place holder in place holder works.
  */
 public function testLanguageLabel4()
 {
     $node = new TemplateTag();
     $node->setContent('<h2><html:getstring id="foo" ' . 'namespace="' . self::TEST_VENDOR . '" ' . 'config="' . self::CONFIG_FILE_NAME . '"' . ' entry="complex" /></h2>');
     $node->onParseTime();
     $node->onAfterAppend();
     $node->getChildNode('id', 'foo', LanguageLabelTag::class)->setPlaceHolder('place-holder', 'test');
     $this->assertEquals('<h2>This is a test!</h2>', $node->transformTemplate());
 }
Ejemplo n.º 9
0
 public function testExtractExpressionTags4()
 {
     $property = new ReflectionProperty(Document::class, 'knownExpressions');
     $property->setAccessible(true);
     // inject special conditions that apply for this
     $original = $property->getValue(null);
     $property->setValue(null, []);
     // setup template
     $doc = new TemplateTag();
     $doc->setContent('${expression}');
     $doc->onParseTime();
     try {
         $doc->onAfterAppend();
         $this->fail('knownExpressions() should throw a ParserException in case no expression applies!');
     } catch (ParserException $e) {
         // this is expected behavior
     }
     // reset to original setup
     $property->setValue(null, $original);
 }
Ejemplo n.º 10
0
 /**
  * Checks, if a place holder exists within the given template.
  *
  * @param TemplateTag $template The instance of the template to check.
  * @param string $name The name of the place holder.
  *
  * @return bool True if yes, false otherwise.
  *
  * @author Christian Schäfer
  * @version
  * Version 0.1, 11.03.2007<br />
  * Version 0.2, 23.04.2009 (Corrected PHP4 style object access)<br />
  * Version 0.3, 02.07.2011 (Renaming to fit the APF naming convention)<br />
  * Version 0.4, 13.08.2014 (ID#231: Allow custom form tag while still using this method to obtain an instance)<br />
  */
 protected function templatePlaceHolderExists(TemplateTag &$template, $name)
 {
     try {
         $template->getChildNode('name', $name, PlaceHolder::class);
         return true;
     } catch (InvalidArgumentException $e) {
         return false;
     }
 }