TYPO3 - Personalize content of the box in backend - typo3

I've built a new content element type, and when you look in the backend, inside the box you can see the name of the module only. I'd like to change what information is show inside.
I could use the "header" field, but is there any way to use another field(s)?

Two answers
First answer
The field that's displayed there is the same field that's displayed in the list module. It is set in the table's TCA using ['ctrl']['label'] in the extension's ext_tables.php
$TCA['tx_myext_mytable'] = array(
'ctrl' => array(
'title' => 'My Table'
'label' => 'name_of_the_field_to_display_as_header'
// end snip
Second answer
If that is not enough for you, you can use a hook to display arbitrary HTML in the preview. The hook is called $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'].
The hook will be called with a function with this signature:
public function preProcess(
tx_cms_layout &$parentObject, // parent object
&$drawItem, // i have no idea what this is
&$headerContent, /* the content of the header
(the grey bar in the screenshot i think) */
&$itemContent, /* the content of the preview
(the white area in your screenshot */
array &$row // the content element's record
)
So all you have to do in that function is set the itemContent and, if you want, headerContent to whatever you want displayed.
Gotchas:
The output is inside of a span, so no block elements allowed in the
html. Any styling has to be done inline in the style attribute.
The function will be called on every content element, so you have to
check the row's CType and (if applicable) list_type fields so
that you only manipulate your own content elements.
An example can be found in the "fed" extension. I hope this helps.

Just a little update to adhominem answear #2 which is correct.
Today in TYPO3 6.2 and above your hook class has to inherit the interface TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface
It´s looks like belove
<?php
namespace TYPO3\CMS\Backend\View;
/**
* Interface for classes which hook into PageLayoutView and do additional
* tt_content_drawItem processing.
*
* #author Oliver Hader <oliver#typo3.org>
*/
interface PageLayoutViewDrawItemHookInterface {
/**
* Preprocesses the preview rendering of a content element.
*
* #param \TYPO3\CMS\Backend\View\PageLayoutView $parentObject Calling parent object
* #param boolean $drawItem Whether to draw the item using the default functionalities
* #param string $headerContent Header content
* #param string $itemContent Item content
* #param array $row Record row of tt_content
* #return void
*/
public function preProcess(\TYPO3\CMS\Backend\View\PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row);
}
&$drawItem is boolean and send as reference and by changing it to $drawItem = false; will stop the default rendering of the preview.

Related

Typo3 9.5 prefill form field with get parameter

I use TYPO3 system extension "form" and want to prefill an input field with a GET parameter.
This TYPO3 8.7. Form prefill input field is working, but only is no_cache=1. Is there another solution without deactivate the whole cache?
Thanks
david
Yes, you can but you need to create HOOK.
This is described in the documentation
For example, the HOOK
/**
* #param \TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface $renderable
* #return void
*/
public function initializeFormElement(\TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface $renderable)
{
if ($renderable->getUniqueIdentifier() === 'contactForm-text-1') {
$renderable->setDefaultValue('foo');
}
}
And the connect the hook
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'][<useATimestampAsKeyPlease>]
= \VENDOR\YourNamespace\YourClass::class;
Please, read the documentation for "Form framework".
I did it and get results what I need.
You can disable the cache of the content column of your form page, for example:
lib.content = COA
lib.content{
10 < styles.content.get
}
[page["uid"] == 512]
lib.content = COA_INT
[global]
Thanks TYPO3UA for you answer. But you should use the hook 'afterBuildingFinished' because the 'initializeFormElement' hook is executed BEFORE the properties from the form definition are set in the form element. So the default values from the form definition (even it is an empty string) will override the values set in the initializeFormElement' hook.
See: https://forge.typo3.org/issues/82615
So this works for setting the default value of an form element:
/**
* #param \TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface $renderable
* #return void
*/
public function afterBuildingFinished(\TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface $renderable)
{
if (method_exists($renderable, 'getUniqueIdentifier') && $renderable->getUniqueIdentifier() === 'contactForm-text-1') {
$renderable->setDefaultValue('Value');
}
}
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['afterBuildingFinished'][<useATimestampAsKeyPlease>]
= \VENDOR\YourNamespace\YourClass::class;

Extbase property mapping for deleted record

I would like to build a preview page for a create form. I set "deleted" property of the record to "1" when in previewAction because in the BE the list module is used to approve the inserted records - so if the record was never finally saved its deleted anyway.
Problem: I can create the record (deleted=1) - I can jump back to the form (no history back for I have to keep the created object). But if I submit again the property mapping tells me
Object of type MyModel with identity "3" not found.
Of course that's because its deleted. The settings in the Repository to ignore deleted are not taking action here.
Yes I could bypass the Extbase magic by filling up everything manually, but this is not what I want.
Here is the action to get an idea what I'm trying
/**
* action preview
*
* #param MyModel
* #return void
*/
public function previewAction(MyModel $newModel)
{
//check if model was already saved
$uid = $this->request->hasArgument('uid') ? this->request->getArgument('uid') : 0;
if($uid){
$newModel = $this->myRepository->findDeletedByUid($uid);
$this->myRepository->update($newModel);
}
else{
$newModel->setDeleted(true);
$this->myRepository->add($newModel);
}
$this->view->assign('ad', $newModel);
$this->persistenceManager->persistAll();
$uid = $this->persistenceManager->getIdentifierByObject($newModel);
$this->view->assign('uid', $uid);
}
Any ideas?
The Extbase default query settings suppress deleted objects.
Since you've already stated the custom query findDeletedByUid() in your repository, you just need to set it to include deleted records. It is important, however, that if you want to call your controller action using the object, you'll have to retrieve it before calling the action. Use an initialization action for that. The initializaton will be called automatically before the action.
If you want to set wether the object is deleted, you'll also going to need to define a property, getter and setter in your Domain Model and a proper definition in your tca to enable the data mapper to access the column.
In the repository:
public function findDeletedByUid($uid) {
$query = $this->createQuery();
$query->getQuerySettings()->setIncludeDeleted(true);
$query->matching(
$query->equals('uid',$uid)
);
return $query->execute();
}
In your Controller class:
/**
* initialize action previewAction
* Overrides the default initializeAction with one that can retrieve deleted objects
*/
public function initializePreviewAction(){
if( $this->request->hasArgument('mymodel') ){
$uid = $this->request->getArgument('mymodel');
if( $mymodel = $this->mymodelRepository->findDeletedByUid($uid) ){
$this->request->setArgument($mymodel);
} else {
// handle non retrievable object here
}
} else {
// handle missing argument here
}
}
In your Domain Model:
...
/**
* #var bool
*/
protected $deleted;
/**
* #return bool
*/
public function getDeleted() {
return $this->deleted;
}
/**
* #param bool $deleted
*/
public function setDeleted($deleted) {
$this->deleted = $deleted;
}
In your tca.php
...
'deleted' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.deleted',
'config' => array(
'type' => 'check',
),
),
Instead of doing any magic with deleted, you should use the hidden field to allow editors to preview documents.
You can tell your query to include hidden records inside the repository.
Your findDeletedByUid($uid) function caught my eye. If it's not a custom function, should it use something like findByDeleted(TRUE) or findByDeleted(1) in combination with ->getFirst() or ->findByUid()? You can find discussions in the Extbase manual reference and the Repository __call() function API sections.
Thanks for all hints.
I think depending to the answers its not possible without bypass extbase property-mapping magic. So I think in general its not a good idea to do it like that.
So I put now my own flag "stored" to the model.
In BE List-Module the not "stored" objects are still visible, but using an own BE Module or deleting the not "stored" object by a cron-job should do the job.
If anyone has a bedder idea feel free to share it :-)

how to set form name directly on symfony3? [duplicate]

With Symfony 2.7, you could customize a form's name in your EntityType class with the method getName()
This is now deprecated. Is there another way to do that with Symfony 3.0 ?
I have custom prototype entry_rows for collections that I would need to use in different forms.
Since the name of the rows is based on the form's name, I would need to change the later in order to use them with a different form.
You should implements the getBlockPrefix method instead of getName as described in the migration guide here.
As example:
/**
* Returns the prefix of the template block name for this type.
*
* The block prefix defaults to the underscored short class name with
* the "Type" suffix removed (e.g. "UserProfileType" => "user_profile").
*
* #return string The prefix of the template block name
*/
public function getBlockPrefix()
{
return "form_name";
}
Hope this help
Depending on how your form is built, there is different ways to set the name of your form.
If you are creating the form through $this->createForm(CustomType::class):
$formFactory = $this->get('form.factory');
$form = $formFactory->createNamed('custom_form_name', CustomType::class);
If you are building the form from the controller directly through $this->createFormBuilder():
$formFactory = $this->get('form.factory');
$form = $formFactory->createNamedBuilder('custom_form_name', CustomType::class);
Look at the FormFactory and FormBuilder APIs for more information.
You can try it, remove prefix on field name
public function getBlockPrefix()
{
return null;
}

In Extbase 6.2, don't use uid for list page

When using Extbase's "show" action:
<f:link.action action="show" arguments="{event : event}">
I would like to look up said event by a special column ('customID').
The actual TYPO3-uid should NOT appear in the URL (with or without RealURL).
The reason is that the data has been imported, and the "real" uid is 'customId'.
There's always #biesior's approach using f:link.page https://stackoverflow.com/a/26145125/160968 – but I thought I'd try it with the official way.
(how) is it possible to do that in extbase/fluid?
This is possible. Let's assume your model Event has a property customId. So you generate your link like this:
<f:link.action action="show" arguments="{event : event.customId}">
The link generated will have a queryString like this:
?tx_myext[event]=9999
The showAction generated by the Extension Builder expects that the UID of the event is passed. The PropertyMapper then fetches the object automatically and assigns it to the view:
/**
* action show
*
* #param \Your\Extension\Domain\Model\Event $event
* #return void
*/
public function showAction(\Your\Extension\Domain\Model\Event $event) {
$this->view->assign('event', $event);
}
But in your case you cannot fetch the object by UID because you passed the customId. So you need to fetch the object yourself:
/**
* action show
*
* #param integer $event
* #return void
*/
public function showAction($event) {
$event = $this->eventRepository->findOneByCustomId($event);
$this->view->assign('event', $event);
}
The annotation #param integer $event tells TYPO3 that the parameter is "just" an integer. You then call the magic method findOneByCustomId from your eventRepository. findOne indicates that you want exactly one Event object back (and not a QueryResult), while the ByCustomId that queries an existing property of your Event model.
Why not use realUrl with lookUpTable? See here: https://wiki.typo3.org/Realurl/manual#-.3ElookUpTable

Conditional validation of attributes in extbase: Add errors manually

I need to validate some fields based on values other fields have, within the same model. Since a custom validator only has access to the value it is validating, I can't check other validations there. From inspecting AbstractValidator, I couldn't find a possibility to reach that object the current value is validated.
Is there a solution to validate/add errors in a controller, set errors and render the actual view by keeping the original routine instead of introducing and assigning new objects to the view? Basically I could create a custom $errors var, fill it with errors after having done custom validations and the display it along with the original form errors. But I don't like that workaround approach.
When you add a new model validator, you have access to the other fields of that model
File: test_extension/Classes/Domain/Validator/TestModelValidator.php:
class Tx_TestExtension_Domain_Validator_TestModelValidator extends Tx_Extbase_Validation_Validator_AbstractValidator {
/**
* #param Tx_TestExtension_Domain_Model_TestModel $testModel
* #return boolean
*/
public function isValid($testModel) {
/** #var $testModel Tx_TestExtension_Domain_Model_TestModel */
//Access all properties from $testModel
$field1 = $testModel->getMyField1();
$field2 = $testModel->getMyField2();
}
}
You can also add errors to speific fields, but this code is from TYPO3 4.5, don't know if its still valid:
$error = t3lib_div::makeInstance('Tx_Extbase_Validation_Error', 'The entered value is allready in use.', 1329936079);
$this->errors['field2'] = t3lib_div::makeInstance('Tx_Extbase_Validation_PropertyError', 'field2');
$this->errors['field2']->addErrors(array($error));