TYPO3: Add custom set functions in extension controller

↘锁芯ラ 提交于 2019-12-06 19:45:38

Disabling a user is not default enabled on the standard user object. I've tackled this issue myself by creating a model extending the FrontendUser from TYPO3 and adding a property disable.

class FrontendUser extends \TYPO3\CMS\Extbase\Domain\Model\FrontendUser {
    /**
     * @var boolean
     */
    protected $disable;

    /**
     * Gets the Disable
     *
     * @return boolean
     */
    public function getDisable() {
        return (bool)$this->disable;
    }

    /**
     * Sets the Disable
     *
     * @param boolean $disable
     * @return void
     */
    public function setDisable($disable) {
        $this->disable = (bool)$disable;
    }
}

You might need a bit of typoscript to map it to the proper property

config.tx_extbase {
    persistence{
        classes {
            VendorName\ExtensionName\Domain\Model\FrontendUser {
                mapping {
                    tableName = fe_users
                    columns {
                        disable.mapOnProperty = disable
                    }
                }
            }
        }
    }
}

You'll need the FrontendUserRepository as well

/**
* A Frontend User repository
*/
class FrontendUserRepository extends \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository {
}

After this you can use the newly created FrontendUser model as your model for the FrontendUser, inject it, and happily use

$userModel->setDisable(1);
// and
$userModel->getDisable();

(All namespaces are fully written, this is not necessary obviously, but simply done for ease of reading)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!