Typo3 Update to CMS 7 -> Problems with ObjectRenderer - typo3

I've updated to CMS 7 and now I've some problems with the ObjectRenderer.
For the TS CONTENT and RECORDS Objects, it does not render correctly and returns always just an empty string. The other TS Objects are working well (TEXT, IMAGE, LINK).
Therefore I'm asking the question, if the behaviour of the cObjectRendererClass has changed or not?
I've done a lot of research and other people use the cObjectRendererClass in the same way as I am... Here is my code snippet for the ViewHelper, that renders this elements....
<?php
namespace TYPO3\Bh\ViewHelpers;
/**
* #package bh
* #author Michael Rainer
* #description Renders a Bakehouse-Content-Object
*
*/
class CObjectViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
/**
* #param \TYPO3\Bh\Domain\Model\Content $content
*/
public function render(\TYPO3\Bh\Domain\Model\Content $content) {
$cObjRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance("TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer");
$conf = array( // config
'tables' => 'tt_content',
'source' => $content->getUid(),
'dontCheckPid' => 1
);
return $cObjRenderer->render( $cObjRenderer->getContentObject('RECORDS'), $conf );
}
}
?>
Thank you in advance for your helpful responses :).

I got it! I finally got it! To be honest the guy next to me found it.
You have to include "CSS Styled Content" in your Root-Template.
You may ask why you have to do that? I can't give you an answer. I don't know, probably no one knows. Just do it and it works like a charm.
Lucky me. I don't have to go back to Joomla.

Related

How to overwrite A flexform of repository extension in to the Site Package in order to change the configuration

Are there any docs that can help me to overwrite the Flexform of powermail extension into my site package? So that I can edit the field configuration.
Please help, I have been searching for this very long.
Thank you.
There is a section "Add new FlexForm properties" in the Powermail documentation.
And in2code (the guys behind Powermail) has published a (german) blog-post "[PHP] FlexForm einer Extension komplett ersetzen"
in ext_localconf.php
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['postUserLookUp'][] = \ABC\MyPackage\Hooks\OverwriteFlexForm::class . '->overwrite';
In OverwriteFlexForm.php:
<?php
declare(strict_types=1);
namespace ABC\MyPackage\Hooks;
/**
* Class OverwriteFlexForm
*/
class OverwriteFlexForm
{
/**
* #var string
*/
protected $path = 'FILE:EXT:my_package/Configuration/FlexForms/FlexformStudyfinderList.xml';
/**
* #return void
*/
public function overwrite()
{
$GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['config']['ds']['powermail_pi1,list']
= $this->path;
}
}
In FlexformStudyfinderList.xml:
Flexform Code goes here.
Finally, I have found the solution myself. Thanks, everyone for your support.

template for list view with system categories

I have an extbase extension (TYPO3 7) with a simple model of a contact person.
The person has a name and a picture.
So far this is clear.
But every Person has a category (e.g. where he works. Office, Marketing etc.)
Therefor i use the system categories, as described here:
https://wiki.typo3.org/TYPO3_6.0#Adding_categories_to_own_models_without_using_Extension_Builder
When creating a person via web > list, i can assign a category.
Now the question for templating:
If i debug my contact person, i get the output like screen below.
I want to have a list where every category (headline) is shown with it's contact persons.
How to do this?
Is the logic for this only in the template or also in the controller?
Has anybody an example for this?
Best regards
Markus
I guess the required logic you need is possible with Fluid with using the GroupedFor ViewHelper and many others. Because a person can have multiple categories this would become a huge nesting of Viewhelpers so I can not recommend to use Fluid for this even if its possible. This kind of logics belong to the controllers, models and repositories.
There are multiple ways to solve this logic. Here is an example how to realize this in the controller...
Controller:
/**
* #var \TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository
* #inject
*/
protected $categoryRespoitory = NULL;
/**
* action list
* #return void
*/
public function listAction()
{
$allCategories = $this->categoryRespoitory->findAll();
$categoriesWithContacts = [];
/** #var \TYPO3\CMS\Extbase\Domain\Model\Category $category */
foreach($allCategories as $category) {
$contactsInCategory= $this->contactRepository->findByCategory($category);
if($contactsInCategory->count()>0) {
$categoriesWithContacts[] = [
'category' => $category,
'contacts' => $contactsInCategory
];
}
}
$this->view->assignMultiple([
'categoriesWithContacts' => $categoriesWithContacts
]);
}
Injecting the CategoryRespository will required clearing cache in install tool or reinstalling the extension.
Maybe you need this function in your ContactRepository:
/**
* #param \TYPO3\CMS\Extbase\Domain\Model\Category $category
* #return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
*/
public function findByCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $category) {
$query = $this->createQuery();
return $query->matching($query->contains('categories', $category))->execute();
}
Then in Fluid you can do something like this:
<f:for each="{categoriesWithContacts}" as="categoryWithContact">
{categoryWithContact.category.title}
<f:for each="{categoryWithContact.contacts}" as="contact">
{contact.name}
</f:for>
</f:for>

Simple date with Sonata Admin Bundle

I have a form with Sonata Admin Bundle with a date, to set the birthday of the user we want to add. Here goes MemberAdmin.php :
/**
* #param \Sonata\AdminBundle\Form\FormMapper $formMapper
*
* #return void
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('General')
->add('username')
->add('name')
->add('surname')
->add('birthdate', 'birthday', array('format' => 'yyyy-MM-dd'))
// ...
}
And my problem is when I send the form, I obtain Error: Call to a member function format() on a non-object ... But if I do print_r($birthdate) in the Entity class it shows me the DateTime object ...
Here are the interesting Entity parts:
/**
* #var date
*
* #ORM\Column(name="birthdate", type="date", nullable=true, options={"default" = "1990-01-01 00:00:00"})
* #Assert\DateTime()
*/
private $birthdate;
/**
* Set birthdate
*
* #param \DateTime $birthdate
* #return Membre
*/
public function setBirthdate($birthdate)
{
$this->birthdate = $birthdate;
return $this;
}
/**
* Get birthdate
*
* #return \DateTime
*/
public function getBirthdate()
{
return $this->birthdate;
}
My problem, currently, is that I don't know what I should do, I just want the date, no time, no anything else, i don't know if the column should be date (I work with PostgreSQL). What should I use for the types of my variables, I feel lost here, no simple Date possible ??
I tried to figure out from where it could come, but when I change too much I end up with: This form should not contain extra fields directly in the form, or even Incorrect value, but the field is a valid date ...
Thanks for your help !!
Change your field type to sonata_type_date_picker and test if the error message persist.
->add('birthdate', 'sonata_type_date_picker', array(
'format' => 'dd/MM/yyyy',
'widget' => 'single_text',
'label' => 'Birthdate',
))
From manual (sonata-project.org) :
If no type is set, the Admin class will use the one set in the
doctrine mapping definition.
So, you can try this:
->add('birthdate', null, array('format' => 'yyyy-MM-dd'));
#wr0ng.name you should never overwrite vendor code. NEVER.
There is something wrong with your mapping somewhere. You can use doctrine's commands to check your entity.
Edit
As #rande said, modifying vendors files is not the way to go, it provided an easy temp workaround for a local private app. As it is not dedicated to stay like that, I took care of the issue once I had more time. Sorry for the delay to come back to you guys.
I played around, tried with multiple setups, it took me time to figure it out, but I finally came to the conclusion that the issue... was caused by another date, that I was generating wrong in the constructor one line above.
Also, thanks to all of you, that guided me on the right path!

Symfony using DiscriminatorColumn with formbuilder

I have a user entity:
/**
* Class User
* #package Somepackage
* #ORM\Entity(repositoryClass="Somepackage\UserBundle\Entity\Repository\UserRepository")
* #ORM\Table(name="user")
* #ORM\InheritanceType("SINGLE_TABLE")
* #ORM\DiscriminatorColumn(name="discr", type="string")
* #ORM\DiscriminatorMap({"usereins" = "UserEins", "userzwei" = "UserZwei", "admin" = "Admin"})
*/
class User implements UserInterface, \Serializable {
Now I want to create a form with formbuilder, where a new user can be created and the "discr" can be selected via dropdown. But if I try this:
$builder
->add('discr', 'choice', array( ... ), 'required' => true ));
then Symfony says:
Neither the property "discr" nor one of the methods "getDiscr()", "isDiscr()", "hasDiscr()", "__get()" exist
How can I do this? Is it possible? I have been googling for over an hour and I cannot seem to find anything except other stackoverflow questions no one has been able to answer.
Cerads answer is correct, thank you very much. I added another field to my table in which I store the type of user, so I didn't have to worry about the discr field.

TYPO3 - Personalize content of the box in backend

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.