Hello, Mustapha Ben Ellafi (benellefimostfa) !

Thank you for a great module!

I use it on one of my projects and found that with latest Drupal core 8.7.8 version "Use Ajax" doesn't work.
It appears because unique_event library doesn't attached because of this line of code (in unique_field_ajax.module):

if(!empty($form['#attached']['library']) && !in_array('unique_field_ajax/unique_event',$form['#attached']['library'])){

property $form['#attached']['library'] is empty and it causes canceling library attachment.
Attached patch solves this issue.

Comments

Antonnavi created an issue. See original summary.

antonnavi’s picture

Status: Active » Needs review
StatusFileSize
new812 bytes
maxilein’s picture

I can confirm that it does not work on core media entities.
It breaks the adding of files through the "media library" widget.

Notice: Trying to access array offset on value of type null in unique_field_ajax_validate_unique() (line 219 of modules/unique_field_ajax/unique_field_ajax.module).

Error: Call to undefined method Drupal\media_library\Form\FileUploadForm::getEntity() in _unique_field_ajax_process() (line 184 of /web/html/modules/unique_field_ajax/unique_field_ajax.module)

#0 [internal function]: _unique_field_ajax_process()
#1 /web/html/core/lib/Drupal/Core/Form/FormBuilder.php(999): call_user_func_array()
#2 /web/html/core/lib/Drupal/Core/Form/FormBuilder.php(1062): Drupal\Core\Form\FormBuilder->doBuildForm()
#3 /web/html/core/lib/Drupal/Core/Form/FormBuilder.php(1062): Drupal\Core\Form\FormBuilder->doBuildForm()
#4 /web/html/core/lib/Drupal/Core/Form/FormBuilder.php(1062): Drupal\Core\Form\FormBuilder->doBuildForm()
#5 /web/html/core/lib/Drupal/Core/Form/FormBuilder.php(1062): Drupal\Core\Form\FormBuilder->doBuildForm()
#6 /web/html/core/lib/Drupal/Core/Form/FormBuilder.php(1062): Drupal\Core\Form\FormBuilder->doBuildForm()
#7 /web/html/core/lib/Drupal/Core/Form/FormBuilder.php(1062): Drupal\Core\Form\FormBuilder->doBuildForm()
#8 /web/html/core/lib/Drupal/Core/Form/FormBuilder.php(433): Drupal\Core\Form\FormBuilder->doBuildForm()
#9 /web/html/core/lib/Drupal/Core/Form/FormBuilder.php(627): Drupal\Core\Form\FormBuilder->rebuildForm()
#10 /web/html/core/lib/Drupal/Core/Form/FormBuilder.php(320): Drupal\Core\Form\FormBuilder->processForm()
#11 /web/html/core/modules/media_library/src/MediaLibraryUiBuilder.php(313): Drupal\Core\Form\FormBuilder->buildForm()
#12 /web/html/core/modules/media_library/src/MediaLibraryUiBuilder.php(164): Drupal\media_library\MediaLibraryUiBuilder->buildMediaTypeAddForm()
#13 /web/html/core/modules/media_library/src/MediaLibraryUiBuilder.php(130): Drupal\media_library\MediaLibraryUiBuilder->buildLibraryContent()
#14 [internal function]: Drupal\media_library\MediaLibraryUiBuilder->buildUi()
#15 /web/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#16 /web/html/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#17 /web/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
#18 /web/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#19 /web/html/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#20 /web/html/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#21 /web/html/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle()
#22 /web/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle()
#23 /web/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#24 /web/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#25 /web/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle()
#26 /web/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#27 /web/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#28 /web/html/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle()
#29 /web/html/index.php(19): Drupal\Core\DrupalKernel->handle()
#30 {main}
benellefimostfa’s picture

@maxilein,
Did the patch in #2 fix your issue?

maxilein’s picture

Sorry. I should have been more specific. I did no try the patch yet. I just wanted to provide more information in order to make it for others easier to find this issue. As soon as I find the time to try it, I will let you know.

n8tron’s picture

Patch in #2 seems to have fixed this issue.

zebda’s picture

I don't know for sure if this is related but I get the following error:

Notice: Trying to access array offset on value of type null in unique_field_ajax_validate_unique() (regel 219 van /site/web/modules/contrib/unique_field_ajax/unique_field_ajax.module). =>

I tried the patch but this didn't fix it. Even when I turn the Ajax function off I get this message.

3li’s picture

Status: Needs review » Fixed

Have made a small change so that the library is always attached, I don't see why we even needed to check that the library array existed or if we have already got the library.

3li’s picture

@maxilein & @zebda I don't believe the issues you have faced are related to the library not loading.
Please open new issues if you are still having problems.

cprofessionals’s picture

I wanted to provide feedback. Patch #2 worked for me and specifically with Feeds Fields!... thanks for the great support and module! I now see you commited... will update and try new release.

Status: Fixed » Closed (fixed)

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

3li’s picture

Version: 8.x-1.x-dev » 2.x-dev