小编Asm*_*pih的帖子

允许在树枝中的沙箱策略中使用新方法(drupal 8)

使用“字段收集”模块时出现此错误:

 Twig_Sandbox_SecurityError: Calling "uri" method on a "Drupal\field_collection\Entity\FieldCollectionItem" object is not allowed in "themes/communitylife/templates/content/node.html.twig" at line 83. in Drupal\Core\Template\TwigSandboxPolicy->checkMethodAllowed() (line 99 of core/lib/Drupal/Core/Template/TwigSandboxPolicy.php).
Run Code Online (Sandbox Code Playgroud)

导致问题的代码是以下代码:

<div class=" title-col col-md-7">

     <a  href="{{file_url(node.field_pressemappe_bildmaterial[key].getFieldCollectionItem().field_presse_bild_file.entity.uri.value)}}" target="_blank"> <strong> {{node.field_pressemappe_bildmaterial[key].getFieldCollectionItem().field_presse_bild_description.value}}

      <span class="file-type"> ({{node.field_pressemappe_bildmaterial[key].getFieldCollectionItem().field_presse_bild_file.entity.uri.value | slice(-3) }} </span>, <span class="file-size"> {{node.field_pressemappe_bildmaterial[key].getFieldCollectionItem().field_presse_bild_file.entity.size }}) </span> 

      </strong></a>

</div>
Run Code Online (Sandbox Code Playgroud)

解决此问题的最佳方法是什么?通过在沙箱策略的允许方法中添加(uri)来实现?如果是,那我该怎么做?

我在树枝文档中阅读到可以执行以下操作:

    $policy = new Twig_Sandbox_SecurityPolicy($tags, $filters, $methods, $properties, $functions);
Run Code Online (Sandbox Code Playgroud)

但我不知道如何或在何处放置此代码。

提前致谢

symfony twig drupal-8 twig-extension

2
推荐指数
1
解决办法
851
查看次数

标签 统计

drupal-8 ×1

symfony ×1

twig ×1

twig-extension ×1