1
votes

I'm just trying to extend the sys_category table with a new field "page" just the normal extbase way. Worked like a charm, field shows up and is saved in DB. But there is no field in my f:debug in Fluid. Anyone got an idea what is missing?

Thanks a lot for any help!

TCA Override:

$newColumns = [
  'page' => [
    'exclude' => true,
    'label' => 'LLL:EXT:project/Resources/Private/Language/Default/locallang_db.xlf:sys_category.page',
    'config' => [
      'type' => 'group',
      'internal_type' => 'db',
      'allowed' => 'pages',
      'size' => 1,
      'maxitems' => 1,
      'minitems' => 0
    ]
  ],
];


\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_category', $newColumns);

// Make fields visible in the TCEforms:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
  'sys_category', // Table name
  'page', // Field list to add
  '1', // List of specific types to add the field list to. (If empty, all type entries are affected)
  'after:title' // Insert fields before (default) or after one, or replace a field
);

SQL:

#
# Table structure for table 'sys_category'
#
CREATE TABLE sys_category (
  page int(11),
);

Model:

<?php
namespace <Vendorname>\Project\Domain\Model;

use TYPO3\CMS\Extbase\Utility\DebuggerUtility;

/**
 * Class Category
 * @package <Vendorname>\Project
 */

class Category extends \TYPO3\CMS\Extbase\Domain\Model\Category
{
    /**
     * @var integer
     */
    protected $page = null;


    /**
     * Gets the page.
     *
     * @return integer
     * @api
     */
    public function getPage()
    {
        return $this->page;
    }

    /**
     * Sets the page.
     *
     * @param integer $page
     * @api
     */
    public function setPage($page)
    {
        $this->page = $page;
    }

}

Typoscript Setup:

config.tx_extbase.persistence {
    storagePid = {$plugin.tx_project.persistence.storagePid}
    classes {
        TYPO3\CMS\Extbase\Domain\Model\Category {
            subclasses {
                <Vendorname>\Project\Domain\Model\Category = <Vendorname>\Project\Domain\Model\Category
            }
        }

        <Vendorname>\Project\Domain\Model\Category {
            mapping {
                tableName = sys_category
            }
        }
    }
}
1
Did you find a solution for your problem? Currently I want to do the same thing...Juburin

1 Answers

2
votes

I'm unsure if it is possible to subclass the sys_category table of TYPO3.

If you always want that all queries to TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository will return objects of your custom type, you can configure your ext_typoscript_setup like shown below

config.tx_extbase{
    objects {
        TYPO3\CMS\Extbase\Domain\Model\Category.className = <vendor>\Project\Domain\Model\Category
    }
    persistence.classes {
        <vendor>\Project\Domain\Model\Category {
            mapping {
                tableName = sys_category
            }
        }
    }
}

Please note, that this will not include any other extensions on the table sys_category made by other TYPO3 extensions.

However, if you just need the extended Category object within your extension and not globally in TYPO3, you could create an own CategoryRepository in your extension like in ext:news