WimDiesel
WimDiesel

Reputation: 65

Typo3 tx_news extend with custom Fields - Content disappears sometimes, caching Issue?

I'm using Typo3 9.5.5 and I extended the extension tx_news with some custom fields. Everything works fine in front-end and back-end, but sometimes the custom content disappears in front-end and is not shown. Also the debug doesn't show the content. In my opinion it could be a caching problem, because after clearing the complete cache, the custom content is shown again. How can I fix this issue?

I tried to put the needed templates into my custom extension, but the result is the same.


<?php

namespace myName\NewsExtend\Domain\Model;

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

 /**
  * @var string
  */
protected $issue;

/**
 * Get categoryHeader
 *
 * @return string
 */
public function getCategoryHeader()
{
    return $this->categoryHeader;
}

/**
 * Set categoryHeader
 *
 * @param string $categoryHeader categoryHeader
 */
public function setCategoryHeader($categoryHeader)
{
    $this->categoryHeader = $categoryHeader;
}

/**
 * Get issue
 *
 * @return string
 */
public function getIssue()
{
    return $this->issue;
}

/**
 * Set issue
 *
 * @param string $issue issue
 */
public function setIssue($issue)
{
    $this->issue = $issue;
}

}

Upvotes: 1

Views: 1740

Answers (4)

user2310852
user2310852

Reputation: 1674

Complete Tutorial to extend TYPO3 tx_news with new fields:

TypoScript Setup

plugin.tx_news {
    persistence {
        classes {
            GeorgRinger\News\Domain\Model\News {
                subclasses {
                    0 = Yourvendor\Yourext\Domain\Model\NewsDefault
                }
            }
            Yourvendor\\Domain\Model\NewsDefault {
                mapping {
                    tableName = tx_news_domain_model_news
                    recordType = 0
                }
            }
        }
    }
}

ext_tables.sql

CREATE TABLE tx_news_domain_model_news (
    new_field varchar(255) DEFAULT '' NOT NULL
);

TCA - typo3conf/ext/yourext/Configuration/TCA/Overrides/tx_news_domain_model_news.php

defined('TYPO3_MODE') or die();

/**
 * Add new fields to news table
 */
$tmpNewsColumns = [
    'new_field' => [
        'exclude' => 1,
        'label' => 'label or use localang file',
        'config' => [
            'type' => 'input',
            'size' => 30,
            'eval' => 'trim'
        ],
    ],
];

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tx_news_domain_model_news', $tmpNewsColumns, true);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('tx_news_domain_model_news', 'new_field', '', 'after:teaser');

Add model - typo3conf/ext/yourext/Classes/Domain/Model/NewsDefault.php

namespace Yourvendor\Yourext\Domain\Model;

use GeorgRinger\News\Domain\Model\NewsDefault as NewsFields;

class NewsDefault extends NewsFields {
    /**
     * the new_field
     * @var string
     */
    protected $newField;


    /**
     * Returns an array of orderings created from a given demand object.
     *
     * @param string $newField
     * @return void
     */
    public function setNewField($newField) {
        $this->newField = $newField;
    }
    /**
     * Get newField
     *
     * @return string
     */
    public function getNewField() {
        return $this->newField;
    }

}

Locate and use new fields in template, to check <f:debug>{newsItem}</f:debug> in typo3conf/ext/yourext/Resources/Private/Extensions/News/Partials/List/Item.html

Upvotes: 2

WimDiesel
WimDiesel

Reputation: 65

A little bit late, but my problem was inside the Typoscript Setup. One tutorial described that it has to be:

config.tx_extbase {
persistence {
    classes {
    GeorgRinger\News\Domain\Model\News {
      ....
    }
  }
 }

but it must be "plugin.tx_news" not "config.tx_extbase":

 plugin.tx_news {
   ...
 }

Upvotes: 0

Paul
Paul

Reputation: 289

I've ran into the same issue. I used the implementation from the linked documentation entry "ProxyClass generator" and when I return to the page after some hours or so the subtitle didn't get rendered anymore. Only a system cache clear brings it back.

Upvotes: 1

Georg Ringer
Georg Ringer

Reputation: 7939

Do you sometimes clear typo3temp which would trigger that as well

Upvotes: 0

Related Questions