added simple math and charts modules
This commit is contained in:
99
web/modules/views_simple_math_field/.gitlab-ci.yml
Normal file
99
web/modules/views_simple_math_field/.gitlab-ci.yml
Normal file
@@ -0,0 +1,99 @@
|
||||
################
|
||||
# DrupalCI GitLabCI template
|
||||
#
|
||||
# Gitlab-ci.yml to replicate DrupalCI testing for Contrib
|
||||
#
|
||||
# With thanks to:
|
||||
# * The GitLab Acceleration Initiative participants
|
||||
# * DrupalSpoons
|
||||
################
|
||||
|
||||
################
|
||||
# Guidelines
|
||||
#
|
||||
# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification. It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
|
||||
#
|
||||
# However, you can modify this template if you have additional needs for your project.
|
||||
################
|
||||
|
||||
################
|
||||
# Includes
|
||||
#
|
||||
# Additional configuration can be provided through includes.
|
||||
# One advantage of include files is that if they are updated upstream, the changes affect all pipelines using that include.
|
||||
#
|
||||
# Includes can be overridden by re-declaring anything provided in an include, here in gitlab-ci.yml
|
||||
# https://docs.gitlab.com/ee/ci/yaml/includes.html#override-included-configuration-values
|
||||
################
|
||||
|
||||
include:
|
||||
################
|
||||
# DrupalCI includes:
|
||||
# As long as you include this, any future includes added by the Drupal Association will be accessible to your pipelines automatically.
|
||||
# View these include files at https://git.drupalcode.org/project/gitlab_templates/
|
||||
################
|
||||
- project: $_GITLAB_TEMPLATES_REPO
|
||||
ref: $_GITLAB_TEMPLATES_REF
|
||||
file:
|
||||
- '/includes/include.drupalci.main.yml'
|
||||
# EXPERIMENTAL: For Drupal 7, remove the above line and uncomment the below.
|
||||
# - '/includes/include.drupalci.main-d7.yml'
|
||||
- '/includes/include.drupalci.variables.yml'
|
||||
- '/includes/include.drupalci.workflows.yml'
|
||||
|
||||
################
|
||||
# Pipeline configuration variables
|
||||
#
|
||||
# These are the variables provided to the Run Pipeline form that a user may want to override.
|
||||
#
|
||||
# Docs at https://git.drupalcode.org/project/gitlab_templates/-/blob/1.0.x/includes/include.drupalci.variables.yml
|
||||
################
|
||||
# variables:
|
||||
# SKIP_ESLINT: '1'
|
||||
|
||||
|
||||
###################################################################################
|
||||
#
|
||||
# *
|
||||
# /(
|
||||
# ((((,
|
||||
# /(((((((
|
||||
# ((((((((((*
|
||||
# ,(((((((((((((((
|
||||
# ,(((((((((((((((((((
|
||||
# ((((((((((((((((((((((((*
|
||||
# *(((((((((((((((((((((((((((((
|
||||
# ((((((((((((((((((((((((((((((((((*
|
||||
# *(((((((((((((((((( .((((((((((((((((((
|
||||
# ((((((((((((((((((. /(((((((((((((((((*
|
||||
# /((((((((((((((((( .(((((((((((((((((,
|
||||
# ,(((((((((((((((((( ((((((((((((((((((
|
||||
# .(((((((((((((((((((( .(((((((((((((((((
|
||||
# ((((((((((((((((((((((( ((((((((((((((((/
|
||||
# (((((((((((((((((((((((((((/ ,(((((((((((((((*
|
||||
# .((((((((((((((/ /(((((((((((((. ,(((((((((((((((
|
||||
# *(((((((((((((( ,(((((((((((((/ *((((((((((((((.
|
||||
# ((((((((((((((, /(((((((((((((. ((((((((((((((,
|
||||
# (((((((((((((/ ,(((((((((((((* ,(((((((((((((,
|
||||
# *((((((((((((( .((((((((((((((( ,(((((((((((((
|
||||
# ((((((((((((/ /((((((((((((((((((. ,((((((((((((/
|
||||
# ((((((((((((( *(((((((((((((((((((((((* *((((((((((((
|
||||
# ((((((((((((( ,(((((((((((((..((((((((((((( *((((((((((((
|
||||
# ((((((((((((, /((((((((((((* /((((((((((((/ ((((((((((((
|
||||
# ((((((((((((( /((((((((((((/ (((((((((((((* ((((((((((((
|
||||
# (((((((((((((/ /(((((((((((( ,((((((((((((, *((((((((((((
|
||||
# (((((((((((((( *(((((((((((/ *((((((((((((. ((((((((((((/
|
||||
# *((((((((((((((((((((((((((, /(((((((((((((((((((((((((
|
||||
# ((((((((((((((((((((((((( ((((((((((((((((((((((((,
|
||||
# .(((((((((((((((((((((((/ ,(((((((((((((((((((((((
|
||||
# ((((((((((((((((((((((/ ,(((((((((((((((((((((/
|
||||
# *((((((((((((((((((((( (((((((((((((((((((((,
|
||||
# ,(((((((((((((((((((((, ((((((((((((((((((((/
|
||||
# ,(((((((((((((((((((((* /((((((((((((((((((((
|
||||
# ((((((((((((((((((((((, ,/((((((((((((((((((((,
|
||||
# ,(((((((((((((((((((((((((((((((((((((((((((((((((((
|
||||
# .(((((((((((((((((((((((((((((((((((((((((((((
|
||||
# .((((((((((((((((((((((((((((((((((((,.
|
||||
# .,(((((((((((((((((((((((((.
|
||||
#
|
||||
###################################################################################
|
||||
339
web/modules/views_simple_math_field/LICENSE.txt
Normal file
339
web/modules/views_simple_math_field/LICENSE.txt
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
66
web/modules/views_simple_math_field/README.md
Normal file
66
web/modules/views_simple_math_field/README.md
Normal file
@@ -0,0 +1,66 @@
|
||||
# Views Simple Math Field
|
||||
|
||||
The Views Simple Math Field module creates a Views field handler that enables
|
||||
the user to perform simple math expressions based on two of the user's
|
||||
view's fields.
|
||||
|
||||
For a full description of the module, visit the
|
||||
[project page](https://www.drupal.org/project/views_simple_math_field).
|
||||
|
||||
Submit bug reports and feature suggestions, or track changes in the
|
||||
[issue queue](https://www.drupal.org/project/issues/views_simple_math_field).
|
||||
|
||||
|
||||
## Table of contents
|
||||
|
||||
- Requirements
|
||||
- Recommended Modules
|
||||
- Installation
|
||||
- Configuration
|
||||
- Maintainers
|
||||
|
||||
|
||||
## Requirements
|
||||
|
||||
This module requires andileco/eval-math
|
||||
(`https://packagist.org/packages/andileco/eval-math`).
|
||||
|
||||
|
||||
## Recommended Modules
|
||||
|
||||
Note: Twig can do math, but it's better to perform math with PHP. This field is
|
||||
especially useful for site-builders who want to avoid Twig or who have a
|
||||
module like Charts that responds better to this module than a field rewrite.
|
||||
|
||||
- [Charts](https://www.drupal.org/project/charts)
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
Install as you would normally install a contributed Drupal module. For further
|
||||
information, see
|
||||
[Installing Drupal Modules](https://www.drupal.org/docs/extending-drupal/installing-drupal-modules).
|
||||
|
||||
|
||||
## Configuration
|
||||
|
||||
1. Navigate to Administration > Extend and enable the module.
|
||||
2. Navigate to Administration > Structure > Views and either create or edit
|
||||
a view.
|
||||
3. Add two or more fields that output numbers.
|
||||
4. Add the `"Global: Simple Math Field"` field (created by this module).
|
||||
Check as many fields as you need, and then add them into the text area
|
||||
where you can write formulas with the fields, such as
|
||||
'(@field_one + @field_two) / @field_three'. Apply and save.
|
||||
|
||||
Please note:
|
||||
After you enable this module you may need to run cron/clear caches.
|
||||
|
||||
|
||||
## Maintainers
|
||||
|
||||
- Daniel Cothran - [andileco](https://www.drupal.org/u/andileco)
|
||||
- Beakerboy - [Beakerboy](https://www.drupal.org/u/beakerboy)
|
||||
|
||||
**Supporting organization:**
|
||||
- [John Snow, Inc. (JSI)](https://www.drupal.org/john-snow-inc-jsi)
|
||||
16
web/modules/views_simple_math_field/composer.json
Normal file
16
web/modules/views_simple_math_field/composer.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "drupal/views_simple_math_field",
|
||||
"type": "drupal-module",
|
||||
"description": "Math operations over selected fields",
|
||||
"homepage": "https://www.drupal.org/project/views_simple_math_field",
|
||||
"license": "GPL-2.0+",
|
||||
"minimum-stability": "dev",
|
||||
"require": {
|
||||
"andileco/eval-math": "^3.0.1",
|
||||
"drupal/core": "^8.7|^9.0 || ^10 || ^11"
|
||||
},
|
||||
"support": {
|
||||
"issues": "https://www.drupal.org/project/issues/views_simple_math_field",
|
||||
"source": "http://cgit.drupalcode.org/views_simple_math_field"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
views.field.field_views_simple_math_field:
|
||||
type: views_field
|
||||
label: 'Simple Math Field'
|
||||
mapping:
|
||||
fieldset_one:
|
||||
label: 'Fieldset One'
|
||||
type: mapping
|
||||
data_fields:
|
||||
type: sequence
|
||||
label: 'Data Fields'
|
||||
sequence:
|
||||
type: string
|
||||
label: 'Data Field'
|
||||
formula:
|
||||
label: 'Formula'
|
||||
type: string
|
||||
mute_logs:
|
||||
type: boolean
|
||||
label: 'Mute database logs for this field'
|
||||
|
||||
views.sort.views_simple_math_field_sort:
|
||||
type: views_sort
|
||||
label: 'Simple Math Fields'
|
||||
mapping:
|
||||
simple:
|
||||
label: 'Simple math fields'
|
||||
type: string
|
||||
8
web/modules/views_simple_math_field/ludwig.json
Normal file
8
web/modules/views_simple_math_field/ludwig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"require": {
|
||||
"andileco/eval-math": {
|
||||
"version": "3.0.1",
|
||||
"url": "https://github.com/andileco/eval-math/archive/3.0.1.zip"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,514 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\views_simple_math_field\Plugin\views\field;
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\views\Plugin\views\field\NumericField;
|
||||
use Drupal\views\ResultRow;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Andileco\Util\EvalMath\EvalMath;
|
||||
use Drupal\Core\Url;
|
||||
use Andileco\Util\EvalMath\Exception\DivisionByZeroException;
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Defines Drupal\views_simple_math_field\Plugin\views\field\SimpleMathField.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to complete mathematical operation.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
* @ViewsField("field_views_simple_math_field")
|
||||
*/
|
||||
class SimpleMathField extends NumericField implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* Support multiple commerce price fields.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commercePriceFields = [
|
||||
'commerce_price_default',
|
||||
'commerce_product_variation',
|
||||
'commerce_price_plain',
|
||||
'commerce_price_calculated',
|
||||
'commerce_order_total_summary',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->entityTypeManager = $entityTypeManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function usesGroupBy() {
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the initial field data at zero.
|
||||
*/
|
||||
public function query() {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function defineOptions() {
|
||||
$options = parent::defineOptions();
|
||||
|
||||
// Give this field and alias.
|
||||
$this->field_alias = 'field_views_simple_math_field';
|
||||
|
||||
$options['fieldset_one']['default'] = NULL;
|
||||
$options['fieldset_one']['data_fields'] = ['default' => NULL];
|
||||
$options['fieldset_one']['formula'] = ['default' => NULL];
|
||||
$options['mute_logs'] = ['default' => 0];
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
parent::buildOptionsForm($form, $form_state);
|
||||
$fieldDelta = preg_replace('[\D]', '', $this->options['id']);
|
||||
$fieldList = $this->displayHandler->getFieldLabels();
|
||||
foreach ($fieldList as $key => $value) {
|
||||
if ($this->field_alias === $key && $fieldDelta < preg_replace('[\D]', '', $key)) {
|
||||
unset($fieldList[$key]);
|
||||
}
|
||||
else {
|
||||
$fieldList[$key] .= new FormattableMarkup(". Formula token: @%field", ["%field" => $key]);
|
||||
}
|
||||
}
|
||||
unset($fieldList[$this->options['id']]);
|
||||
$form['fieldset_one'] = [
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Select the fields to use in the formula.'),
|
||||
'#collapsible' => FALSE,
|
||||
'#collapsed' => FALSE,
|
||||
'#weight' => -10,
|
||||
'#required' => TRUE,
|
||||
];
|
||||
$form['fieldset_one']['data_field'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Data Fields'),
|
||||
'#options' => $fieldList,
|
||||
'#default_value' => $this->options['fieldset_one']['data_field'],
|
||||
'#weight' => -10,
|
||||
];
|
||||
$form['fieldset_one']['formula'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Formula'),
|
||||
'#default_value' => $this->options['fieldset_one']['formula'],
|
||||
'#weight' => -8,
|
||||
'#description' => t('Enter the formula to give this field its value. You can use any fields specified in the checkboxes above, using the formula token listed beside the field name. It uses the EvalMath library, refer to this web to see math expressions: <a href=":url">project in github</a>.', [
|
||||
':url' => Url::fromUri('https://github.com/andileco/eval-math')
|
||||
->toString(),
|
||||
]),
|
||||
];
|
||||
$form['mute_logs'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Mute database logs for this field'),
|
||||
'#default_value' => $this->options['mute_logs'],
|
||||
'#weight' => -7,
|
||||
'#description' => t('Normally, a DivisionByZeroException will occur if you attempt to divide a number by zero within your Views Simple Math Field. If you are plotting data containing zeros, for example, and know that this exception is likely to occur, you can check this box to prevent logging of this exception in your Drupal database log.'),
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the field type we are dealing with.
|
||||
*
|
||||
* @param string $field
|
||||
* The view field name string.
|
||||
*
|
||||
* @return string
|
||||
* The type of field as understood by Views.
|
||||
*/
|
||||
protected function getFieldType($field) {
|
||||
$field_handler = $this->displayHandler->getHandler('field', $field)->options;
|
||||
if (!empty($field_handler['type'])) {
|
||||
$field_type = $field_handler['type'];
|
||||
}
|
||||
else {
|
||||
$field_type = 'undefined';
|
||||
}
|
||||
|
||||
return $field_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the field plugin we are dealing with.
|
||||
*
|
||||
* @param string $field
|
||||
* A view field name string.
|
||||
*
|
||||
* @return string
|
||||
* The field plugin ID.
|
||||
*/
|
||||
protected function getFieldPlugin($field) {
|
||||
$field_handler = $this->displayHandler->getHandler('field', $field)->options;
|
||||
if (!empty($field_handler['plugin_id'])) {
|
||||
$field_plugin = $field_handler['plugin_id'];
|
||||
}
|
||||
else {
|
||||
$field_plugin = 'undefined';
|
||||
}
|
||||
|
||||
return $field_plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the field comes from a relationship.
|
||||
*
|
||||
* @param string $field
|
||||
* The view field name string.
|
||||
*
|
||||
* @return mixed
|
||||
* The relationship as defined by Views.
|
||||
*/
|
||||
protected function getFieldRelationship($field) {
|
||||
$field_handler = $this->displayHandler->getHandler('field', $field)->options;
|
||||
if (!empty($field_handler['relationship']) && $field_handler['relationship'] !== 'none') {
|
||||
$relationship = $field_handler['relationship'];
|
||||
}
|
||||
else {
|
||||
$relationship = NULL;
|
||||
}
|
||||
|
||||
return $relationship;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the field is rewritten/altered.
|
||||
*
|
||||
* @param string $field
|
||||
* The view field name string.
|
||||
*
|
||||
* @return mixed
|
||||
* The text of the rewritten field.
|
||||
*/
|
||||
protected function getRewriteStatus($field) {
|
||||
$field_handler = $this->displayHandler->getHandler('field', $field)->options;
|
||||
if (isset($field_handler['alter']['alter_text']) && !empty($field_handler['alter']['text'])) {
|
||||
$alter = $field_handler['alter']['text'];
|
||||
}
|
||||
else {
|
||||
$alter = NULL;
|
||||
}
|
||||
|
||||
return $alter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entity referenced in the view relationship.
|
||||
*
|
||||
* @param \Drupal\views\ResultRow $values
|
||||
* The ResultRow object.
|
||||
* @param string $field
|
||||
* The view field name string.
|
||||
* @param mixed $relationship
|
||||
* The View relationship.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityInterface|null
|
||||
* The relationship entity.
|
||||
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
|
||||
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
|
||||
*/
|
||||
protected function getRelationshipEntity(ResultRow $values, $field, $relationship) {
|
||||
$relationship_entity = NULL;
|
||||
// Get the entity type of the relationship.
|
||||
$relationship_entity_type = $this->displayHandler
|
||||
->getHandler('field', $field)->getEntityType();
|
||||
$relationship_entities = $values->_relationship_entities;
|
||||
// First check the referenced entity.
|
||||
if (isset($relationship_entities[$relationship])) {
|
||||
// Get the id of the relationship entity.
|
||||
$entity_id = $relationship_entities[$relationship]->id();
|
||||
// Get the data of the relationship entity.
|
||||
$relationship_entity = $this->entityTypeManager
|
||||
->getStorage($relationship_entity_type)
|
||||
->load($entity_id);
|
||||
}
|
||||
|
||||
return $relationship_entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove thousands marker.
|
||||
*
|
||||
* @param string $field
|
||||
* The view field name string.
|
||||
* @param mixed $data
|
||||
* The number that may need a thousands separator removed.
|
||||
*
|
||||
* @return mixed
|
||||
* The resulting number with thousands separator removed.
|
||||
*/
|
||||
protected function removeSeparator($field, $data) {
|
||||
if (!empty($this->view->field[$field]->options['separator'])) {
|
||||
$separator = $this->view->field[$field]->options['separator'];
|
||||
}
|
||||
if (!empty($separator)) {
|
||||
if (strpos($data, $separator)) {
|
||||
$data = str_replace($separator, '', $data);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Even if a separator has not been selected, your data may have a
|
||||
* common separator already applied. This is a very U.S.-centric
|
||||
* approach, so open to other ideas here!
|
||||
*/
|
||||
else {
|
||||
if (strpos($data, ',')) {
|
||||
$data = str_replace(',', '', $data);
|
||||
}
|
||||
if (strpos($data, ' ')) {
|
||||
$data = str_replace(' ', '', $data);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a simple math field.
|
||||
*
|
||||
* @param \Drupal\views\ResultRow $values
|
||||
* Row results.
|
||||
* @param \Drupal\Core\Entity\EntityInterface|null $entity
|
||||
* The current row entity.
|
||||
* @param bool $field
|
||||
* The field we are fetching.
|
||||
*
|
||||
* @return mixed
|
||||
* The field value.
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function getFieldValue(ResultRow $values, $entity, $field) {
|
||||
// Determine what type of field is being used.
|
||||
$field_type = $this->getFieldType($field);
|
||||
// Determine what type of field plugin is being used.
|
||||
$field_plugin = $this->getFieldPlugin($field);
|
||||
// If the field is rewritten, get the rewritten text. Else, returns null.
|
||||
$rewritten = $this->getRewriteStatus($field);
|
||||
// Check if the display is aggregated. Not needed right now.
|
||||
// $isAggregated = $this->view->getDisplay()->getOption('group_by');
|
||||
$data = NULL;
|
||||
// Compatibility with the views_entity_form_field module.
|
||||
if ($field_plugin === 'entity_form_field') {
|
||||
$field_handler = $this->displayHandler->getHandler('field', $field)->options;
|
||||
if (!empty($field_handler['plugin']['type'])) {
|
||||
$field_type = $field_handler['plugin']['type'];
|
||||
}
|
||||
if (!empty($field_handler['field'])) {
|
||||
$form_field = $field_handler['field'];
|
||||
$prefix = 'form_field_';
|
||||
if (0 === strpos($form_field, $prefix)) {
|
||||
$field = substr($form_field, strlen($prefix));
|
||||
}
|
||||
}
|
||||
$relationship = $this->getFieldRelationship($field);
|
||||
if ($relationship) {
|
||||
// Use the relationship's entity to fetch the field value.
|
||||
$entity = $this->getRelationshipEntity($values, $field, $relationship);
|
||||
}
|
||||
// For Commerce fields.
|
||||
if (in_array($field_type, $this->commercePriceFields)) {
|
||||
$commerce_field_id = $this->displayHandler->getHandler('field', 'form_field_' . $field)->options['id'];
|
||||
if ($entity->hasField($commerce_field_id) && !empty($entity->get($commerce_field_id)->getValue())) {
|
||||
$data = $entity->get($commerce_field_id)->first()->toPrice();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$data = $entity->get($field)->getValue()[0]['value'];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Process if not undefined.
|
||||
if ($field_type !== 'undefined') {
|
||||
// Get the value of a field that comes from a relationship.
|
||||
$relationship = $this->getFieldRelationship($field);
|
||||
if ($relationship) {
|
||||
// Use the relationship's entity to fetch the field value.
|
||||
$entity = $this->getRelationshipEntity($values, $field, $relationship);
|
||||
}
|
||||
// The next two statements handle fields with or without a relationship.
|
||||
if (isset($entity) && $rewritten) {
|
||||
// If already numeric, there is no need for advancedRender().
|
||||
if (is_numeric($rewritten) == TRUE) {
|
||||
$data = $rewritten;
|
||||
}
|
||||
else {
|
||||
// @todo Rewrite using dependency injection.
|
||||
if (\Drupal::routeMatch()->getRouteName() == 'entity.view.preview_form') {
|
||||
\Drupal::service('messenger')
|
||||
->addMessage(t('It appears that <em>@field</em> is rewritten and requires advanced rendering. Do not use the Views Simple Math Field sort handler for this View.', [
|
||||
'@field' => $field,
|
||||
]), 'warning');
|
||||
}
|
||||
$data = $this->view->field[$field]->advancedRender($values);
|
||||
}
|
||||
}
|
||||
if (isset($entity) && !$rewritten) {
|
||||
// Gets the value from the row, which works when aggregated (or not).
|
||||
$data = $this->view->field[$field]->getValue($values);
|
||||
|
||||
/*
|
||||
* Keeping these here, but I've commented out in favor of the above
|
||||
* line, as this was not working with aggregation.
|
||||
* $field_base = $this->displayHandler
|
||||
* ->getHandler('field', $field)->field;
|
||||
* if ($entity->hasField($field_base)) {
|
||||
* $data = $entity->get($field_base)->getValue()[0]['value'];
|
||||
* }
|
||||
*/
|
||||
|
||||
// For Commerce fields.
|
||||
if (in_array($field_type, $this->commercePriceFields)) {
|
||||
$commerce_field_id = $this->displayHandler->getHandler('field', $field)->options['id'];
|
||||
if ($entity->hasField($commerce_field_id) && !empty($entity->get($commerce_field_id)->getValue())) {
|
||||
$data = $entity->get($commerce_field_id)->first()->toPrice();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Some fields, such as fields from Views Database Connector, pull
|
||||
* directly from the database or an index. This attempts to handle those
|
||||
* types of fields.
|
||||
*/
|
||||
else {
|
||||
if (isset($this->view->field[$field]->original_value)) {
|
||||
$data = $this->view->field[$field]->original_value;
|
||||
}
|
||||
// Decided to leave this as a fallback.
|
||||
else {
|
||||
$data = $this->view->field[$field]->getValue($values);
|
||||
}
|
||||
|
||||
if ($rewritten) {
|
||||
// @todo Rewrite using dependency injection.
|
||||
if (\Drupal::routeMatch()->getRouteName() == 'entity.view.preview_form') {
|
||||
\Drupal::service('messenger')
|
||||
->addMessage(t('Views Simple Math Field sometimes has difficulty rendering the correct value for rewritten fields. You may want to double check that field ID <em>@field</em> is properly outputting a value.', [
|
||||
'@field' => $field,
|
||||
]), 'warning');
|
||||
}
|
||||
$data = $this->displayHandler->getHandler('field', $field)
|
||||
->advancedRender($values);
|
||||
}
|
||||
}
|
||||
|
||||
// There's no value. Default to 0.
|
||||
if (!isset($data)) {
|
||||
$data = 0;
|
||||
}
|
||||
|
||||
// Remove the thousands marker.
|
||||
$data = $this->removeSeparator($field, $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getValue(ResultRow $values, $field = NULL) {
|
||||
parent::getValue($values, $field);
|
||||
|
||||
// If no fields are selected as data fields, return NULL.
|
||||
if (!isset($this->options['fieldset_one']['data_field'])) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Get the entity from the row.
|
||||
$entity = $this->getEntityOrNull($values);
|
||||
|
||||
// Collect all the fields checked.
|
||||
$fields_in_formula = [];
|
||||
foreach ($this->options['fieldset_one']['data_field'] as $key => $value) {
|
||||
if ($value) {
|
||||
$raw_field_in_formula = $this->getFieldValue($values, $entity, $key);
|
||||
// Filter and sanitize out the float values.
|
||||
if (preg_match('/^.*?([\d]+(?:\.[\d]+)?).*?$/', $raw_field_in_formula, $match)) {
|
||||
$raw_field_in_formula_sane = floatval($match[0]);
|
||||
$fields_in_formula['@' . $key] = filter_var($raw_field_in_formula_sane, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
|
||||
}
|
||||
else {
|
||||
$fields_in_formula['@' . $key] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Format the numbers to a string that EvalMath can evaluate.
|
||||
$formula = new FormattableMarkup($this->options['fieldset_one']['formula'], $fields_in_formula);
|
||||
$m = new EvalMath();
|
||||
try {
|
||||
$result = $m->evaluate($formula);
|
||||
}
|
||||
catch (DivisionByZeroException $e) {
|
||||
if ($this->options['mute_logs'] != 1) {
|
||||
\Drupal::logger('views_simple_math_field')
|
||||
->error('DivisionByZeroException');
|
||||
}
|
||||
}
|
||||
|
||||
// Return the value if evaluate is successful.
|
||||
return $result ?? NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entity from the row.
|
||||
*
|
||||
* @param \Drupal\views\ResultRow $values
|
||||
* The ResultRow object.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityInterface|null
|
||||
* The entity.
|
||||
*/
|
||||
public function getEntityOrNull(ResultRow $values): ?object {
|
||||
// Get the entity from the row.
|
||||
if (!empty($values->_entity)) {
|
||||
return $this->getEntity($values);
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static($configuration, $plugin_id, $plugin_definition,
|
||||
$container->get('entity_type.manager')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\views_simple_math_field\Plugin\views\sort;
|
||||
|
||||
use Drupal\views\Plugin\views\field\FieldPluginBase;
|
||||
use Drupal\views\Plugin\views\sort\SortPluginBase;
|
||||
use Drupal\views\ResultRow;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Handler which sort by the similarity.
|
||||
*
|
||||
* @ingroup views_sort_handlers
|
||||
*
|
||||
* @ViewsSort("views_simple_math_field_sort")
|
||||
*/
|
||||
class ViewsSimpleMathFieldSort extends SortPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function defineOptions() {
|
||||
$options = parent::defineOptions();
|
||||
$options['simple'] = ['default' => ''];
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function postExecute(&$values) {
|
||||
$view = $this->view;
|
||||
$order = $this->options['order'];
|
||||
foreach ($this->view->result as $result) {
|
||||
$sm_field = $view->field[$this->options['simple']]->getValue($result);
|
||||
$this->view->result[$result->index]->{$this->options['simple']} = $sm_field;
|
||||
}
|
||||
if ($order === 'ASC') {
|
||||
usort($this->view->result, function ($item1, $item2) {
|
||||
return $item1->{$this->options['simple']} <=> $item2->{$this->options['simple']};
|
||||
});
|
||||
}
|
||||
else {
|
||||
usort($this->view->result, function ($item1, $item2) {
|
||||
return $item2->{$this->options['simple']} <=> $item1->{$this->options['simple']};
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
parent::buildOptionsForm($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function showSortForm(&$form, FormStateInterface $form_state) {
|
||||
parent::showSortForm($form, $form_state);
|
||||
$simpleOptions = [];
|
||||
$fieldsOptions = $this->displayHandler->getFieldLabels();
|
||||
foreach ($fieldsOptions as $key => $value) {
|
||||
if (strpos($key, 'field_views_simple_math_field') !== FALSE) {
|
||||
$simpleOptions[$key] = $value;
|
||||
}
|
||||
}
|
||||
if (!empty($simpleOptions)) {
|
||||
$form['simple'] = [
|
||||
'#title' => $this->t('Simple math fields'),
|
||||
'#type' => 'radios',
|
||||
'#options' => $simpleOptions,
|
||||
'#default_value' => $this->options['simple'],
|
||||
'#required' => TRUE
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
name: Views Simple Math Field
|
||||
description: 'Creates a Views field handler that enables you to perform simple math expressions'
|
||||
type: module
|
||||
package: Views
|
||||
core_version_requirement: ^8.8 || ^9 || ^10 || ^11
|
||||
dependencies:
|
||||
- drupal:views
|
||||
|
||||
# Information added by Drupal.org packaging script on 2024-06-26
|
||||
version: '3.0.2'
|
||||
project: 'views_simple_math_field'
|
||||
datestamp: 1719379403
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Implements hook_views_data().
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_views_data().
|
||||
*/
|
||||
function views_simple_math_field_views_data() {
|
||||
$data['views_simple_math_field']['table']['group'] = t('Global');
|
||||
$data['views_simple_math_field']['table']['join'] = [
|
||||
// Exist in all views.
|
||||
'#global' => [],
|
||||
];
|
||||
$data['views_simple_math_field']['field_views_simple_math_field'] = [
|
||||
'title' => t('Simple Math Field'),
|
||||
'help' => t('Views field that performs simple math expressions.'),
|
||||
'field' => [
|
||||
'id' => 'field_views_simple_math_field',
|
||||
// Allow users to specify how precise the results should be. Useful for divisions
|
||||
'float' => TRUE,
|
||||
],
|
||||
'sort' => [
|
||||
'id' => 'views_simple_math_field_sort',
|
||||
],
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
Reference in New Issue
Block a user