Mykola Veryha Asked:2020-03-28 23:19:52 +0000 UTC2020-03-28 23:19:52 +0000 UTC 2020-03-28 23:19:52 +0000 UTC 如何更改 Drupal 8 中的图像类型字段? 772 我需要在保存时将 alt 和 title 参数更新为图像。避免手动生成这些参数 drupal 1 个回答 Voted Best Answer Mykola Veryha 2020-03-28T23:19:52Z2020-03-28T23:19:52Z 解决方案: /** * Implements hook_node_presave(). */ function MODULE_node_presave(Drupal\Core\Entity\EntityInterface $node) { if ($node->getType() == 'press_release') { $title = $node->getTitle(); $images = $node->get('field_image')->getValue(); $first_image = reset($images); $first_image['alt'] = $title; $first_image['title'] = $title; $node->field_image->setValue($first_image); } } 可以在此处找到更多详细信息,以 编程方式将文件附加到 Drupal 8 中的节点
解决方案:
可以在此处找到更多详细信息,以 编程方式将文件附加到 Drupal 8 中的节点