Let's add some useful and easy to implement text processing capabilities:

  • convert to upper / lower case
  • trim string
  • strip tags
  • encode / decode html entities
  • reverse text
  • sort & reverse sort lists (numerically and alphabetically)

Original issue:
Sometimes I only need aliases for a few content types, but I don't want the overhead and full fledged features of the pathauto module. Creating a rule to make path aliases is pretty painless, but I was wondering if it is or would be possible to transform the aliases to lowercase in the rules. At this time, it only seems possible to use the case of the node title.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mitchell’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
Component: Rules Core » Rules Engine

Bumping feature request to 7.x.

Judging by fago's comment in #852596: Port path module integration, this'll probably be easier with pluggable path cleaners.

fago’s picture

Category: feature » task

Indeed. Maybe we could add a textual data processor doing that? We could also offer some other simple text processing options like strip html tags.

fago’s picture

Title: Transform text case in path alias creating » Add basic text processing capabilities

Suggestions for other useful and easy to implement text processing capabilities are welcome. So far I think
* make lower/uper case
* ucfirst char
* strip html tags

would be useful.

fago’s picture

bump. We still need that.

mitchell’s picture

A very similar set of functionality is currently available to Feeds through its preprocessing hook in an extension, called Feeds Tamper. Here is a link to all the text processors which will be easy to port and will work very well in a generalized fashion: http://drupalcode.org/project/feeds_tamper.git/tree/refs/heads/7.x-1.x:/...

mitchell’s picture

Title: Add basic text processing capabilities » Add basic data processing capabilities
mitchell’s picture

Marked #1323056: Calculations and Rounding as a duplicate.

Rounding is basically trim, I think.

mitchell’s picture

Status: Active » Needs review

Some long overdue code can be found in Rules Data Transforms. I originally intended to have this code posted here as a patch, but that'll be next on my list. In any event, @maintainers, please review the code and let me know if there's anything specific that needs to be changed in order to have it merged and if a separate project is necessary in your minds.

mitchell’s picture

Re: #7. I was wrong. Rounding is a separate function. Added #1371492: Rounding to rules_data_transforms.

mitchell’s picture

Title: Add basic data processing capabilities » Add basic data transformation capabilities

Transformation seems a bit more refined over processing.

AndrzejG’s picture

@Mitchell - please update dev of Your module, to include this Rounding function.

mitchell’s picture

Title: Add basic data transformation capabilities » Add data transformation capabilities
Category: task » feature
Priority: Normal » Major
Issue tags: +data transforms
FileSize
8.85 KB

Uploading a tar.gz of requested code. If someone else can help by reviewing the code and submitting a patch, I would really appreciate it. Coding isn't my expertise, and I've already done quite a bit to produce this.

Known bug: #1429076: Action: 'make uppercase' doesn't work.

See also, Issues tagged 'data transforms' for more related code improvements and use cases.

freddura’s picture

For the action "combine list into string" it would beneficial to be able to select a multi-value field as a list option from within the data selector. For example, if a have a multi-value integer field titled "field-integer-list" which resides in the node being viewed, then I should be able to select that integer list directly from within the data selector by typing in and receiving a match: "node:field-integer-list." Instead I receive a match: "node:field-integer-list:" When I change the match to "node:field-integer-list" and click save, I receive an error message: "The data type of the configured argument does not match the parameter's input_list requirement."

Look forward to this patch being committed to the rules module nevertheless. Thanks!

mitchell’s picture

Title: Add data transformation capabilities » Action: transform text
Assigned: Unassigned » fago
FileSize
12.91 KB

Here's a patch with the functions listed in the issue summary:

Current Bugs

  • Transform actions aren't loaded. To test, install from the 'sandbox' project
  • 'Implode list' has incorrectly named variable, patch
  • 'Make uppercase' is broken

The code does work. drush dl rules_data_transforms will get you up and running. The patch is mainly here to illustrate where the code might go and how it might look.

@fago, what do you think of the coding style and organization? I don't like adding a second file, like I did here, but organizing it as you did in data.eval.inc and data.rules.inc is a bit difficult. I started #1540394: Make Data API's module integrations pluggable to address this in a way that will deal with the other data related patches.

Side note: I had really hoped that by renaming rules_data_transforms.rules.inc to data_transforms.rules.inc and putting it Rule's modules dir, it would work. The file and function names seemed to align, but I cleaned my cache and was not so lucky, so I'm interested to find out why it didn't work.

mitchell’s picture

Issue summary: View changes

update

mitchell’s picture

I removed 'implode & explode lists', 'combine lists', and 'permute lists' from this issue, because they fit better in another.

Also, 'convert string to date' is also addressed in #1301022: Action: type conversion for numbers, integers, and strings. It's better suited there.

mitchell’s picture

Assigned: fago » mitchell
Status: Needs review » Needs work

In order to get this to a review-able state, this patch needs to be rewritten to extend data.rules.inc and data.eval.inc. I will see if can handle the port in the next few days, but if I don't post anything with a week, consider me unassigned.

I really want to see this go in soon, but if you do to, then trust me... you're coding skills are better than mine.

tr33m4n’s picture

I posted this on the rules data transform module page, thought I'd post it here as well. Attached a patch that allows first word only capitalization or capitalization of every word in the string.

Cheers

dmoonman’s picture

klonos’s picture

Component: Rules Engine » Rules Core

Thanx for bumping this Derek ;)

klonos’s picture

Issue summary: View changes

a

mjcarter’s picture

Issue summary: View changes

The rules_data_transforms module has existing features and number of patches waiting to be committed adding features which aren't specifically related to text handling - things like unserializing data and converting from one array type to another.

At the moment the module is marked as a temporary code location for things related to this issue.

My thoughts are that rules_data_transforms may contribute more to the community by remaining a separate module which handles all advanced data manipulation not carried out by rules itself, sort of equivalent to the feeds_tamper module's relation to feeds - particularly in light of the lack of progress on this issue.

What are others thoughts on this?

sonicthoughts’s picture

Stumbled on this - exactly what I'm looking for but totally hidden! Biggest reason to add to Rules as a submodule is so people know it exists!

jelo’s picture

Could the maintainers clarify what the approach going forward is going to be, e.g. integration into rules, sub-module of rules or separate module? I find these additional actions very useful. Unfortunately, Rules Data Transform at https://www.drupal.org/project/rules_data_transforms is only in dev and still states it is temporary while this discussion started more than 4 years ago. The functionality seems to be working though...

Thanks!

thePanz’s picture

I would also add my module: https://www.drupal.org/sandbox/thepanz/rules_list_extra to the list.
It focuses on lists, the first action supported is "merge list", and I am planning to add further functions.

Support and help needed, or could it be better to integrate it with rules_data_transform module?

dercheffe’s picture

IMHO a very important feature. +1