Field validation not working.

Created on 17 May 2021, over 3 years ago
Updated 6 September 2023, over 1 year ago

Problem/Motivation

Field validation constraint not validating URL properly.

Steps to reproduce

Add facebook media with random string in Facebook field. For example add "TestString" instead of facebook post URL.

Facebook media will save without any validation error.

Proposed resolution

Change FieldItemInterface to FieldItemListInterface In FacebookEmbedCodeConstraintValidator::validate

Remaining tasks

Update FacebookEmbedCodeConstraintValidator::validate

User interface changes

NA

API changes

NA

Data model changes

NA

🐛 Bug report
Status

Fixed

Version

4.0

Component

Code

Created by

🇮🇳India bunty badgujar Delhi

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇸🇰Slovakia kaszarobert

    I applied the changes but when I click saving the media, it throws a WSOD:

    The website encountered an unexpected error. Please try again later.
    TypeError: trim(): Argument #1 ($string) must be of type string, Drupal\Core\Field\FieldItemList given in trim() (line 169 of modules/contrib/media_entity_facebook/src/Plugin/media/Source/Facebook.php).
    trim(Object) (Line: 169)
    Drupal\media_entity_facebook\Plugin\media\Source\Facebook::parseFacebookEmbedField(Object) (Line: 30)
    Drupal\media_entity_facebook\Plugin\Validation\Constraint\FacebookEmbedCodeConstraintValidator->validate(Object, Object) (Line: 201)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateConstraints(Object, '00000000000009430000000000000000', Array) (Line: 153)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode(Object) (Line: 163)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode(Object, Array, 1) (Line: 105)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validate(Object, NULL, NULL) (Line: 93)
    Drupal\Core\TypedData\Validation\RecursiveValidator->validate(Object) (Line: 132)
    Drupal\Core\TypedData\TypedData->validate() (Line: 489)
    Drupal\Core\Entity\ContentEntityBase->validate() (Line: 471)
    Drupal\media\Entity\Media->validate() (Line: 188)
    Drupal\Core\Entity\ContentEntityForm->validateForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 82)
    Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 275)
    Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'media_facebook_add_form') (Line: 118)
    Drupal\Core\Form\FormValidator->validateForm('media_facebook_add_form', Array, Object) (Line: 593)
    Drupal\Core\Form\FormBuilder->processForm('media_facebook_add_form', Array, Object) (Line: 325)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult(Object, Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    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}() (Line: 169)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    
  • 🇮🇳India shubham_jain

    Hi @kaszarobert, I installed the theme and applied the patch in the comment #3 in the composer.json.

    I did this with both Drupal 9 and 10 but was unable to get the error mentioned in the comment #4. But the patch file in the #3 solved the Field validation error.

    See the attached screenshot for refrence.

  • Status changed to RTBC over 1 year ago
  • 🇸🇰Slovakia kaszarobert

    What version of the module were you testing? Then I'll try it again.

  • Assigned to kaszarobert
  • Status changed to Needs work over 1 year ago
  • 🇸🇰Slovakia kaszarobert

    Okay, for a new site, I can't reproduce the error I posted. I'll try to reproduce it later for the existing site I was working when checking this.

    Also, it works only for media add/edit form. We need that to work on Media Library form as many editorial sites embed Facebook posts to article text with CKEditor or they have a separate media field where the Media Library widget is used to create and select media.

  • Issue was unassigned.
  • Status changed to Fixed over 1 year ago
  • 🇸🇰Slovakia kaszarobert

    Alright, I could no longer reproduce the error I experienced. Probably I was doing something wrong during development. I decided to commit this and open a followup issue for Media Library validation 🐛 Field validation should work in Media Library widget Active .
    Thanks for your work!

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

Production build 0.71.5 2024