image object is lost - typo3

My Extention passes a Model to fluid via
$this->view->assign('theSingleData', $object);
$this->view->assign('theMultipleData', $multipleObjects);
the object/thedata contains an image:
f:debug of theSingleData gives me this:
image => TYPO3\CMS\Extbase\Domain\Model\FileReferenceprototypepersistent entity (uid=17069, pid=341)
perfect. I can render the image with
<f:image....>
but 'theMultipleData' I process this way since its an array (just tested: it IS an array of 10 objects):
<f:for each="{theMultipleData}" as="item">
<f:debug inline="true">{item}</f:debug>
</f:for>
this is fine for all fields but the image:
'Extbase Variable Dump
image => '1' (1 chars)'
Where is my object gone????

If you assign multiple data you should use the corresponding method:
$this->view->assignMultiple($multipleObjects);
while $multipleObjects is an array with pairs of key and value:
$multipleObjects = [
'key1' => $value1,
'key2' => $value2,
'key3' => $value3,
...
];
In the template you have the values then available by the keys: {key1}, {key2}, {key3}, ...
So in general you can treat each pair like a common assignement you did with
$this->view->assign('key1', $value1);
$this->view->assign('key2', $value2);
$this->view->assign('key3', $value3);
...
I'd advise to use the method $this->view->assignMultiple() I mentioned above and then it will work if everything else is fine.
Details about the method $this->view->assignMultiple() you find here.

Related

Retrieving values of Form::select

I have a select box with an array of data to populate it like this:
{!! Form::select('language',$languageArray,'null', ['id'=>'language','multiple',]) !!}
I am passing $languageArray with view , and is simply an array of values like ['A','B','C']...
Now while fetching the selected values i am getting numeric value of selected options. Is there a way to change the values from numeric indexes to Text written in option. i did it using an associative array as second argument like this:
['english' => 'English',
'french' => 'French',
'so on ...' => 'So On ..']
But it creates a long list and view seems to be overloaded with data is there a better way for achieving below output ???
<select name="language">
<option value="english" ">English</option>
<option value="french">French</option>
....
I suggest you to use Config values ,
Create a file like languages.php in config folder.
<?php
return ['english' => 'English',
'french' => 'French',
'so on ...' => 'So On ..'
'german' => Lang::get('languages.german')
];
View :
{!! Form::select('language',Config::get('languages'),'null', ['id'=>'language','multiple',]) !!}
As you can see, in this way you can use config values in another view too and support multi language(its important too.. look at 'german')
Last Option is creating your own Form macro for example,
Form::macro('slugiySelect', function($name , $list , $selected = null , $options = [])
{
$options = [];
foreach($list as $row)
$options[Str::slug($row)] = $row;
return Form::select($name , $options , $selected , $options);
});
In this macro your options array is slugify with Laravel string function and uses as a key , I kept value as yours. You can do it with your way.

Accessing stacked data structures with HTML::Template::Compiled

To display a task dashboard on the web I take information from a file with Perl, store that in a stacked hash and send it to HTML::Template::Compiled.
There I can only access the key of the hash but no further data.
Here is what I wrote in Perl
my $template = HTML::Template::Compiled->new(
filename => '../templates/task_dashboard.tmpl',
case_sensitive => 1,
search_path_on_include => 1,
loop_context_vars => 1,
use_query => 0,
default_escape => 'HTML',
);
$template->param(
TIME => $time,
VERSION => $version,
REPORTDAT => $reportdat,
INFOS => \%information,
);
print $template->output();
The hash %information looks like this:
%informmation{key} = ($RefToArrayOfHashes1, $RefToArrayOfHashes2, $Skalar1, $Skalar2);
Within HTML::Template::Compiled I want to loop through the hash %information and subsequently through its content (like Data::Dumper).
I wrote this in the template file:
<%each INFOS %>
<h2><%=__key__ %></h2>
<table>
...loop through RefToArrayOfHashes1
</table>
<table>
...loop through RefToArrayOfHashes2
</table>
<p>Skalar1, Skalar2</p>
<%/each %>
To access the keys of %information is not a problem, but I don't know how to access the lower levels of the data structure.
I read some things about to use Dot but still don't get how to do it.
Can anybody help me by giving an example?

Perl HTML::TreeBuilder Class "Contains" Condition

I'm trying to use Perls HTML::TreeBuilder to extract data from an HTML page. My selectors include the following:
$root->look_down(_tag => 'div', class => 'member-search-results');
However, the div I'm looking for has multiple classes, one of which is member-search-results. With this code, I'm unable to find the div, and need to list all of the classes to get a successful match.
Is there any way I can do a class contains search on the elements, so that the code can also match tags like:
<div class="CLASS1 member-search-results CLASS2">...</div>
I understand that this should work:
$root->look_down(_tag => 'div', class => qr/member-search-results/);
But is this the correct way of doing this or is there a better method?
Thanks
Use Web::Query instead. Its CSS selectors are working according to the standards.
use Web::Query qw();
Web::Query
->new_from_html('<div class="CLASS1 member-search-results CLASS2">...</div>')
->find('div.member-search-results')
->text; # returns '...'
As Philip pointed out, using the regex method gets the desired results. Specifically, here is what I used:
$tag = $tag->look_down(_tag => 'ol', class => qr/members/);
Perhaps you need to separate _tag and class into separate look_down's (chain them together).
I use:
$tree->look_down( id => 'mw-content-text' )->look_down( _tag => 'ul' );
at https://github.com/pdurbin/scripts/blob/master/inthenews

TYPO3: Use t3lib_TCEforms in frontend plugin

I would like to use as much standard TYPO3 as possible to create a form to edit single records from tx_mytable.
In pi1 i load the tca for the table:
t3lib_div::loadTCA('tx_mytable');
Now I would like to use standard functions to create my form elements more or less like it is done in the backend...
I found this for the front end but cannot find any working examples:
t3lib_TCEforms_fe.php (that extends the normal t3lib_TCEforms)
Is this the right way to go or is there a better way?
I got something working but not really that nice code in the frontend
Here is a link that telss that TCA is not enough but two new entries in the array is needed
http://www.martin-helmich.de/?p=15
It is itemFormElName and itemFormElValue
// include tceforms_fe (place outside class where pipase is included)
require_once(PATH_t3lib.'class.t3lib_tceforms_fe.php');
// load TCA for table in frontend
t3lib_div::loadTCA('tx_ogcrmdb_tasks');
// init tceforms
$this->tceforms = t3lib_div::makeInstance("t3lib_TCEforms_FE");
$this->tceforms->initDefaultBEMode(); // is needed ??
$this->tceforms->backPath = $GLOBALS['BACK_PATH']; // is empty... may not be needed
//////////REPEAT FOR EACH INPUT FIELD/////////
// start create input fields, here just a single select for responsible
// conf used for tceforms similar to but not exactly like normal TCA
$conftest = array(
'itemFormElName' => $GLOBALS['TCA']['tx_ogcrmdb_tasks']['columns']['responsible']['label'],
'itemFormElValue' => 1,
'fieldConf' => array(
'config' => $GLOBALS['TCA']['tx_ogcrmdb_tasks']['columns']['responsible']['config']
)
);
// create input field
$this->content .= $this->tceforms->getSingleField_SW('','',array(),$conftest);
// wrap in form
$output = '<form action="" name="editform" method="post">';
$output .= $this->content;
$output .= '</form>';
// wrap and return output
return $output;
Still looking for a working example with custem template for input fields.

Using HTML::FormFu, how do you change a field value *after* processing so that it appears modified in Template Toolkit?

For example, if I process a form:
my $form_input = { input_data => '123' };
$form->process($form_input);
Then I want to alter the value of 'input_data':
my $clearme = $form->get_field('input_data');
$clearme->value("546"); # doesn't seem to work
..Before pushing the form object to TT:
template 'index' => { form => $form }; # using Dancer
'input_data' seems to retain it's original value (123). Any hints on what I'm doing wrong, or what I should be doing?
Thanks
After looking at the documentation and doing some testing, I think you want
$form->add_valid(input_data => '546');