简体   繁体   English

TYPO3 8在textmedia的后端预览中显示布局选择

[英]TYPO3 8 show layout selection in backend preview for textmedia

I try to use and customize the CTypes of fluid_styled_content as much as possible. 我尝试尽可能地使用和自定义fluid_styled_content的CType。 Therefore the select-field "Layout" is very useful to have a possibility to select some different styles (like red box, shadow, or image-stuff). 因此,选择字段“布局”非常有用,可以选择一些不同的样式(例如红色框,阴影或图像填充)。 But if you have some possibilities to select it is not shown in backend preview an every element is looking the same. 但是,如果您有选择的余地,它不会显示在后端预览中,则每个元素看起来都一样。

Is there a way to show the selected value the layout field in backend preview for textmedia? 有没有一种方法可以在textmedia的后端预览中在布局字段中显示所选值?

To get this done register a hook (path: yourextension/Classes/Hooks/PageLayoutView/TextMediaCustomPreviewRenderer.php) like that: 为此,请注册一个钩子(路径: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;
      }
   }
}

And in your ext_localconf.php you put like that: 然后在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;

In my case I offer the different options of the select in pageTsconfig like that: 就我而言,我在pageTsconfig中提供了select的不同选项,如下所示:

    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
}

It is the better way to use correct language handling by locallang.xlf for that. 这是通过locallang.xlf使用正确的语言处理的更好方法。 If you do it like that maybe you have to change the code example a bit... 如果那样做,也许您需要稍微更改一下代码示例...

This was the result of a thread at "TYPO3 Fragen, Antworten, inoffizielle Gruppe" on Facebook. 这是Facebook上“ TYPO3 Fragen,Antworten,inoffizielle Gruppe”上一个话题的结果。 Thanks a lot to every helping hand specially to Wolfgang Klinger :-) 非常感谢沃尔夫冈·克林格(-)的所有帮助之手:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM