Почему TYPO3 9.5.x Fluid Viewhelper f: security работает только в Default.html, но не в List.html? - PullRequest
0 голосов
/ 21 ноября 2018

В TYPO3 9.5.x этот код работает в шаблоне Layout / Default.html моего расширения extbase.Но тот же код не работает ни в одном другом шаблоне, например в шаблоне List.html.Я не получаю любой вывод viewhelper, когда я использую его там.В TYPO3 8.x он работает в каждом шаблоне, а не только в Default.html.Есть ли для этого веская причина?Как я могу использовать f: security внутри партиалов и шаблонов, которые не являются Layout / Default.html?

<f:security.ifHasRole role="2">
                <f:then>
                    <p>CHECK RIGHTS role=2</p>
                </f:then>
                <f:else>
                    <p>CHECK RIGHTS role=not2</p>
                </f:else>
</f:security.ifHasRole>

То же самое с этим кодом, поэтому он не имеет ничего общего с f: else:

<f:security.ifAuthenticated>
            <p>I AM LOGGED IN, but it does not show up :( </p>
</f:security.ifAuthenticated>

Layout / Default.html:

<html xmlns:f="https://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
    <f:security.ifHasRole role="2">
        <p>ROLE is 2 in Default.html, this  gets rendered as expected</p>
    </f:security.ifHasRole>
    <div class="container">
        <f:debug title="Debug" maxDepth="12">{_all}</f:debug>
        <f:render section="content" />
    </div><!-- /container -->
</html>

Шаблоны / Статистика / List.html

<html xmlns:f="https://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
    <f:layout name="Default" />

    This Template is responsible for creating a table of domain objects.

    If you modify this template, do not forget to change the overwrite settings
    in /Configuration/ExtensionBuilder/settings.yaml:
    Resources:
    Private:
    Templates:
    List.html: keep

    Otherwise your changes will be overwritten the next time you save the extension in the extension builder

    <f:section name="content">
        <h3>Anruf-Statistiken</h3>
        <f:flashMessages />
        <div style="float:right; clear:both;"><f:link.action action="export" controller="Statistic" pluginName="Run"><button type="button" class="btn btn-xs btn-default">Tabelle für Excel speichern (CSV-Export)</button></f:link.action></div>



        <table style="padding: 1em; margin-top:2em; width:100%;" class="tx_srv2" >
            <tr>
                <th style="padding: 1em;">ID</th>
                <th style="padding: 1em;">Timestamp</th>
                <th style="padding: 1em;"><f:translate key="tx_srv2_domain_model_statistic.agent" /></th>
            <th style="padding: 1em;"><f:translate key="tx_srv2_domain_model_statistic.status" /></th>
            <th style="padding: 1em;"><f:translate key="tx_srv2_domain_model_statistic.campaigntitle" /></th>
            <th style="padding: 1em;"><f:translate key="tx_srv2_domain_model_statistic.duration" /> (sec.)</th>
            <th style="padding: 1em;"><f:translate key="tx_srv2_domain_model_statistic.comment" /></th>
            </tr>
            <f:widget.paginate objects="{statistics}" configuration="{itemsPerPage: 10, insertBelow:1}" as="paginatedStatistics">
                <f:for each="{paginatedStatistics}" as="statistic">
                    <tr>
                        <td style="padding: 1em;">{statistic.uid}</td>
                        <td style="padding: 1em;"><f:format.date format="Y-m-d H:i:s">{statistic.crdate}</f:format.date></td>
                    <td style="padding: 1em;">{statistic.agent.username}</td>
                    <td style="padding: 1em;">{statistic.status}</td>
                    <td style="padding: 1em;">{statistic.campaigntitle}</td>
                    <td style="padding: 1em;">{statistic.duration}</td>
                    <td style="padding: 1em;">{statistic.comment}</td>
                    </tr>
                </f:for>
            </f:widget.paginate>
        </table> 
        <f:security.ifAuthenticated>
            <f:then>
                This part should be shown if there is a frontend user logged in, but it never shows up.
            </f:then>
            <f:else>
                This part should be shown if the current user is not logged in., but it also doesnt show up.
            </f:else>
        </f:security.ifAuthenticated>
    </f:section>
</html>

В веб-интерфейсе нет содержимого из части f: security в List.HTML обрабатывается, но часть f: security из Default.html обрабатывается.И обычный вывод из List.html, который является списком объектов, отображается как ожидалось.

Ответы [ 3 ]

0 голосов
/ 18 января 2019

в TYPO3 9.5.x кажется, что ViewHelper возвращает только логическое значение и не отображает теги «then» или «else».Это работает для меня:

<f:if condition="{f:security.ifHasRole( role: '9')}">
<f:then>
yes
</f:then>
<f:else>
no
</f:else>
</f:if>
0 голосов
/ 24 июля 2019
У

была эта проблема в 9.5.2, и проверка роли не была возможной, вот как я обошел ее с помощью расширения vhs:

<f:security.ifAuthenticated>
    <f:then>
        <v:variable.set name="isLoggedIn" value="true"/>
    </f:then>
</f:security.ifAuthenticated>

<f:if condition="{isLoggedIn}">
    <f:then>### Logged In ###</f:then>
    <f:else>### Not Logged In ###</f:else>
</f:if>

Хитрость заключалась в том, что Viewhelper былвозможность делать то, что находится в блоке f:then, но не то, что находится в блоке f:else, поэтому я создал переменную, которая устанавливается только в блоке f:then, и позже проверим наличие этой переменной.

0 голосов
/ 21 ноября 2018

Использование выглядит отлично.

f:security ViewHelpers работает только в веб-интерфейсе.Если вы находитесь в области действия бэкэнда, вам нужно использовать f:be.security эквивалентов.Если это не решит проблему, не могли бы вы предоставить код шаблона, где используется неисправный ViewHelper?

...