Problem/Motivation
Creating the PHPUnit test we saw that the auto reference links are not listed, maybe we should create a subcategory called auto-reference or similar, and include on the table.
Steps to reproduce
Example extracted from PHPUnit test:
// Create HTML content containing various link scenarios.
$html = '
<p>External link: <a href="https://example.com">Example</a></p>
<p>Internal valid link: <a href="/node/1">Internal Node</a></p>
<p>Broken link: <a href="/non-existent">Broken</a></p>
<p>Iframe content: <iframe src="https://example.com/iframe"></iframe></p>
';
// Create a node entity in English.
$node_en = Node::create([
'type' => 'page',
'title' => 'Test Node EN',
'nid' => 1,
'body' => [
'value' => $html,
'format' => 'basic_html',
],
'langcode' => 'en',
]);
$node_en->save();
// Create a node entity in French.
$node_fr = Node::create([
'type' => 'page',
'title' => 'Test Node FR',
'nid' => 2,
'body' => [
'value' => $html,
'format' => 'basic_html',
],
'langcode' => 'fr',
]);
$node_fr->save();
$connection = $this->container->get('database');
$query = $connection->select('entity_mesh', 'em')
->fields('em', [
'id',
'type',
'category',
'subcategory',
'source_entity_type',
'source_entity_bundle',
'source_entity_id',
'source_entity_langcode',
'source_title',
'target_href',
'target_path',
'target_link_type',
'target_entity_type',
'target_entity_bundle',
'target_entity_id',
'target_entity_langcode',
'target_title',
]);
$results = $query->execute()->fetchAllAssoc('id', \PDO::FETCH_ASSOC);
Links:
Array
(
[1] => Array
(
[id] => 1
[type] => entity_render
[category] => link
[subcategory] => link
[source_entity_type] => node
[source_entity_bundle] => page
[source_entity_id] => 1
[source_entity_langcode] => en
[source_title] => Test Node EN (node - 1)
[target_href] => https://example.com
[target_path] =>
[target_link_type] => external
[target_entity_type] =>
[target_entity_bundle] =>
[target_entity_id] =>
[target_entity_langcode] =>
[target_title] => https://example.com (external)
)
[2] => Array
(
[id] => 2
[type] => entity_render
[category] => link
[subcategory] => broken-link
[source_entity_type] => node
[source_entity_bundle] => page
[source_entity_id] => 1
[source_entity_langcode] => en
[source_title] => Test Node EN (node - 1)
[target_href] => /non-existent
[target_path] => /non-existent
[target_link_type] => internal
[target_entity_type] =>
[target_entity_bundle] =>
[target_entity_id] =>
[target_entity_langcode] =>
[target_title] => /non-existent ()
)
[3] => Array
(
[id] => 3
[type] => entity_render
[category] => iframe
[subcategory] => iframe
[source_entity_type] => node
[source_entity_bundle] => page
[source_entity_id] => 1
[source_entity_langcode] => en
[source_title] => Test Node EN (node - 1)
[target_href] => https://example.com/iframe
[target_path] =>
[target_link_type] => external
[target_entity_type] =>
[target_entity_bundle] =>
[target_entity_id] =>
[target_entity_langcode] =>
[target_title] => https://example.com/iframe (external)
)
[4] => Array
(
[id] => 4
[type] => entity_render
[category] => link
[subcategory] => link
[source_entity_type] => node
[source_entity_bundle] => page
[source_entity_id] => 2
[source_entity_langcode] => fr
[source_title] => Test Node FR (node - 2)
[target_href] => https://example.com
[target_path] =>
[target_link_type] => external
[target_entity_type] =>
[target_entity_bundle] =>
[target_entity_id] =>
[target_entity_langcode] =>
[target_title] => https://example.com (external)
)
[5] => Array
(
[id] => 5
[type] => entity_render
[category] => link
[subcategory] => link
[source_entity_type] => node
[source_entity_bundle] => page
[source_entity_id] => 2
[source_entity_langcode] => fr
[source_title] => Test Node FR (node - 2)
[target_href] => /node/1
[target_path] => /node/1
[target_link_type] => internal
[target_entity_type] => node
[target_entity_bundle] => page
[target_entity_id] => 1
[target_entity_langcode] =>
[target_title] => Test Node EN (node - 1)
)
[6] => Array
(
[id] => 6
[type] => entity_render
[category] => link
[subcategory] => broken-link
[source_entity_type] => node
[source_entity_bundle] => page
[source_entity_id] => 2
[source_entity_langcode] => fr
[source_title] => Test Node FR (node - 2)
[target_href] => /non-existent
[target_path] => /non-existent
[target_link_type] => internal
[target_entity_type] =>
[target_entity_bundle] =>
[target_entity_id] =>
[target_entity_langcode] =>
[target_title] => /non-existent ()
)
[7] => Array
(
[id] => 7
[type] => entity_render
[category] => iframe
[subcategory] => iframe
[source_entity_type] => node
[source_entity_bundle] => page
[source_entity_id] => 2
[source_entity_langcode] => fr
[source_title] => Test Node FR (node - 2)
[target_href] => https://example.com/iframe
[target_path] =>
[target_link_type] => external
[target_entity_type] =>
[target_entity_bundle] =>
[target_entity_id] =>
[target_entity_langcode] =>
[target_title] => https://example.com/iframe (external)
)
)
Comments
Comment #2
gedur commentedProbably having a subtype, and the possibility to ignore them by config is the way to go.
Auto references on pages with several anchors could increase database size dramatically, and probably the information provided is no as important as if the node is analyzed (user has access) it is proof that the self-reference link works also.