0

我尝试尽可能多地使用和自定义 fluid_styled_content 的 CType。因此,选择字段“布局”非常有用,可以选择一些不同的样式(如红色框、阴影或图像内容)。但是,如果您有一些选择的可能性,它不会显示在后端预览中,每个元素看起来都一样。

有没有办法在 textmedia 的后端预览中显示布局字段的选定值?

4

1 回答 1

1

要完成此操作,请注册一个钩子(路径:yourextension/Classes/Hooks/PageLayoutView/TextMediaCustomPreviewRenderer.php),如下所示:

    <?php
namespace Vendor\Yourextension\Hooks\PageLayoutView;

/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

use \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
use \TYPO3\CMS\Backend\View\PageLayoutView;

/**
 * Contains a preview rendering for the page module of CType="textmedia"
 */
class TextMediaCustomPreviewRenderer implements PageLayoutViewDrawItemHookInterface
{

   /**
    * Preprocesses the preview rendering of a content element of type "Text Media"
    *
    * @param \TYPO3\CMS\Backend\View\PageLayoutView $parentObject Calling parent object
    * @param bool $drawItem Whether to draw the item using the default functionality
    * @param string $headerContent Header content
    * @param string $itemContent Item content
    * @param array $row Record row of tt_content
    *
    * @return void
    */
   public function preProcess(
      PageLayoutView &$parentObject,
      &$drawItem,
      &$headerContent,
      &$itemContent,
      array &$row
   )
   {
      $pageTs = \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($row['pid']);
      if ($row['CType'] === 'textmedia') {
         $itemContent .= '<p>Layoutversion: ' . $pageTs['TCEFORM.']['tt_content.']['layout.']['types.']['textmedia.']['addItems.'][$row['layout']] . '</p>';

         if ($row['bodytext']) {
             $itemContent .= $parentObject->linkEditContent(
                     $parentObject->renderText($row['bodytext']),
                     $row
                 ) . '<br />';
         }
         if ($row['assets']) {
             $itemContent .= $parentObject->thumbCode($row, 'tt_content', 'assets') . '<br />';
         }
         $drawItem = false;
      }
   }
}

在你的 ext_localconf.php 中你这样写:

    // Register for hook to show preview of tt_content element of CType="textmedia" in page module
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem']['textmedia'] = \Vendor\Yourextension\Hooks\PageLayoutView\TextMediaCustomPreviewRenderer::class;

就我而言,我在 pageTsconfig 中提供了不同的选择选项,如下所示:

    TCEFORM.tt_content.layout.types.textmedia.addItems {
    50 = Textbox grau, Bildergalerie oben
    60 = Textbox grau, Bildergalerie unten
    110 = Blau, rechtsbündig
    210 = Hellblau, linksbündig
    220 = Rot, linksbündig
    310 = Akkordeon
}

这是使用 locallang.xlf 正确语言处理的更好方法。如果您这样做,也许您必须稍微更改代码示例...

这是 Facebook 上“TYPO3 Fragen, Antworten, inoffizielle Gruppe”的帖子的结果。非常感谢沃尔夫冈·克林格 (Wolfgang Klinger) 的每一位帮助 :-)

于 2018-02-23T09:00:27.103 回答