2017-04-27 24 views
0

我想存储在我的D8数据库加密的数据,并解密它显示给授权用户:Drupal的8节点 - >的setTitle

use \Defuse\Crypto\Key; 
use \Defuse\Crypto\Crypto; 

function my_module_node_load($nodes) {  
    $key = loadEncryptionKeyFromConfig(); 
    $title = $nodes[1]->getTitle(); // $title is "def369u8765" 
    $decrypted_title = Crypto::decrypt($title, $key); //$decrypted_title is 'a test note' 
    $nodes[1]->setTitle($decrypted_title); 
    $nodes[1]->getTitle(); // returns 'a test note' 
    return $nodes; 
} 

当它实际上被显示我的网页上,它仍然是加密版本。在db中,node_field_revision仍然显示加密版本,并且时间戳记自昨天起保持不变。

我在做什么错?我应该如何返回解密版本?

我不想在我的数据库中解密它。它必须在磁盘上保持加密。编辑:我添加$节点[1] - >保存();并且它(可预测地)进入了无限循环,因为node_load作为save()过程的一部分被调用。

编辑:我知道我不应该硬编码[1]!一旦我得到了这个节点,我将把它放到$节点中所有节点的循环中。

回答

1

原来,缓存让我感到沮丧 - 代码工作正常。

drupal cr all 

诀窍。

我是新来的Drupal X,不要评判我

0

我也有类似的这类要求,使用

use Drupal\views\Views; 
function my_module_node_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) { 

// parse node $build 

} 

或预处理主题钩解决

function themename_preprocess_node(&$variables) { 
}