[TYPO3-mvc] Using a Repository inside a ViewHelper

Thomas Layh thomas at layh.com
Tue May 24 13:09:37 CEST 2011


Hi Sebastian,

I have not tried this but this is what I would try. Perhaps it works or
helps.

Overwrite the findAll function in your repository to get the storagePage as
argument to your findAll function.

Then try to manipulate the query settings like:

$query->getQuerySettings()->setStoragePageIds(array($storagePage));

Like I sad, I have not tried it, it is just a shoot in the blue.

Greetings,
Thomas


On Tue, May 24, 2011 at 12:07, Sebastian Michaelsen <
sebastian.gebhard at gmail.com> wrote:

> Hey,
>
> I'm struggling to use a Repository inside a custom ViewHelper.
>
> === Why the heck would you want to do that? ===
> I have an Extension dealing with "definitions" (like Glossary Entries). It
> provides a ViewHelper that checks some text if it has "defined" words in it
> and links them to their explanation on a Glossary page. It is designed to be
> used in other extensions. Like if you have an extbased blog you can use the
> GlossarylinksViewHelper to add links to your posts. (The actual replacement
> in the code below is not finished, but that's not my problem)
> This is why I need to do the data things inside the ViewHelper, because the
> extension that is enriched with "definitions" is not aware of the glossary
> data.
>
> === What's the problem? ===
> I can't figure out how to tell the DefinitionsRepository from which Folder
> it should read the records. By default it takes the
> plugin.tx_otherextension.persistence.storagePid value from the extension
> that it is used with.
>
> E.g. I have a Blog with posts from pid 20 and I have Glossary Terms on pid
> 30. In one of the Blog Templates I use the GlossarylinksViewHelper, but the
> DefinitionsRepository will always try to read from pid 20.
>
> Any hints for me how I can set the right Storage Folder? Or should I try a
> totally other approach?
>
> Kind regards,
> Sebastian
>
> (Below my current GlossarylinksViewHelper Class:)
>
> <?php
>
> /**
>  * Parses text and includes explanations for glossary words
>  *
>  * @author Michaelsen
>  */
> class Tx_Definitions_ViewHelpers_GlossarylinksViewHelper extends
> Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
>
>        /**
>         * @var Tx_Definitions_Domain_Repository_DefinitionRepository
>         */
>        protected $definitionRepository;
>
>        /**
>         * @param Tx_Definitions_Domain_Repository_DefinitionRepository
> $definitionRepository
>         * @return void
>         */
>        public function
> injectDefinitionRepository(Tx_Definitions_Domain_Repository_DefinitionRepository
> $definitionRepository) {
>                $this->definitionRepository = $definitionRepository;
>        }
>
>        /**
>         * @param string $targetPage TODO: Link to the Glossary page
>         * @param string $storagePage Page to read Glossary entries from
>         * @return string
>         */
>        public function render($targetPage, $storagePage) {
>
>                $content = $this->renderChildren();
>
>                /**
>                 * TODO: Read from $storagePage
>                 */
>                $definitions = $this->definitionRepository->findAll();
>
>                foreach($definitions as $definition) {
>                        $content = str_replace($definition->getTitle(),
> '<span title="' . $definition->getExplanation() . '">' .
> $definition->getTitle() . '</span>', $content);
>                }
>
>                return $content;
>
>        }
>
> }
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>


More information about the TYPO3-project-typo3v4mvc mailing list