2017-04-27 25 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) { 
}