I've installed the latest 8.x-5.0-beta6, but the same issue happens with beta5 and on dev too. I've added an "entity select" field/element to my webform and configured it to show taxonomy terms from a specified vocabulary. I chose to sort by term name ascending using the "default" reference method.

However, after saving the element, the drop-down continues to not be sorted by name. I think it might sorted by term weight.

I also tried configuring the entity select to show content of a particular type, sorting by title ascending, and again it didn't work. I'm not sure of the actual sort order used here, perhaps it's the creation date.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

stella created an issue. See original summary.

jrockowitz’s picture

@stella I am seeing the below error in 'Recent Logs'

Notice: Undefined index: direction in Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection->buildEntityQuery() (line 412 of core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php).

Can you please confirm that you are seeing the same error?

stella’s picture

@jrockowitz I only see that error after initially turning on the Sort as there appears to be no ajax enabled on that field (in fact I think I see code in the module that removes ajax from that select). This means when I change the "Sort by" from "-none-" to name or whatever, the "Sort direction" drop-down does not appear. Saving the form element and re-editing it causes it to appear.

FYI I'm happy to try and work on a patch towards this, just still trying to piece together where the problem actually is.

jrockowitz’s picture

Yes, I think there are some AJAX related issue with the UI for all entity reference webform elements.

stella’s picture

Yeah, I'm not too concerned with that as there's a workaround. However, I'm now also seeing similar errors when I try to edit the element and add a conditional rule to it - might be ajax related again, or might be something to do with entity select type, as I've had no problems editing other elements to add conditional rules. Putting them here, but can spin out to a separate issue if you think they're not related:

Notice: Undefined index: target_type in Drupal\webform\Plugin\WebformElement\WebformEntitySelect->form() (line 297 of /var/www/docroot/modules/contrib-dev/webform/src/Plugin/WebformElement/WebformEntityReferenceTrait.php)

Notice: Undefined index: selection_handler in Drupal\webform\Plugin\WebformElement\WebformEntitySelect->form() (line 298 of /var/www/docroot/modules/contrib-dev/webform/src/Plugin/WebformElement/WebformEntityReferenceTrait.php) 

Notice: Undefined index: selection_settings in Drupal\webform\Plugin\WebformElement\WebformEntitySelect->form() (line 299 of /var/www/docroot/modules/contrib-dev/webform/src/Plugin/WebformElement/WebformEntityReferenceTrait.php)

InvalidArgumentException: Missing required 'target_type' property for a EntityReferenceSelection plugin. in Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getInstance() (line 36 of /var/www/docroot/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php).

jrockowitz’s picture

Status: Active » Needs review
FileSize
1.84 KB

I kind-of/sort-of knew the configuration form was a little broken when I implemented these entity reference elements but I wasn't sure how to fix it.

Hopefully, the attached patch finally fixes these little bugs.

  • jrockowitz committed c5684b5 on 8.x-5.x
    Issue #2852676 by jrockowitz, stella: Entity Select sorting doesn't work
    
jrockowitz’s picture

Status: Needs review » Fixed

I committed the patch. Please download and review the latest dev release.

Status: Fixed » Closed (fixed)

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

ilclaudio’s picture

I have the same error "Notice: Undefined index: direction" on Drupal 8.3.4 (Webform 4.6.2) should I apply the same patch?
I've created a webform with a field "Entity Select" with:
- Type of item to reference: Content
- Reference method: Default
Using a view as Reference method, I don't have the error.

Notice: Undefined index: direction in Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection->buildEntityQuery() (line 412 of core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php).

Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection->buildEntityQuery(NULL, 'CONTAINS') (Line: 35)
Drupal\node\Plugin\EntityReferenceSelection\NodeSelection->buildEntityQuery(NULL, 'CONTAINS') (Line: 283)
Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection->getReferenceableEntities() (Line: 49)
Drupal\webform\Element\WebformEntityTrait::setOptions(Array) (Line: 260)
Drupal\webform\Plugin\WebformElement\WebformEntitySelect->setOptions(Array) (Line: 30)
Drupal\webform\Plugin\WebformElement\WebformEntitySelect->prepare(Array, Object, NULL) (Line: 149)
Drupal\webform\WebformElementManager->invokeMethod('prepare', Array, Object) (Line: 1375)
Drupal\webform\WebformSubmissionForm->prepareElements(Array, Array, Object) (Line: 315)
Drupal\webform\WebformSubmissionForm->form(Array, Object) (Line: 115)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object) (Line: 252)
Drupal\webform\WebformSubmissionForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 514)
Drupal\Core\Form\FormBuilder->retrieveForm('webform_submission_revisione_auto_form', Object) (Line: 271)
Drupal\Core\Form\FormBuilder->buildForm('webform_submission_revisione_auto_form', Object) (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'default') (Line: 869)
Drupal\webform\Entity\Webform->getSubmissionForm() (Line: 82)
Drupal\webform\Controller\WebformController->addForm(Object, 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: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
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: 38)
Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

omdb’s picture

This patch doesn't work in the latest 8.x-5.0-beta15 version.

Notice: Undefined index: direction in Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection->buildEntityQuery() (line 412 of core\lib\Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection.php).

jrockowitz’s picture