TYPO3: Extbase, extending the extension

In this example we have described how to extend the extension.
Here we are adding a field called 'mobile' to the fe_users table and described how we can extend it to the original extension.

 

Step1: Create a table record in your extension's ext_table.sql file

#
# Table structure for table 'fe_users'
#
CREATE TABLE fe_users (
    mobile varchar(255) DEFAULT '' NOT NULL,
);

 

Step2: Create Users.php in your extension's TCA folder

<?php
    if (!defined('TYPO3_MODE')) {
        die ('Access denied.');
    }
    $tempColumns = array (    
        'mobile' => array (
            'exclude' => 0,
            'label' => 'LLL:EXT:extname/Resources/Private/Language/locallang_db.xlf:fe_users.mobile',
            'config' => array(
                'type' => 'input',
                'size' => 13,
                'max' => 20,
                'eval' => 'trim',
                'checkbox' => 0,
                'default' => 0,
            ),
        ),
    );


    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('fe_users',$tempColumns,1);
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('fe_users','mobile');
    $GLOBALS['TCA']['fe_users']['types']['0']['showitem'] = str_replace('telephone','telephone, mobile ',$GLOBALS['TCA']['fe_users']['types']['0']['showitem']);
?>

 

Stpe3: Create a UserController.php in your extension's Controller folder

<?php
    namespace VENDOR\Extname\Controller;

    /**
     * UserController
    */

    class UserController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {

        /**
         * userRepository
         *
         * @var \VENDOR\Extname\Domain\Repository\UserRepository
         * @inject
         */
        protected $userRepository = NULL;
    }
?>

Inject the UserRepository from your extension like mentioned above.

 

Step4: Create a UserRepository.php in your extension's Repository folder

<?php
    namespace VENDOR\Extname\Domain\Repository;

    class UserRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {    
        
    }
?>

 

Step5: Create Users.php in your extension's Model folder and extend the class of model from fe_users extension

<?php
    namespace VENDOR\Extname\Domain\Model;

    class User extends \TYPO3\CMS\Extbase\Domain\Model\FrontendUser {

        /**
         * mobile
         *
         * @var \string
         */
        protected $mobile;
        
        
        
        /**
         * Returns the mobile
         *
         * @return \string $mobile
         */
        public function getMobile() {
            return $this->mobile;
        }

        /**
         * Sets the mobile
         *
         * @param \string $mobile
         * @return void
         */
        public function setMobile($mobile) {
            $this->mobile = $mobile;
        }
    }
?>

 

Step6: Create ext_typoscript_setup.txt in your extension

Now extending the fe_users is done, but that is not complete. We have to let our extension know that, model User extends the table fe_users.

Copy the following code to your    ext_typoscript_setup.txt file.

plugin.tx_extname {
    persistence{
        classes{
            VENDOR\Extname\Domain\Model\User {
                mapping {
                   tableName = fe_users
                }
            }
            
        }
    }
}

If we use the old version's of Extbase and Typo3 less than 6.2.0 , 
Copy the following code

config.tx_extbase {
    persistence{
        classes{
            VENDOR\Extname\Domain\Model\User {
                mapping {
                   tableName = fe_users
                }
            }
            
        }
    }
}

 

Now that's it. You have extended the extension fe_users.