The combination of Relationships and Contextual filters to make it work isn't random, it actually follows your requirements just as you've written them, you only need to add them to your Views configuration the way you describe.
How Views types work
You want a list of nodes, that is why you create a Content Views Display. Content Views display information that is stored on nodes. When a node has an Entity reference field, that field stores only the information about what entity that is, usually the entity ID. For example, when referencing files what is stored in the Entity file reference field is the FID. The node (the node's table in the database) doesn't store anything more about that field.
The entity that is being referenced may have fields of its own. These fields are stored with the entity data (in the database they are stored in the related "entity table"). Simply put; nodes have their own tables of data, other entities have their own separate tables of data. The connections between nodes and other entities can be done through small "bridges" that are Entity reference fields that store only the connection between two IDs.
When you create Views of a certain type, you're basically choosing which entity database table to pull information from. To overly simplify for clarity: If you want to list nodes, views set nodes table and you can only show data stored in nodes, if you want to list documents, views set files table and you can only show data stored in files.
How to show referenced data in Views
But what if you want to show more information about the related entities, like in your case? You need to add Relationships towards the related entities. Relationships make other database tables data available into your Views!
Once you add some related entity Relationship to your Views you will see new options appear under Fields and Filters, options related to the referenced entity, options you didn't have before you added the Relationship.
And that is what you need to do to your Content Views. Your content references some Files and you want files data to be available in your content views. If you wanted to list content that shares the same file reference you would then add another Relationship, the "backwards" Relationship pointing towards the content that uses the file field we added the Relationship to, and add a Contextual filter that uses that second "backwards" Relationship.
How to show data that is referenced by referenced data
But in your case, there is one extra layer of connection, and you need to add 2 more Relationships. You're not matching the referenced files, you're matching the taxonomy terms that are referenced from files that are referenced from content:
Page > File > Term < Other Files < Other Pages
Here are the steps for your case:
- Create Content Views Block Display listing Page nodes
- Add Relationship towards your "Linked Document" field, you can require it since you won't have nodes with empty document field in the results
Add another Relationship Taxonomy term referenced from field_document, it will use the first Relationship automatically, you can require it since that field won't be empty either, so you won't be excluding any nodes you don't need to if you require it
So far we've been going in the direction from nodes to their referenced files, to terms referenced from those files.
Now we have all that information in Views, we can start matching "backwards" to get term siblings and file second cousins.
- Add the third Relationship Taxonomy term using field_document_tag and make it use the second Relationship. You can require it
Add the fourth Relationship Content using field_document and make it use the third Relationship, you can require it
This fourth Relationship is pointing to nodes that reference files that refrence terms that are referenced from files that are referenced from nodes listed in this Views.
- Now we can add a Contextual ID filter from
Content
Category, and configure it:
Make it use the fourth Relationship (the only one available)
When the filter value is NOT available
Provide default value
Content ID from URL
When the filter value IS available or a default is provided
Specify validation criteria
Content
Basic Page
Hide View if the argument doesn't validate, or some other options that makes sense to you.
- Place the Block on Basic pages, adjust the
Node from URL
and other Block options.
Remove the current node from the list
The node you're currently viewing will also be listed. To Exclude it add the second Contextual ID filter:
When the filter value is NOT available
Provide default value
Content ID from URL
More
Exlude