amitaibu / og

A fork to work on OG8
https://github.com/Gizra/og
29 stars 16 forks source link

Undefined index when saving group content #256

Open jhedstrom opened 8 years ago

jhedstrom commented 8 years ago
Notice: Undefined index: field_mode in Drupal\og\Plugin\EntityReferenceSelection\OgSelection->buildEntityQuery() (line 88 of /.../modules/og/src/Plugin/EntityReferenceSelection/OgSelection.php).
amitaibu commented 8 years ago

Can you please provide steps to reproduce, as I'm not seeing it.

jhedstrom commented 8 years ago

Just basic usage (however, I am on 8.2.x latest)

  1. Make page nodes to be a group
  2. Make article nodes to be group content
  3. Add a page node, titled A group
  4. Add an article node, select the page node as the group
  5. When saving I see the notice

I verified on a fresh install as I initially had workbench moderation enabled when I first saw this.

Full stack trace:

Notice: Undefined index: field_mode in Drupal\og\Plugin\EntityReferenceSelection\OgSelection->buildEntityQuery() (line 88 of /Users/jonathan.hedstrom/work/contributions/modules/og/src/Plugin/EntityReferenceSelection/OgSelection.php).
Drupal\og\Plugin\EntityReferenceSelection\OgSelection->buildEntityQuery() (Line: 321)
Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection->validateReferenceableEntities(Array) (Line: 122)
Drupal\Core\Entity\Plugin\Validation\Constraint\ValidReferenceConstraintValidator->validate(Object, Object) (Line: 185)
Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateConstraints(Object, '0000000059a6290300000000726fa538', Array) (Line: 140)
Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode(Object) (Line: 147)
Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode(Object, Array, 1) (Line: 99)
Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validate(Object, NULL, NULL) (Line: 90)
Drupal\Core\TypedData\Validation\RecursiveValidator->validate(Object) (Line: 135)
Drupal\Core\TypedData\TypedData->validate() (Line: 373)
Drupal\Core\Entity\ContentEntityBase->validate() (Line: 96)
Drupal\Core\Entity\ContentEntityForm->validateForm(Array, Object)
call_user_func_array(Array, Array) (Line: 83)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 270)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'node_article_form') (Line: 119)
Drupal\Core\Form\FormValidator->validateForm('node_article_form', Array, Object) (Line: 569)
Drupal\Core\Form\FormBuilder->processForm('node_article_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm('node_article_form', Object) (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object) (Line: 113)
Drupal\node\Controller\NodeController->add(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 139)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 649)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
amitaibu commented 8 years ago

Thanks, I'll check.

amitaibu commented 8 years ago

Checked on a clean installation with 8.2.x. It seems to work fine for me also using a "regular" authenticated user.

But I believe there is something there - so if you can/ want to send me your DB dump (or even better try to debug it 😄 )

jhedstrom commented 8 years ago

I'll dig in a bit to see what's going on :)

jhedstrom commented 8 years ago

I dug into this a bit.

The field config's handler settings by default are missing field_mode, which then throws the undefined index notice.

langcode: en
status: true
dependencies:
  config:
    - field.storage.node.og_group_ref
    - node.type.article
    - node.type.page
  module:
    - og
id: node.article.og_group_ref
field_name: og_group_ref
entity_type: node
bundle: article
label: 'Groups audience'
description: 'OG group audience reference field.'
required: false
translatable: true
default_value: {  }
default_value_callback: ''
settings:
  handler: 'og:default'
  handler_settings:
    target_bundles:
      page: page
  access_override: false
field_type: og_standard_reference
amitaibu commented 8 years ago

Thanks for digging! The field_mode shouldn't be saved in the config, as it's just a switch (with a terrible name) that indicates if we should return the valid groups for "My groups" or "Other Groups". So I'm not sure this config here is the problem.

(btw, Variable name could probably change to something like $my_groups_results = TRUE)