fabarea / rss_display

TYPO3 CMS extension for fetching a RSS / Atom Feed and display its content on the Frontend
Other
12 stars 25 forks source link

Broken Fluid ViewHelpers #36

Closed stephan-tittel closed 5 years ago

stephan-tittel commented 5 years ago

Since Typo3 9.0, method arguments for ViewHelper's render method have been deprecated.

This currently breaks TagsViewHelper and TagViewHelper so that both throw RuntimeExceptions (when using Typo3 in strict mode only?). Proposed fix:

diff --git a/Classes/ViewHelpers/Item/TagViewHelper.php b/Classes/ViewHelpers/Item/TagViewHelper.php
index 9e62a20..a261604 100644
--- a/Classes/ViewHelpers/Item/TagViewHelper.php
+++ b/Classes/ViewHelpers/Item/TagViewHelper.php
@@ -17,6 +17,12 @@ use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
  */
 class TagViewHelper extends AbstractViewHelper
 {
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('namespace', 'string', 'RSS element namespace', true);
+        $this->registerArgument('tag', 'string', 'RSS element name', true);
+    }

     /**
      * Retrieve the SimplePie item from the context and return its "tag".
@@ -27,12 +33,12 @@ class TagViewHelper extends AbstractViewHelper
      * @return string
      * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException
      */
-    public function render($namespace, $tag)
+    public function render()
     {

         /** @var SimplePie_Item $item */
         $item = $this->templateVariableContainer->get('item');
-        $values = $item->get_item_tags($namespace, $tag);
+        $values = $item->get_item_tags($this->arguments['namespace'], $this->arguments['tag']);

         $result = '';
         if (is_array($values)) {

and

diff --git a/Classes/ViewHelpers/Item/TagsViewHelper.php b/Classes/ViewHelpers/Item/TagsViewHelper.php
index 756d6dc..debc34e 100644
--- a/Classes/ViewHelpers/Item/TagsViewHelper.php
+++ b/Classes/ViewHelpers/Item/TagsViewHelper.php
@@ -17,21 +17,26 @@ use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
 class TagsViewHelper extends AbstractViewHelper
 {

+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('namespace', 'string', 'RSS element namespace', true);
+        $this->registerArgument('tag', 'string', 'RSS element name', true);
+    }
+
     /**
      * Retrieve the SimplePie item from the context and return its "tags".
      * Example of namespace: http://purl.org/dc/elements/1.1/
      *
-     * @param string $namespace
-     * @param string $tag
      * @return array
      * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException
      */
-    public function render($namespace, $tag)
+    public function render()
     {

         /** @var SimplePie_Item $item */
         $item = $this->templateVariableContainer->get('item');
-        $values = $item->get_item_tags($namespace, $tag);
+        $values = $item->get_item_tags($this->arguments['namespace'], $this->arguments['tag']);

         $result = array();
         if (is_array($values)) {
fabarea commented 5 years ago

It would be awesome if you could create a PR. I would merge it from there.

stephan-tittel commented 5 years ago

I can do this, but what I am really not sure about is ensuring downward compatibility to older Typo3 versions. I have to leave this up to you :-)

fabarea commented 5 years ago

I am intending to release a major version (3.0.0) with this change and increase the minimum TYPO3 compatibility to v9.

stephan-tittel commented 5 years ago

Thanks for your great work @fabarea :-)