I have a content type names Link in which contains only a link field. I want to rewrite the title link to the external link(link field's value),but I couldn't get link field's value under hook_views_pre_render, although I could get title,body,created... value without any problem ,I just couldn't get the value of link field which I added to the content type. core: Drupal 10
Blockquote Drupal\views\ResultRow {#11171 ▼ +_entity: Drupal\node\Entity
Node {#11292 ▼ #entityTypeId: "node" #enforceIsNew: null #typedData: null #cacheContexts: [] #cacheTags: [] #cacheMaxAge: -1 #_serviceIds: [] #_entityStorages: [] #values: array:21 [▼ "nid" => array:1 [▶] "vid" => array:1 [▶] "type" => array:1 [▶] "uuid" => array:1 [▶] "langcode" => array:1 [▶] "revision_uid" => array:1 [▶] "revision_timestamp" => array:1 [▶] "revision_log" => array:1 [▶] "revision_default" => array:1 [▶] "isDefaultRevision" => array:1 [▶] "status" => array:1 [▶] "uid" => array:1 [▶] "title" => array:1 [▶] "created" => array:1 [▶] "changed" => array:1 [▶] "promote" => array:1 [▶] "sticky" => array:1 [▶] "default_langcode" => array:1 [▶] "revision_translation_affected" => array:1 [▶] "field_comment2" => array:1 [▶] "field_link" => array:1 [▶] ] #fields: [] #fieldDefinitions: null #languages: null #langcodeKey: "langcode" #defaultLangcodeKey: "default_langcode" #activeLangcode: "x-default" #enforceDefaultTranslation: null #defaultLangcode: "en" #translations: array:1 [▶] #translationInitialize: false #newRevision: false #isDefaultRevision: "1" #entityKeys: array:4 [▶] #translatableEntityKeys: array:8 [▶] #validated: false #validationRequired: false #loadedRevisionId: "214" #revisionTranslationAffectedKey: "revision_translation_affected" #enforceRevisionTranslationAffected: [] #isSyncing: false +in_preview: null } +_relationship_entities: array:1 [▶] +index: 0 +"node_field_data_created": "1718470654" +"nid": "214" +"users_field_data_node_field_data_uid": "36" } ... Blockquote
function showcontent_views_pre_render(ViewExecutable $view){
// Check if we are working with the correct view and display.
if ($view->id() == 'newest' ) {
// Iterate through the rendered result to find the title field and rewrite it.
foreach ($view->result as $key => $row) {
if($row->_entity->hasField('field_link')){
$current_title = $row->_entity->get('title')->value;
dpm($current_title); //get node title
$external_link_uri = $row->_entity->get('field_link')->value;
dpm($external_link_uri); //get null value
}else{
}
}
}
}