在自定义模块中,我正在根据来自另一个字段的条目来验证一个字段。当哈希被硬编码(即// $bookhash = 1;
)时,验证工作。但是,我似乎无法弄清楚如何访问参考书的哈希值。
从 book_signatures 中引用的书中访问该数据的正确方法是什么?
use \Drupal\Core\Entity\EntityTypeInterface;
/**
* Implements hook_entity_bundle_field_info_alter().
*/
function custom_validation_entity_bundle_field_info_alter(&$fields, \Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle) {
if ($bundle === 'book_signatures') {
if (isset($fields['field_confirm_book_hash'])) {
$book = $fields['field_book']; // book is a referenced entity within book_signatures.
$bookhash = $book->field_hash_check; // need to set this equal to the hash in the book entity.
// $bookhash = 1; works with static hash. need specific books hash
$fields['field_confirm_book_hash']->addConstraint('BookHash', ['hash' => $bookhash]);
}
}
}
编辑:来自开发领域的输出$fields['field_book']。它的 id 输出“node.book_signatures.field_book”