2016-10-10 50 views
0

在tx_news中,還可以通過將TypoScript的名稱添加到overrideFlexformSettingsIfEmpty來設置所有插件設置。顧名思義,只有在任何插件化身的相應Flexform字段爲空時,纔會使用這些基於TS的設置。這是我想要的和我需要的。它允許可以在每個插件元素中重寫的基本TS配置。useStdWrap與tx_news中的overrideFlexformSettingsIfEmpty的衝突

現在,這裏的問題:

正如我的TS默認值需要更復雜的計算,我也激活useStdWrap對於一些tx_news設置字段。但是我發現永遠都會使用活動的stdWrap--無論是否存在Flexform設置。

我需要的是使用TS stdWrap來計算默認值的可能性,但是如果定義了Flexform設置,它應該總是覆蓋TS設置(不管它們的計算有多複雜以及是否包含stdWrap操作)。

下面是一個例子:

plugin.tx_news.settings { 
    overrideFlexformSettingsIfEmpty := addToList(categories) 
    useStdWrap := addToList(categories) 

    categories.data = GP:cat 
    categories.ifEmpty = 1 
} 

我希望這個TS設置從查詢字符串參數(CAT)的任何消息插件的類別,並回落到1類,但只有如果有在插件本身中沒有設置任何類別。

stdWrap操作(。數據和.ifEmpty)總是踢,也沒有辦法再使用的柔性成型設置。

有沒有辦法解決這個問題?

回答

1

沒有辦法爲每個人解決這個問題,因爲如果它會改變的話,還會有其他的缺點。

一個解決方案是使用鉤子$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['Controller/NewsController.php']['overrideSettings'],您可以在PHP中操縱您所需的所有設置。

+0

嗨喬治,我已經接受了你的回答。但我不同意你的評估,沒有辦法解決這個問題。我已經在下面發佈了我自己的解決方案,它可以將其全部添加到EXT新聞中。您需要確保所有useStdWrapped字段在插件中定義的設置都被設置爲通過stdWrap處理的TS對象的默認內容。這不會與任何現有的新聞實現衝突,因爲useStdWrapped字段的默認內容無論如何都被破壞了(如問題[#126](https://github.com/georgringer/news/issues/126)中所述)。 – Jpsy

1

我已經接受Georgs答案,但選擇了另一種方式來解決這個問題:

我創建了一個PHP類,讀取並返回類別任何給定的tx_news插件化身的設置,並允許將它們合併回useStdWrap處理。

要使用此方法,最好創建一個基本的自定義擴展,將PHP類文件放入其Classes文件夾。這裏有這樣一類文件的代碼,存儲爲/your_extension/Classes/TsSetupHelper.php:

<?php 
namespace YourVendor\YourExtension; 

class TsSetupHelper { 

    /** 
    * Reference to the parent (calling) cObject set from TypoScript 
    */ 
    public $cObj; 


    /** 
    * Return the categories chosen in a tx_news plugin content element. 
    * Can be used in TS Setup to stdWrap the categories without losing the settings defined within a plugin incarnation. 
    * 
    * @param string   Empty string (no content to process) 
    * @param array   TypoScript configuration 
    * @return string   return categorie value list from plugin in page, e.g.: '1,3,4' 
    */ 
    public function getNewsPluginCategory($content, $conf) { 

     $newsPluginFlexformArr = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($this->cObj->data['pi_flexform']); 
     $newsPluginCategories = $newsPluginFlexformArr['data']['sDEF']['lDEF']['settings.categories']['vDEF']; 

     return $newsPluginCategories; 
    } 
} 

有了這個類的地方,你可以在TS安裝一個插件tx_news化身選擇的類別看,使用stdWrap處理它們並將它們作爲更新後的類別值推回到插件中。

下面是相應TS設置代碼的示例。

plugin.tx_news.settings { 
    overrideFlexformSettingsIfEmpty := addToList(categories,categoryConjunction) 
    useStdWrap := addToList(categories) 
    categoryConjunction = or 

    # pre fill categories with value from plugin in page 
    categories.cObject = USER 
    categories.cObject { 
     userFunc = YourVendor\YourExtension\TsSetupHelper->getNewsPluginCategory 
    } 
    # only if no categories are chosen within plugin, 
    # use TS to define categories: 
    categories.ifEmpty { 
     # get cat from parameter in query 
     data = GP:cat 
     # ignore cat parameter if page layout 5 is chosen in page properties 
     override = 1,2,3,4,5,6,7,8,9,10 
     override.if.value.data = page:layout 
     override.if.equals = 5 
     # default categories to 3 if cat param is not set 
     ifEmpty = 3 
    } 
} 

我們在這裏做了很多花哨的東西。這都是作爲一個例子。重要的部分是,插件中的類別設置優先,並且僅在categories.ifEmpty{...}塊中的所有TS設置才被使用,如果在插件中沒有正確設置類別。

在寫這篇文章時的版本:TYPO3 7.6.11,tx_news 5.2.0