php - 在 Drupal 8 中更改节点主体
问题描述
我正在尝试更改我所有文章节点的内容以在第一段之后插入一个 div。
我目前正在使用钩子:hook_entity_view_alter
function bcom_advertising_entity_view_alter(array &$build, Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display) {
$text = $build['body'][0]['#text'];
$end_of_paragraph = strpos($text, '</p>');
insertSlimcutDiv($end_of_paragraph, $build['body'][0]['#text']);
}
在 insertSlimcutDiv 函数中,我可以先插入一些东西
如果我添加普通文本,它会起作用,如果我添加一个 div,它会被 Drupal 删除。
知道我应该如何处理这个问题吗?
谢谢你的帮助!
解决方案
我设法通过改变正文的文本格式来解决这个问题,如下所示:
$build['body'][0]['#format'] = "full_html";
内部 hook_entity_view_alter
推荐阅读
- javascript - JavaScript 查找是否有任何具有特定类的 div 被悬停,然后识别确切的 div
- python - 使用 OOP Python 读取 CSV
- reactjs - React 组件与函数,我应该使用什么,为什么?
- android - 访问 EditText ID 数据返回 Null
- debugging - 如何在 web2py 中启用调试?
- python - 在不同列中比较 Pandas DataFrame 中的前行值
- r - 根据R中另一行的值选择行
- java - 如何在 Android Studio 中实现 Parcelable 多个类
- jenkins - 当我们执行命令“npm run
--silent" 在詹金斯它失败了 - aggregate - 在 Traefik 中聚合两个 API 的结果