[英]Drupal 8: How to unpublish node when user clicked on Delete button
在我的网站上,用户可以添加内容和编辑内容。 在编辑页面上,有一个删除按钮可以删除内容,但我想使用该按钮来向用户和公众隐藏/取消发布内容。
I have tried the below code but it is deleting the content.
function test_entity_predelete(Drupal\Core\Entity\EntityInterface $entity) {
$nid = $entity->id();
$node =Node::load($nid);
$node->setPublished(FALSE);
$node->save();
}
您可以尝试使用 hook_form_alter() 覆盖操作按钮。
$form['actions']['delete']
而是使用您自己的标准动作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.