[TYPO3-mvc] Extend CropViewhelper

Sebastian Schreiber me at schreibersebastian.de
Mon Oct 10 15:48:22 CEST 2011


Am 10.10.2011 15:31, schrieb Tim Schoch | GSTALTIG:
> Hello Thomas
>
> This works fine for me:
> <?php
>    class ExtendedCrop extends CropViewHelper {
>          protected function renderChildren() {
>              return 'Child + ' . parent::renderChildren();
>          }
>    }
>
>    class CropViewHelper { // imagine this to be the original fluid viewhelper
>        public function render() {
>              return $this->renderChildren();
>        }
>          protected function renderChildren() {
>              return 'Parent';
>          }
>      }
>
>      $crop = new ExtendedCrop();
>      echo $crop->render(); // returns Child + Parent
> ?>
>
> The call in the parent $this->renderChildren() will call you're extended function and not the one defined by itself.
> If you want to preprocess the content before it gets cropped, you can do use the parent::renderChildren() method in your extended version.
> I guess thats what Sebastian meant.
>
> Tim
>
>    _____
>
> From: Thomas Allmer [mailto:at at delusionworld.com]
> To: typo3-project-typo3v4mvc at lists.typo3.org
> Sent: Mon, 10 Oct 2011 13:50:37 +0200
> Subject: Re: [TYPO3-mvc] Extend CropViewhelper
>
> On 10.10.2011 09:17, Sebastian Schreiber wrote:
>    >  Maybe this helps and make you feel better:
>    >
>    >  Introduce a member variable in your class overrite the renderChildren
>    >  method in your class and return your
>    >  variable.
>    >
>    >  Right?
>
>    probably not :p
>
>    changing the renderChildren method won't change how the parent will
>    fetch it's string... so it won't help :p unless I extend the Crop with a
>    "CropFix" overwriting the renderChildren there and then extend from the
>    "CropFix" instead of the normal Crop... but than again this looks even
>    more ugly :p and if I would crop I would certainly only change the
>    render method so I could pass the string to use and not temper with the
>    renderChildren :p
>
>    more ideas? :p
>
>    >  Am 10.10.2011 01:00, schrieb Thomas Allmer:
>    >>  hey,
>    >>
>    >>  can I set somehow the content of the current viewhelper?
>    >>  I do want to extend the CropViewHelper like this:
>    >>
>    >>  class Tx_Reposearch_ViewHelpers_Format_HighlightCropViewHelper extends
>    >>  Tx_Fluid_ViewHelpers_Format_CropViewHelper
>    >>
>    >>  so I get the string and do some modifications to it afterward I want
>    >>  to call the parent, but as Crop gets the content with
>    >>  $this->renderChildren(); I can't give my "new" string as a parameter?
>    >>
>    >>  I though of probably something like this but that obviously don't work
>    >>  as there is no setContent function :p
>    >>  $this->setContent($stringToHighlightTruncate);
>    >>  return parent::render($maxCharacters, $append, [...]);
>    >>
>    >>  so currently I more or less just fork the Crop viewhelper... but that
>    >>  doesn't seem right... so anyone got a better solution?
>    >>
>    >>  see gist for full code https://gist.github.com/1274313
>    >>
>    >>  I was just thinking, but in most cases I don't even need this as most
>    >>  viewhelpers do it like this and let you define the subject via
>    >>  parameter...
>    >>  if ($subject === NULL) {
>    >>  $subject = $this->renderChildren();
>    >>  }
>    >>
>    >>  so probably a bug report for a view?
>    >>
>    >>  cheers
>    >
>    >
>
>
>    -- 
>    +---------------------------------+-----------------------------------+
>    | Thomas Allmer                   |   http://www.delusionworld.com    |
>    | E-mail: at at delusionworld.com    |   phone: +43 699 16217064         |
>    +---------------------------------+-----------------------------------+
>    _______________________________________________
>    TYPO3-project-typo3v4mvc mailing list
>    TYPO3-project-typo3v4mvc at lists.typo3.org
>    http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
Thanks Tim for clarifying the things up.
That´s exactly what i meant.
Actually that´s nothing to do with extbase or fluid, it´s just OOP ;-)

Good luck

-- 
Sebastian Schreiber
(Medieninformatiker B.Sc.)
(TYPO3 Certified Integrator)

Schanzenstraße 27, Schlosserei 4
D-51063 Köln

T  0221 677 88 541
M  0176 431 05 790

Skype schreibersebastian.de

me at schreibersebastian.de
www.schreibersebastian.de

Steuernummer: 217 / 5269 / 4675



More information about the TYPO3-project-typo3v4mvc mailing list