2016-09-27 119 views
0

我的目標是能夠:如何在Typo3中實現繼承6.2擴展?

  1. 在後端(已完成)
  2. 創建SubExpertise項在後端
    • (同樣的道具作爲Expertise但 它們屬於創建Expertise項一個或多個Expertise
  3. 在後臺創建AdditionalInfoTitles
    • (它們可以屬於一個或多個Expertise OR SubExpertise
    • 我希望能夠創建一個新的條目
    時,選擇從所有ExpertiseSubExpertise對象

現在,我只能將所有Expertise -entries之間進行選擇: enter image description here

這就是爲什麼我考慮繼承的原因SubExpertise將與Expertise類型相同,因此會自動顯示在AdditionalInfoTitles條目的Expertise列表中。但是,這只是我的理論,我有點困在用TYPO3 TCA和我缺乏的其他我認識現實。

在我的分機建設者我做了以下(不介意subExpertises屬性)enter image description here
然後我說expertiseOverrides文件夾,因爲我試圖把它與subexpertise擴展:

<?php 
if (!defined('TYPO3_MODE')) { 
     die ('Access denied.'); 
} 

$temporaryColumns = array (
     'expertise' => array(
     'exclude' => 1, 
     'label' => 'LLL:EXT:appoints/Resources/Private/Language/locallang_db.xlf:tx_appoints_domain_model_subexpertise.expertise', 
     'config' => array(
      'type' => 'select', 
      'foreign_table' => 'tx_appoints_domain_model_subexpertise', 
      'MM' => 'tx_appoints_subexpertise_expertise_mm', 
      'size' => 10, 
      'autoSizeMax' => 30, 
      'maxitems' => 9999, 
      'multiple' => 0, 
      'wizards' => array(
       '_PADDING' => 1, 
       '_VERTICAL' => 1, 
       'edit' => array(
        'module' => array(
         'name' => 'wizard_edit', 
        ), 
        'type' => 'popup', 
        'title' => 'Edit', 
        'icon' => 'edit2.gif', 
        'popup_onlyOpenIfSelected' => 1, 
        'JSopenParams' => 'height=350,width=580,status=0,menubar=0,scrollbars=1', 
        ), 
       'add' => Array(
        'module' => array(
         'name' => 'wizard_add', 
        ), 
        'type' => 'script', 
        'title' => 'Create new', 
        'icon' => 'add.gif', 
        'params' => array(
         'table' => 'tx_appoints_domain_model_expertise', 
         'pid' => '###CURRENT_PID###', 
         'setValue' => 'prepend' 
        ), 
       ), 
      ), 
     ), 
    ), 
); 

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
     'tx_appoints_domain_model_expertise', 
     $temporaryColumns 
); 
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
     'tx_appoints_domain_model_expertise', 
     'expertise' 
); 

但我不認爲我會到正確的方向與本 - 因爲我覺得這樣我就不會添加SubExpertiseExpertise分開 - 我已經有了與我的對象相同的問題,它擴展了fe_user,因爲創建它們時我通常必須經過一個新的用戶然後設置擴展類型 - 但這樣我就沒有單獨的延伸fe_user的不同實體列表。

+0

'Expertise'和'SubExpertise'之間是否有其他區別,後者有一個或多個父母?如果不是,我會把它們當作一個一樣的,只是創建'Expertise'對象。 'AdditionalInfoTitle'同樣的問題。 –

+0

是的,專業和SubExpertise是相同的,SubExpertise可以屬於一個或多個專業知識的差異。 AdditionalInfoTitle是完全不同的,它的屬性與此問題無關 - 除了它的Expertise-Property,我希望能夠選擇Expertise和SubExpertise條目。 –

回答

1

我會擺脫大部分Expertise和SubExpertise之間的分離。根據你的描述,一個SubExpertise不能有另一個SubExpertise作爲它的父項,所以你可以調整選擇字段,它只列出具有一個空的父字段的專家。 通過消除差異,刪除AdditionalInfoTitles中選擇(Sub)Expertise的問題;它只是一個和相同類型的對象。

如果您需要區分BE表單中的演示文稿,有很多選項可以調整列出的項目的標籤,使用您自己的函數來構建列表或甚至自定義表單元素。

在Extbase中,您可以簡單地在存儲庫中編寫幾個函數來獲取Expertise,SubExpertise或兩者。

+0

謝謝 - 今天我也開始考慮是否有一個實體不會讓事情變得更簡單 - 我會嘗試一下,一旦它有效,我會將您的答案標記爲已接受! :) –

1

如果實體SubExpertise在您的域模型中沒有意義,Jigal的答案對您的場景來說是完美的。如果它確實有意義,那麼可以在Extbase中使用單個表繼承來實現該目的。

class Expertise extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity 
{ 
    // all common properties 
} 

class SubExpertise extends Expertise 
{ 
    /** 
    * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\[YourVendorName]\Appoints\Domain\Model\Expertise> 
    */ 
    protected $expertises; 

    public function __construct() 
    { 
     $this->expertises = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); 
    } 

    public function getExpertises() {} 
    public function setExpertises($expertises) {} 
} 

通過Typo腳本,那麼你必須定義映射規則,因爲這兩個ExpertiseSubExpertise將被存儲在同一個表tx_appoints_domain_model_subexpertise

您可以在Extbase book中找到有關單個表繼承的更多詳細信息。

+0

謝謝你的替代 - 當我終於有一段時間了,我會更深入地閱讀這兩種方法,並取決於哪一個更適合我執行,我會選擇接受的答案:) –