Typo3 - own viewhelper escapes HTML in T3 V8 - typo3

I have a viewhelper which worked well in Typo3 V7.x, but in V8.x its output is not plain html any more, but it's html-encoded.
Simplified viewhelper class:
namespace MyName\Teaserbox\ViewHelpers;
class TeaserboxViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
public function render ( $html = null ) {
return "<div><h2>$html</h2></div>"
}
}
Simplified HTML:
<m:teaserbox><f:cObject typoscriptObjectPath="lib.someHTML"></f:cObject></m:teaserbox>
Output is something like:
<div><h2>TEST</h2></div>

Escaping can be turned off by adding protected $escapeOutput = false; to your ViewHelper.
namespace MyName\Teaserbox\ViewHelpers;
class TeaserboxViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
protected $escapeOutput = false;
public function render ( $html = null ) {
return "<div><h2>$html</h2></div>"
}
}
Doing so, you must be aware of, that you need to sanitize user input yourself in order to prevent XSS.

Related

I can't pass parameters to the component Wire Elements Modal

I can't pass parameters to the component.
I have 3 files:
Inside Livewire/test.blade.php
...............
onclick='Livewire.emit("openModal", "test-modal", {{ json_encode(["id_code" => $client->id_code]) }})'>
Inside /Http/Livewire/TestModal.php
namespace App\Http\Livewire;
use LivewireUI\Modal\ModalComponent;
use App\Models\Client;
class TestModal extends ModalComponent
{
public $id_code;
public function render($id_code)
{
dd($id_code);
return view('livewire.test-modal');
}
}
And livewire.test-modal which displays the content of the modal window.
But I can't get the id_code.
Let's see if someone can help me with this. Thanks.
So I had the same issue pretty much.
I solved it by adding the $id_code to the mount method. I hope it helps
namespace App\Http\Livewire;
use LivewireUI\Modal\ModalComponent;
use App\Models\Client;
class TestModal extends ModalComponent
{
public $id_code;
public function mount($id_code){
$this->id_code = $id_code
}
public function render()
{
$elCliente = Client::where("erp_code", $this->id_code)->first();
dd($elCliente);
return view('livewire.test-modal');
}
}
Livewire.emit("openModal") will emit an event that you can listen to in your components. The render() method in Livewire does not accept a parameter, so instead you need to listen to that event, and do your actions in a separate method instead.
By adding
protected $listeners = ['openModal' => 'openModal'];
the component will now listen to the event openModal (key in the array) being dispatched, and then fire the method openModal() (value in the array). Since you pass in two parameters, "test-modal" and a JSON parameter, you can accept those in that method.
namespace App\Http\Livewire;
use LivewireUI\Modal\ModalComponent;
use App\Models\Client;
class TestModal extends ModalComponent
{
public $id_code;
protected $listeners = ['openModal' => 'openModal'];
public function openModal($name, $data)
{
$this->id_code = $data['id_code'];
}
public function render()
{
return view('livewire.test-modal');
}
}

Symfony5.2 form action on change ChoiceType

How I can make an action on change choiceType in Symfony Form ?
Something like this:
if ($form->onChange()) {
//action
{
Symfony as your backend only notices changes when the form is submitted. Any changes to the form before you submit must be detected via Javascript.
If your form maps an entity, you can add an event subscriber to check that some property was changed
namespace App\EventSubscriber\Doctrine
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\ORM\Events;
class DoctrinePreUpdateSubscriber implements EventSubscriber
{
/**
* #return array<string, string>
*/
public function getSubscribedEvents(): array
{
return [
Events::preUpdate => 'preUpdate',
];
}
private function preUpdate(PreUpdateEventArgs $args): void
{
if ($args->getObject() instanceof SomeEntity && $args->hasChangedField('someProperty')) {
}
}
}

Suitecrm custom template for custom module

I built a custom module using the module builder.
I want to modify templates of my module (edit, detail, subpanel).
How can I tell Suitecrm to use an other template?
Thanks
(Suitecrm 7.7)
it's work for me.
<?php
require_once('include/MVC/View/SugarView.php');
class AccountsViewEdit extends SugarView {
private $smarty;
public function __construct() {
}
public function display() {
$this->smarty = new Sugar_Smarty();
$data = ['a'=> 'a', 'b'=>'b'];
$this->smarty->assign($data);
$this->smarty->display('path/custom/template.tpl');
}
}
You need to create a SugarView in the module and then override the display() method to return the path to your custom template. The convention is keep your templates in a 'tpl' folder in the module.
For example if you look at the 'modules/Accounts/views/view.edit.php' you would just need to add
class AccountsViewEdit extends ViewEdit
{
public function __construct()
{
parent::__construct();
$this->useForSubpanel = true;
$this->useModuleQuickCreateTemplate = true;
}
public function display() {
parent::display(); // TODO: Change the autogenerated stub
return $this->ss->fetch('path/to/your/smarty/template.tpl');
}
}
it's almost the same for the subpanels except the location is in the Dashlets folder. Take a look at modules/Accounts/Dashlets/MyAccountsDashlet/MyAccountsDashlet.php for example.

unit-testing Wicket input components

I just wrote my first Wicket component :) It contains a ListView with some Radio input fields. Now I want to unit test if a selected value makes its way to the model.
As WicketTester.newFormTester("myForm") expects a form, I try to create a form on the fly:
public void testDataBinding()
{
Model model = ...
MyRadioComponent myRadioComponent = new MyRadioComponent (...);
Form form = new Form("myForm", ...);
form.add(myRadioComponent);
WicketTester wicketTester = new WicketTester();
wicketTester.startComponentInPage(form);
// FormTester formTester = wicketTester.newFormTester("myForm");
// ...
}
Now wicketTester.startComponentInPage(form) results in:
Failed: Component [myForm] (path = [0:x]) must be applied to a tag of type [form],
not: '<span wicket:id="myForm" id="myForm3">'
Any idea how to fix this and/or how to test such an input component the right way?
OK, in detail the solution now looks like this:
public FormTester createFormTester(Component c) {
final WicketTester wicketTester = new WicketTester();
final FormPage page = new FormPage(c);
wicketTester.startPage(page);
return wicketTester.newFormTester(page.getPathToForm());
}
private static class FormPage extends WebPage implements IMarkupResourceStreamProvider {
private final Form<Void> form;
private final Component c;
private FormPage(final Component c) {
this.c = c;
add(form = new Form<>("form"));
form.add(c);
}
public String getPathToForm() {
return form.getPageRelativePath();
}
#Override
public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass) {
return new StringResourceStream(
"<html><body>"
+ "<form wicket:id='" + form.getId() + "'><span wicket:id='" + c.getId() + "'/></form>"
+ "</body></html>");
}
}
I believe startComponentInPage uses a <span> for its component. Wicket checks that Forms are attached to <form> tags which is why you get this error.
You need to create your own test page with a <form> inside it. See org.apache.wicket.markup.html.form.NumberTextFieldTest for an example of inline markup. Otherwise, create a Form test page class with associated html markup file.

Language switcher, redirect to current page with symfony

What is the best way to do a language switcher in symfony that redirects to the same page in the chosen language? Jobeet simply redirects on the homepage.
Something like so should do the trick:
<?php
class myActions extends sfActions
{
public function executeLanguageSwitch(sfWebRequest $request)
{
$new_language = $request->getParameter('lang',false);
$this->forward404unless($new_language);
// You should probably insert stuff here check that the new culture passed in is valid
$this->getUser()->setCulture($new_language);
$this->redirect($request->getReferer());
return sfView::HEADER_ONLY;
}
}
This works for me:
<?php
class PageController extends Controller
{
public function changeLocaleAction(Request $request)
{
$locale = $request->get('_locale');
$this->get('session')->set('_locale', $locale);
$referer = $request->headers->get('referer');
return new RedirectResponse($referer);
}
}