It looks like it's gone without an upgrade path?
(but did not test yet)

Comments

kanzer’s picture

I'm also looking for "global: Math Expression" ??

Lendude’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 8.x-3.x-dev » 8.0.x-dev
Component: Miscellaneous » views.module
Category: Support request » Feature request
Issue tags: +Regression

Math expression was dependant on Ctools (and having a certain version of that) in D7, that seems to have cost it a place in core.

moved to the right queue.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Anonymous’s picture

Seriously I loved Drupal 8 until this problem came up for me. This is really stupid. This functionality should be in core and the fact that this isn't makes me hate the people making decisions about releases. This is the most used feature for me in Drupal 7. Is helps with any kind of accounting and I think most of the companies I know using Drupal "rely on this" this is a critical feature.

Programmers may be smart as heck at building modules and making code, but they make stupid decisions about functionality to sacrifice obviously. This makes Drupal 8 absolutely useless for just about every project I might get now.

Absolutely infuriating that someone thought that functionality was "a feature".

This community is slowly going to cut out all the useful features of Drupal to make it more coder friendly. Making Drupal more code reliant, and taking out anything normal people could use in it, will make sure lots of people don't use new versions of Drupal in the future.

I thought Drupal 8 was amazing, until I needed to calculate 2 fields, now I am going back to Drupal 7 and may forget about Drupal 8 contributions from here on out. You just ruined views in Drupal in my opinion.

Anonymous’s picture

Category: Feature request » Bug report
Priority: Normal » Critical
Issue tags: -Regression +Math: globals

This should not be considered a feature request, it should be considered basic functionality. This was in views in Drupal 7 and you removed it from 8. In my mind stripping features, is not migrating, or porting modules, it is destroying them.

Every accountant in the world that uses Drupal, now hates Drupal 8. Good job.

catch’s picture

Project: Drupal core » Ctools
Version: 8.1.x-dev »
Component: views.module » Code

This was a ctools feature in 7.x, not a views feature. Lots of modules provide integration with and additional functionality to Views. Some of them are ported, some of them aren't.

Ctools is a contrib module, and it looks like there's an existing issue for porting that functionality to 8.x here: #2695723: Global Math Expression. Possibly you could try to help with porting ctools to 8.x, instead of attacking the people who did the work porting Views to 8.x. In case this isn't quite the same feature, moving it to the ctools queue for now rather than marking duplicate.

geek-merlin’s picture

Thanks @catch for clarification.

@alex_drupal_dev: I think you have a fundamental misconception about open source and really should file a request to get your money back ;-)
Seriously, such a harsh and unappropriate tone won't have a positive impact on getting your problem solved.

DamienMcKenna’s picture

Project: Ctools » Chaos Tool Suite (ctools)
Version: » 8.x-3.x-dev

Moving the issue to the correct project.

stefan.r’s picture

Priority: Critical » Major
andileco’s picture

This is nowhere as good, but it may help a few people who need just a simple operation (add, subtract, multiply, divide) performed in their view while this issue is being fixed:

https://www.drupal.org/sandbox/andileco/views_simple_math_field

I don't plan on taking it out of the sandbox, but I would like to make it better, so please submit patches!

geek-merlin’s picture

@andileco:
> I don't plan on taking it out of the sandbox, but I would like to make it better, so please submit patches!

Given that there's a big need for such a module, it would be highly appreciated to make it a full module. If you need help, feel free to PM me.

geek-merlin’s picture

Also note that some might benefit from a d8 port of raw sql field:
https://www.drupal.org/project/views_raw_sql

frankdesign’s picture

I've found a way of working around this. Views Global Custom Text field allows Twig coding (as does rewriting results in any field). And Twig itself allows pretty much any type of calculation.

So to create complex calculations:

Add your fields to the view as normal
Put a tick in Exclude from Display
In the field Style Settings remove tick from Add default classes and put a tick in each of Customize field html, Customise label HTML and Wrapper HTML element and change the dropdown for all to -None- (this reduces the field result to just the content)
Add a Global Custom Text Field.
In this field, if you try to perform calculations on the values of above fields, you will either get an error or the result will be 1 or 0. This is because Drupal auto converts Views results to ViewsRenderPipelineMarkup objects. So the first thing you need to add in the Global Custom Text Field is a new variable for each of your fields and add |trim to the end of the field value (this converts the object back into a string) e.g.

{% set price = field_price|trim %}
{% set amount = field_amount|trim %}

Now you can perform calculations on the new variables.

{{ price * amount }}

Obviously you can perform more complex calculations e.g.

{{ ((((price * interest) * year) + price) / (year * 12))|number_format(2, '.', ',') }}

Thanks to lincolnbergeson in https://www.drupal.org/node/2890113#comment-12146025 for the info on ViewsRenderPipelineMarkup objects and |trim.

P.S. |number_format(2, '.', ',') at the end of the result converts the result to a integer with 2 decimal places and uses a comma for a thousand separator

lquessenberry’s picture

I can't seem to get anything to work. My output always ends up being 0 every time. I tried what was mentioned in #13 https://www.drupal.org/project/ctools/issues/2544670#comment-12275432

Everything I get is a 0 value. I am just trying to perform a simple operation on the views row counter.

Thanks

andileco’s picture

@lquessenberry - people who do a lot of debugging will probably shun me, but I have found

{{ data|json_encode() }}

really helpful when things aren't working, as you can put it right into your view field. I've definitely had unexpected whitespace mess me up.

You can try my module: https://www.drupal.org/project/views_simple_math_field as well, though at this point I think I agree with @frankdesign that Twig is a better option.

lquessenberry’s picture

Would you care to elaborate a little more on how you're using that? Forgive my ignorance.

andileco’s picture

Replace "data" with "field_name" (the token suggested by Views). So for counter, try:

{{ counter|json_encode() }}

lquessenberry’s picture

Oh I see. Good call.Well that spits out their value just fine but if I multiply them, I can't get it to do anything but give me 0 for a result.

andileco’s picture

lquessenberry’s picture

I saw that earlier, but I really miss the Global Math Expression option from Ctools/Drupal7 or whatever it was. It's weird that I can print the value out with {{ counter }} and when I set it to another variable it will also print out just fine even if I have used the "trim" feature from Twig. The problem is that when I use it with an expression {{ newcounter * 1 }} or anything like that, it prints a 0.

lquessenberry’s picture

So the "nid" as a value works just fine in a math expression. Am I correct to assume that the Views Counter for each item in a view is not working mathematically because it is rendering a number to the screen but has a value of nothing?

rszrama’s picture

fyi, I'm seeing this issue as well ... very bizarre behavior. The string output by the counter field only casts to 0, nothing else. Even if you try to manually cast it before using it in an expression, it won't work. There's something odd about the way that variable is being passed to Twig preventing it from working right, but I'll be darned if I can see where in the code this is getting into the Views field for evaluation in the first place. Happy to dig further if someone knows.

frankdesign’s picture

@lquessenberry - sorry I'm only replying to this now. The '|trim' solution does work for calculations on fields but as you noticed, it doesn't work on the Views Counter. As @rszrama noted, there's something odd going on with the Counter variable - I can't find the problem in the code either. If anyone has any ideas, please let us know.

Thanks

F

C.E.A’s picture

1

joelpittet’s picture

Priority: Major » Normal
Status: Active » Closed (duplicate)
Issue tags: -Math: globals

This is a duplicate of #2695723: Global Math Expression

stopopol’s picture

I can confirm that #13 works.
I just used it to calculate percentage values for the number of filled in fields per node.

That being said, having "global: Math Expression" back in the module would be a more elegant solution.

danrod’s picture

The proposed workaround on the post #13 worked for me, thanks!