Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up the value of the float (number) and money field types in the custom field. #463

Merged

Conversation

sunilpawar
Copy link
Contributor

Overview

Clean the field value for custom field of type Money and Number (Float).

Before

Error on formatted custom field values activity entity.

After

Error not present. Using the views formatter, admins can decide about value.

Technical Details

#0 demo10/web/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/DecimalFormatter.php(67): number_format('123,456,789', 2, '.', '')
#1 demo10/web/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/NumericFormatterBase.php(66): Drupal\Core\Field\Plugin\Field\FieldFormatter\DecimalFormatter->numberFormat('123,456,789')
#2 demo10/web/core/lib/Drupal/Core/Field/FormatterBase.php(89): Drupal\Core\Field\Plugin\Field\FieldFormatter\NumericFormatterBase->viewElements(Object(Drupal\Core\Field\FieldItemList), 'en')
#3 demo10/web/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php(268): Drupal\Core\Field\FormatterBase->view(Object(Drupal\Core\Field\FieldItemList), 'en')
#4 demo10/web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php(339): Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple(Array)
#5 demo10/web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php(281): Drupal\Core\Entity\EntityViewBuilder->buildComponents(Array, Array, Array, 'full')
#6 demo10/web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php(238): Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array)
#7 [internal function]: Drupal\Core\Entity\EntityViewBuilder->build(Array)
#8 demo10/web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(111): call_user_func_array(Array, Array)
#9 demo10/web/core/lib/Drupal/Core/Render/Renderer.php(858): Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_ren...', 'exception', 'Drupal\\Core\\Ren...')
#10 demo10/web/core/lib/Drupal/Core/Render/Renderer.php(421): Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array)
#11 demo10/web/core/lib/Drupal/Core/Render/Renderer.php(240): Drupal\Core\Render\Renderer->doRender(Array, false)
#12 demo10/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(238): Drupal\Core\Render\Renderer->render(Array, false)
#13 demo10/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#14 demo10/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(239): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#15 demo10/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(128): Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#16 demo10/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#17 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#18 demo10/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#19 demo10/vendor/symfony/http-kernel/HttpKernel.php(186): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view')
#20 demo10/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#21 demo10/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 demo10/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 demo10/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 demo10/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 demo10/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 demo10/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 demo10/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 demo10/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 demo10/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 demo10/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 demo10/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#32 demo10/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#33 {main}

Custom field types of numbers and money are created for activity types.

Access that activity record using the following URL (here 12 is the activity ID).

https://demo10/civicrm-activity/12

@civibot civibot bot added the 4.0.x label Jan 27, 2024
@jackrabbithanna
Copy link
Collaborator

We discovered that "Number" custom fields are sometimes retrieved by the CiviCRM API 3 as formatted with commas. Those custom fields are setup as numeric Drupal base fields on the CiviCRM Entity types. This was causing type errors rendering the field values.
Strangely, it seems to only be the "Activity" API, whereas custom fields on Contacts didn't have this issue.
We had seen odd inconsistencies between these legacy APIs in the past, so this PR massages the values.

Tested in prod.

@jackrabbithanna jackrabbithanna merged commit f94404b into eileenmcnaughton:4.0.x Feb 16, 2024
1 check passed
puresyntax71 added a commit to puresyntax71/civicrm_entity that referenced this pull request Apr 19, 2024
* origin/4.0.x:
  4.0.x field mappings (eileenmcnaughton#430)
  Adding a raw value function to return value from values array (eileenmcnaughton#465)
  Add filter for state province. (eileenmcnaughton#453)
  Update default timezone handling for dates in CiviEntityStorage.php (eileenmcnaughton#461)
  fix testLoadContact birthdate assertion (eileenmcnaughton#472)
  port to 4.0.x from 436: Include dblocale table names in list of civicrm entity info (eileenmcnaughton#438)
  Ignore convert to UTC if custom field is date only (eileenmcnaughton#469)
  update contact entity referece field on contact merge (eileenmcnaughton#456)
  update test versions of Drupal 10.2 and CiviCRM 5.69 (eileenmcnaughton#468)
  Clean value on custom field for Float (Number) and Money field type (eileenmcnaughton#463)
  From eileenmcnaughton#378 for 4.0.x (eileenmcnaughton#466)
  Add reset to the file URLs generated. (eileenmcnaughton#458)
  fix Views field custom date field output for year only (eileenmcnaughton#439)
puresyntax71 added a commit to puresyntax71/civicrm_entity that referenced this pull request Apr 27, 2024
* origin/4.0.x: (41 commits)
  patch from issue 3420771 (eileenmcnaughton#475)
  only check for data in enabled components on module uninstall (eileenmcnaughton#476)
  Adds is Empty/NULL operators (eileenmcnaughton#423)
  Pathauto (eileenmcnaughton#470)
  fix test to use string instead of integer for zip code (eileenmcnaughton#474)
  4.0.x field mappings (eileenmcnaughton#430)
  Adding a raw value function to return value from values array (eileenmcnaughton#465)
  Add filter for state province. (eileenmcnaughton#453)
  Update default timezone handling for dates in CiviEntityStorage.php (eileenmcnaughton#461)
  fix testLoadContact birthdate assertion (eileenmcnaughton#472)
  port to 4.0.x from 436: Include dblocale table names in list of civicrm entity info (eileenmcnaughton#438)
  Ignore convert to UTC if custom field is date only (eileenmcnaughton#469)
  update contact entity referece field on contact merge (eileenmcnaughton#456)
  update test versions of Drupal 10.2 and CiviCRM 5.69 (eileenmcnaughton#468)
  Clean value on custom field for Float (Number) and Money field type (eileenmcnaughton#463)
  From eileenmcnaughton#378 for 4.0.x (eileenmcnaughton#466)
  Add reset to the file URLs generated. (eileenmcnaughton#458)
  fix Views field custom date field output for year only (eileenmcnaughton#439)
  update Add Contact to Group Views Bulk operations action plugin access handler (eileenmcnaughton#464)
  Readme update (eileenmcnaughton#457)
  ...
puresyntax71 pushed a commit to puresyntax71/civicrm_entity that referenced this pull request Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants