TYPO3 8在textmedia的后端预览中显示布局选择 [英] TYPO3 8 show layout selection in backend preview for textmedia

查看:94
本文介绍了TYPO3 8在textmedia的后端预览中显示布局选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I try to use and customize the CTypes of fluid_styled_content as much as possible. 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.

是否可以在textmedia的后端预览中的布局字段中显示所选值?

Is there a way to show the selected value the layout field in backend preview for textmedia?

推荐答案

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

To get this done register a hook (path: yourextension/Classes/Hooks/PageLayoutView/TextMediaCustomPreviewRenderer.php) like that:

    <?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中,您应该这样输入:

And in your ext_localconf.php you put like that:

    // 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中提供了select的不同选项,如下所示:

In my case I offer the different options of the select in pageTsconfig like that:

    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使用正确的语言处理的更好方法.如果那样做,也许您需要稍微更改一下代码示例...

It is the better way to use correct language handling by locallang.xlf for that. If you do it like that maybe you have to change the code example a bit...

这是Facebook上"TYPO3 Fragen,Antworten,inoffizielle Gruppe"上一个话题的结果.非常感谢沃尔夫冈·克林格(Wolfgang Klinger)的所有帮助:-)

This was the result of a thread at "TYPO3 Fragen, Antworten, inoffizielle Gruppe" on Facebook. Thanks a lot to every helping hand specially to Wolfgang Klinger :-)

这篇关于TYPO3 8在textmedia的后端预览中显示布局选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆