Search code examples
typo3typo3-8.xtx-news

TYPO3 tx_news problem by adding custom field


I have got a problem by adding 3 custom fields to the tx_news extension for typo3 8.7.20.

I have worked with this tutorial: http://keinerweiss.de/525-die-extbase-extension-news-um-ein-feld-erweitern.html

But I can't get it to work.

In the backend I can see die new fields (lat, lng, reciever), I can fill them with content and when I save them they are in the database. So that works fine.

On the frontend it does not work. If I am not loggedin in Typo3 I can't even see the page now.

If I am loggedin: In the fluid debbuger I can see the 3 vars but they are always empty (even if I have saved the news record with some content in thiese new fields)

Here is my Domain Model:

<?php
namespace Newsextend\Newsextend\Domain\Model;

/**
 * News model for default news
 *
 * @package TYPO3   
 * @subpackage tx_news
 */
class NewsDefault extends \GeorgRinger\News\Domain\Model\News {
/**
 * @var string
 */
protected $ext_lat;
/**
 * @var string
 */
protected $ext_lng;
/**
 * @var string
 */
protected $ext_reciever;

/**
 * Get lat
 *
 * @return string
 */
public function getExt_lat()
{
    return $this->ext_lat;
}
public function setExt_lat($ext_lat)
{
    $this->ext_lat = $ext_lat;
}

/**
 * Get lng
 *
 * @return string
 */
public function getExt_lng()
{
    return $this->ext_lng;
}
public function setExt_lng($ext_lng)
{
    $this->ext_lng = $ext_lng;
}

/**
 * Get reciever
 *
 * @return string
 */
public function getExt_reciever()
{
    // return "teststring";
    return $this->ext_reciever;
}
public function setExt_reciever($ext_reciever)
{
    // return "teststring";
    $this->ext_reciever = $ext_reciever;
}

/**
 * Set title
 *
 * @param string $subtitle subtitle
 * @return void
 */
public function setSubtitle($subtitle)
{
    $this->subtitle = $subtitle;
}
}

Here is my Typescript setup.txt:

    plugin.tx_news {
    persistence {
        classes {
            GeorgRinger\News\Domain\Model\News {
                subclasses {
                    # three different classes are used for each news type
                    # 0 == default news
                    0 = Newsextend\Newsextend\Domain\Model\NewsDefault
                }
            }
            Newsextend\Newsextend\Domain\Model\NewsDefault {
                mapping {
                    recordType = 0
                    tableName = tx_news_domain_model_news
                }
            }
        }
    }
}

And my ext_tables.php

    <?php
defined('TYPO3_MODE') || die('Access denied.');

call_user_func(
    function()
    {

        \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('newsextend', 'Configuration/TypoScript', 'news_extend');
        \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'news_extend');
    }
);

// define new fields
$tempColumns = array(
    'ext_lat' => array(
        'exclude' => 0,
        'label' => 'LAT',
        'config' => array(
            'type' => 'input',
            'size' => 30,
            'eval' => 'trim'
        ),
    ),
    'ext_lng' => array(
        'exclude' => 0,
        'label' => 'LONG',
        'config' => array(
            'type' => 'input',
            'size' => 30,
            'eval' => 'trim'
        ),
    ),
    'ext_reciever' => array(
        'exclude' => 0,
        'label' => 'Förderungsempfänger',
        'config' => array(
            'type' => 'input',
            'size' => 30,
            'eval' => 'trim'
        ),
    ),
);

// add field to tca
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
    'tx_news_domain_model_news',
    $tempColumns,
    1
);

// add new field subtitle after title
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes("tx_news_domain_model_news", 'ext_lat', '', 'after:title');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes("tx_news_domain_model_news", 'ext_lng', '', 'after:ext_lat');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes("tx_news_domain_model_news", 'ext_reciever', '', 'after:ext_lng');

Can anyone see my problem? Thanks Christopher Smith


Solution

  • in extbase underscores are transformed to uppercase. So if your field in the DB is ext_lat, then the property must be $extLat and the getters & setters must be changed according to that as well.