Comments

Status: Needs review » Needs work

The last submitted patch, der.views_.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new3.11 KB
new11.16 KB

With test fix.

jibran’s picture

Title: Adds views relationship » Provide a relationship for each dynamic entity reference field

Status: Needs review » Needs work

The last submitted patch, 2: der.views-2321721-2.patch, failed testing.

Status: Needs work » Needs review

jibran queued 2: der.views-2321721-2.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 2: der.views-2321721-2.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review

Well this passes locally.

jibran queued 2: der.views-2321721-2.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 2: der.views-2321721-2.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new11.16 KB

Status: Needs review » Needs work

The last submitted patch, 10: der.views-2321721-2.patch, failed testing.

Status: Needs work » Needs review

jibran queued 10: der.views-2321721-2.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 10: der.views-2321721-2.patch, failed testing.

Status: Needs work » Needs review

jibran queued 10: der.views-2321721-2.patch for re-testing.

jibran queued 2: der.views-2321721-2.patch for re-testing.

The last submitted patch, 2: der.views-2321721-2.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 10: der.views-2321721-2.patch, failed testing.

jibran queued 2: der.views-2321721-2.patch for re-testing.

The last submitted patch, 2: der.views-2321721-2.patch, failed testing.

jibran queued 2: der.views-2321721-2.patch for re-testing.

The last submitted patch, 2: der.views-2321721-2.patch, failed testing.

Status: Needs work » Needs review

jibran queued 10: der.views-2321721-2.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 10: der.views-2321721-2.patch, failed testing.

Status: Needs work » Needs review

jibran queued 10: der.views-2321721-2.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 10: der.views-2321721-2.patch, failed testing.

jibran queued 2: der.views-2321721-2.patch for re-testing.

Status: Needs work » Needs review

jibran queued 10: der.views-2321721-2.patch for re-testing.

The last submitted patch, 2: der.views-2321721-2.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 10: der.views-2321721-2.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new3.25 KB
new11.29 KB

Keeping up with the core.

Status: Needs review » Needs work

The last submitted patch, 30: der.views-2321721-28.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new957 bytes
new11.45 KB

Just debugging.

jibran’s picture

jibran’s picture

StatusFileSize
new11.45 KB

Status: Needs review » Needs work

The last submitted patch, 34: der.views-2321721-30.patch, failed testing.

Status: Needs work » Needs review

jibran queued 34: der.views-2321721-30.patch for re-testing.

The last submitted patch, 32: der.views-2321721-30.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 34: der.views-2321721-30.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new5.46 KB
new11.43 KB

It is broken again :/

Status: Needs review » Needs work

The last submitted patch, 39: der.views-2321721-39.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new2.32 KB
new11.43 KB

Minor fixes

Status: Needs review » Needs work

The last submitted patch, 41: der.views-2321721-41.patch, failed testing.

jibran’s picture

jibran’s picture

jibran’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 44: der.views-2321721-44.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new1.69 KB
new5.66 KB
new13.61 KB
new18.59 KB

Reroll and fixes. Core patch is dependent on join issue.

jibran’s picture

StatusFileSize
new6.55 KB
new13.01 KB

All the blockers are fixed now. Let's fix this issue as well.

larowlan’s picture

I can't see anything wrong with this, but views isn't really my area of expertise.
Is it worth pinging someone else on VDC to give this a once-over?
If not, RTBC+1

jibran queued 49: 2321721-49.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 49: 2321721-49.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new1.07 KB
new12.82 KB

Test fix.

jibran’s picture

StatusFileSize
new2.41 KB
new13.31 KB

Added some docs as per @dawehner suggestions.

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

thanks for all the effort on this

socketwench’s picture

Are all the tests disappearing after applying the patch for anyone else or am I PEBKACing?

jibran’s picture

StatusFileSize
new1.04 KB
new13.31 KB

Fixes after #2451679: Validate cache contexts (+ cache contexts in some views plugins wrong). I'll commit it once the HEAD is back green.
@socketwench everything is working fine for me.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 57: provide_a_relationship-2321721-57.patch, failed testing.

Status: Needs work » Needs review
jibran’s picture

jibran’s picture

StatusFileSize
new4.9 KB
new13.58 KB

Fixes after #2451789: Entity reference joins to the wrong base table in views.. Need to rewrite DynamicEntityReferenceRelationshipTest just like EntityReferenceRelationshipTest

Status: Needs review » Needs work

The last submitted patch, 61: provide_a_relationship-2321721-61.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new13.6 KB
new573 bytes

Copy paste fix.

jibran’s picture

StatusFileSize
new19 KB
new25.66 KB

Ok we have an issue now. I have been adding and extra condition to join which checks target type of current relationship. It works fine for single relationship but for multiple relationships join produce no result because a single value can't have two values of target types as can be seen in the resultant query.

SELECT entity_test.id AS id, entity_test_entity_test__field_test.id AS entity_test_entity_test__field_test_id, entity_test_mul_property_data_entity_test__field_test.id AS entity_test_mul_property_data_entity_test__field_test_id
FROM 
`entity_test` entity_test
LEFT JOIN `entity_test__field_test` entity_test__field_test ON entity_test.id = entity_test__field_test.entity_id AND entity_test__field_test.deleted = '0'
INNER JOIN `entity_test` entity_test_entity_test__field_test ON entity_test__field_test.field_test_target_id = entity_test_entity_test__field_test.id AND entity_test__field_test.field_test_target_type = 'entity_test'
INNER JOIN `entity_test_mul_property_data` entity_test_mul_property_data_entity_test__field_test ON entity_test__field_test.field_test_target_id = entity_test_mul_property_data_entity_test__field_test.id AND entity_test__field_test.field_test_target_type = 'entity_test_mul'
LIMIT 10 OFFSET 0

The why around this would be if we'd add WHERE clause in the query instead of extra join condition something like this.

SELECT entity_test.id AS id, entity_test_entity_test__field_test.id AS entity_test_entity_test__field_test_id, entity_test_mul_property_data_entity_test__field_test.id AS entity_test_mul_property_data_entity_test__field_test_id
FROM 
`entity_test` entity_test
LEFT JOIN `entity_test__field_test` entity_test__field_test ON entity_test.id = entity_test__field_test.entity_id AND entity_test__field_test.deleted = '0'
INNER JOIN `entity_test` entity_test_entity_test__field_test ON entity_test__field_test.field_test_target_id = entity_test_entity_test__field_test.id
INNER JOIN `entity_test_mul_property_data` entity_test_mul_property_data_entity_test__field_test ON entity_test__field_test.field_test_target_id = entity_test_mul_property_data_entity_test__field_test.id
WHERE entity_test__field_test.field_test_target_type IN ('entity_test', 'entity_test_mul')
LIMIT 10 OFFSET 0

The problem with this approach is it produced duplicate results just like when we add a relationship with term and term parent in node view. This can be avoided using distinct. Producing duplicates is fine IMO to avoid it user can always turn distinct on. If we'd go by this solution we'd have to implement a views relationship plugin which will add this where clause.

Do we've any other way around that?

Meanwhile I updated the tests. Currently it only asserts views data. Just have to create some views like EntityReferenceRelationshipTest and check the relationships but we have to finalize the approach first.

Status: Needs review » Needs work

The last submitted patch, 64: provide_a_relationship-2321721-64.patch, failed testing.

dawehner’s picture

I'm curious why you use INNER JOIN by default? Isn't that the reason why you don't get any result?

jibran’s picture

Oh I just made relationships required. You are right that's the reason I'm not getting results.
Though making those relationships not required gives me this error. Let me debug some more. Thanks for the replay.

Uncaught AjaxError: 
An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /admin/structure/views/view/test_dynamic_entity_reference_entity_test_view/preview/default
StatusText: OK
ResponseText: 
( ! ) Fatal error: Call to a member function bundle() on a non-object in /vagrant/app/core/modules/views/src/Entity/Render/EntityFieldRenderer.php on line 203
Call Stack
#TimeMemoryFunctionLocation
10.0001265320{main}(  )../index.php:0
20.0008569968Drupal\Core\DrupalKernel->handle(  )../index.php:19
30.00521320048Stack\StackedHttpKernel->handle(  )../DrupalKernel.php:572
40.00521320176Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(  )../StackedHttpKernel.php:23
50.00521320992Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(  )../NegotiationMiddleware.php:67
60.00541321104Drupal\page_cache\StackMiddleware\PageCache->handle(  )../ReverseProxyMiddleware.php:58
70.00541321704Drupal\page_cache\StackMiddleware\PageCache->pass(  )../PageCache.php:83
80.00541321752Drupal\Core\DependencyInjection\Container\prod\Drupal_Core_StackMiddleware_KernelPreHandle_Proxy->handle(  )../PageCache.php:104
90.00551325328Drupal\Core\StackMiddleware\KernelPreHandle->handle(  )../73041b7dda6cde1a1c2665c605705b0de53416cf44a31cd564c06e134fe42808.php:9254
100.00881900464Drupal\Core\DependencyInjection\Container\prod\Drupal_Core_StackMiddleware_Session_Proxy->handle(  )../KernelPreHandle.php:53
110.00891905176Drupal\Core\StackMiddleware\Session->handle(  )../73041b7dda6cde1a1c2665c605705b0de53416cf44a31cd564c06e134fe42808.php:9304
120.02202061552Drupal\Core\DependencyInjection\Container\prod\Symfony_Component_HttpKernel_HttpKernel_Proxy->handle(  )../Session.php:62
130.02232086080Symfony\Component\HttpKernel\HttpKernel->handle(  )../73041b7dda6cde1a1c2665c605705b0de53416cf44a31cd564c06e134fe42808.php:9194
140.02242087032Symfony\Component\HttpKernel\HttpKernel->handleRaw(  )../HttpKernel.php:68
150.16498506920call_user_func_array:{/vagrant/app/core/vendor/symfony/http-kernel/HttpKernel.php:147}
(  )../HttpKernel.php:147
160.16498507616Drupal\Core\Controller\FormController->getContentResult(  )../HttpKernel.php:147
170.16538711776Drupal\Core\Form\FormBuilder->buildForm(  )../FormController.php:79
180.610918415512Drupal\Core\Form\FormBuilder->processForm(  )../FormBuilder.php:265
190.612018457680Drupal\Core\Form\FormBuilder->rebuildForm(  )../FormBuilder.php:554
200.612018457680Drupal\Core\Form\FormBuilder->retrieveForm(  )../FormBuilder.php:306
210.612018460304call_user_func_array:{/vagrant/app/core/lib/Drupal/Core/Form/FormBuilder.php:442}
(  )../FormBuilder.php:442
220.612018460872Drupal\views_ui\ViewFormBase->buildForm(  )../FormBuilder.php:442
230.612018460872Drupal\Core\Entity\EntityForm->buildForm(  )../ViewFormBase.php:46
240.612118460920Drupal\views_ui\ViewPreviewForm->form(  )../EntityForm.php:105
250.612218468784Drupal\views_ui\ViewUI->renderPreview(  )../ViewPreviewForm.php:65
260.613718501104Drupal\views\ViewExecutable->preview(  )../ViewUI.php:634
270.623218755256Drupal\views\Plugin\views\display\DisplayPluginBase->preview(  )../ViewExecutable.php:1548
280.623218756128Drupal\views\ViewExecutable->render(  )../DisplayPluginBase.php:2386
290.650119004448Drupal\views\Plugin\views\display\DisplayPluginBase->render(  )../ViewExecutable.php:1431
300.650119004632Drupal\views\Plugin\views\style\StylePluginBase->render(  )../DisplayPluginBase.php:2126
310.650119004984Drupal\views\Plugin\views\style\StylePluginBase->renderGrouping(  )../StylePluginBase.php:455
320.650119005536Drupal\views\Plugin\views\style\StylePluginBase->renderFields(  )../StylePluginBase.php:557
330.650319018584Drupal\Core\Render\Renderer->render(  )../StylePluginBase.php:681
340.650319019872Drupal\Core\Render\Renderer->doRender(  )../Renderer.php:158
350.650419034504call_user_func:{/vagrant/app/core/lib/Drupal/Core/Render/Renderer.php:320}
(  )../Renderer.php:320
360.650419034600Drupal\views\Plugin\views\style\StylePluginBase->elementPreRenderRow(  )../Renderer.php:320
370.751919956024Drupal\views\Plugin\views\field\FieldPluginBase->theme(  )../StylePluginBase.php:728
380.751919958416Drupal\Core\Render\Renderer->render(  )../FieldPluginBase.php:1657
390.751919958464Drupal\Core\Render\Renderer->doRender(  )../Renderer.php:158
400.751919961776Drupal\Core\Theme\ThemeManager->render(  )../Renderer.php:380
410.751919961776Drupal\Core\Theme\ThemeManager->theme(  )../ThemeManager.php:98
420.752019964120template_preprocess_views_view_field(  )../ThemeManager.php:300
430.752019964120Drupal\views\Plugin\views\field\FieldPluginBase->advancedRender(  )../views.theme.inc:277
440.752019964120Drupal\views\Plugin\views\field\Field->getItems(  )../FieldPluginBase.php:1125
450.752019964120Drupal\views\Entity\Render\EntityFieldRenderer->render(  )../Field.php:808
460.752019964120Drupal\views\Entity\Render\EntityFieldRenderer->buildFields(  )../EntityFieldRenderer.php:130
dpi’s picture

Title: Provide a relationship for each dynamic entity reference field » Provide a views relationship for each dynamic entity reference field
jibran’s picture

I didn't debug the above error but thanks to @olli it is blocked on #2534780: Fatal error rendering fields using an optional relationship.

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new35.79 KB
new49.91 KB

This is finally complete now with tests for all the cases.

1. A DER field can create relationships with multiple entity types.
2. A DER field can create mutliple reverse relationships with multiple entity types.

In tests I only added one test per display to keep things simple.

dawehner’s picture

I think this looks really great in general!

  1. +++ b/dynamic_entity_reference.views.inc
    @@ -0,0 +1,100 @@
    + * Implements hook_field_views_data().
    + */
    +function dynamic_entity_reference_field_views_data(FieldStorageConfigInterface $field_storage) {
    +  $data = views_field_default_views_data($field_storage);
    

    Did you ever tried to place a DER field as part of basefields?

  2. +++ b/dynamic_entity_reference.views.inc
    @@ -0,0 +1,100 @@
    +        // Entity reference field only has one target type whereas dynamic
    +        // entity reference field can have multiple target types that is why we
    +        // need extra join condition on target types.
    

    Its just like old d7 field tables ...

  3. +++ b/dynamic_entity_reference.views.inc
    @@ -0,0 +1,100 @@
    +      /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
    

    Is there a reason why you don't typehint \Drupal\Core\Entity\Sql\TableMappingInterface. Is there something specific to the core implementation in your hook_views_data (I guess this is something coming from views itself?)

  4. +++ b/dynamic_entity_reference.views.inc
    @@ -0,0 +1,100 @@
    +        'base' => $entity_type->getDataTable() ?: $entity_type->getBaseTable(),
    

    +1 for doing it right

jibran’s picture

Thanks for the review @dawehner

  1. We should add dedicate tests with entity_test_der in which der is a basefield and whatever problem we'll find there we'll fix it follow up. I think for basic views implementation we should not block this issue on this point.
  2. Anything to fix here?
  3. getDedicatedDataTableName is not defined on the interface $table_mapping->getDedicatedDataTableName($field_storage),
  4. I really like the idea. I'll create a follow up for this.
jibran’s picture

  • jibran committed f7ca7be on 8.x-1.x
    Issue #2321721 by jibran, dawehner, damiankloip, larowlan: Provide a...
jibran’s picture

Status: Needs review » Fixed

Committed and pushed to 8.x-1.x.

Thanks @dawehner for the reviews.
Thanks @damiankloip for discussing the issue with me at DrupalCon Amsterdam.
Thanks @larowlan for the manual testing.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.