There is not configuration for converting case for text in text effect module. This will be helpful if we use a token and need to convert in case.

Comments

Ajithlal created an issue. See original summary.

fietserwin’s picture

Issue tags: -text effect

Though I can understand the feature request, I doubt if we should add it to the UI, because case conversion comes in many styles: all uppercase, all lowercase, headline style (leaving out simple short words like 'the', 'and', 'a' or not), only first letter.

However, what we could do is introduce some alter hook that passes in the $image and $data variables from the effect and that allows to change the params to your liking. it should be called when the effect function has done its own work on the params but before starting to use them to calculate offsets and such (line 329 of image_effects_text\image_effects_text.inc).

If you provide a patch I will review and eventually commit it.

Ajithlal’s picture

Please find the patch attached. Included four types of case conversion.

  • uppercase
  • lowercase
  • title case
  • sentence case
Ajithlal’s picture

fietserwin’s picture

Status: Active » Needs work

OK, so you want to go with a UI, let's do that.

  1. +++ b/image_effects_text/image_effects_text.inc
    @@ -151,6 +151,19 @@ if ($field) {
    +    'textcase' => array(
    +      '#type' => 'select',
    

    Can you change all usages of textcase to text_case?

  2. +++ b/image_effects_text/image_effects_text.inc
    @@ -151,6 +151,19 @@ if ($field) {
    +    'textcase' => array(
    +      '#type' => 'select',
    +      '#title' => t('Convert to case'),
    +      '#options' => array(
    +        'default' => t('Default'),
    +        'upper' => t('UPPERCASE'),
    +        'lower' => t('lowercase'),
    +        'ucwords' => t('Uppercase Words'),
    +        'ucfirst' => t('Uppercase first'),
    +      ),
    +      '#description' => t('Covert the input text to a consistent format. The default makes no changes to input text.'),
    

    Please have a look at ctools\includes\stylizer.inc where you will find a similar form control. If you use the same wording (and case) for the field and the options, there will be less new translations. But please keep the default value the 1st one (thus do not add an empty option like stylizer does).

  3. +++ b/image_effects_text/image_effects_text.inc
    @@ -151,6 +151,19 @@ if ($field) {
    +      '#description' => t('Covert the input text to a consistent format. The default makes no changes to input text.'),
    +      '#default_value' => isset($data['textcase']) ? $data['textcase'] : 'default',
    

    - typo: Convert.
    - do not use 'format' but 'case'.
    - do not use 'input text' but 'the text'.

  4. +++ b/image_effects_text/image_effects_text.inc
    @@ -151,6 +151,19 @@ if ($field) {
    +      '#default_value' => isset($data['textcase']) ? $data['textcase'] : 'default',
    +    ),
    

    Add the default option to the $defaults at the start of the function, so you don't have to check here if it is set or not.

  5. +++ b/image_effects_text/image_effects_text.inc
    @@ -724,5 +737,31 @@ function image_effects_text_get_text(stdClass $image, array $data) {
    +  // Convert case.
    +  $textcase = $data['textcase'] ? $data['textcase'] : '';
    +  switch ($textcase) {
    

    This gave me a Notice: Undefined index: textcase in image_effects_text_get_text() (line 742 of image_effects_text.inc). Use isset(...) ? : and give it the default value.

Ajithlal’s picture

StatusFileSize
new2.1 KB

Changes are done. Stylizer doesn't have a sentence case conversion. I also included that.

  • fietserwin committed 71a956a on 7.x-1.x
    Issue #2690337 by Ajithlal, fietserwin: Would like a feature for...
fietserwin’s picture

Status: Needs work » Fixed

Thanks, added and committed.

I did a new search if this feature was implemented anywhere else and found module://views/handlers/views_handler_argument_string.inc (line 64) and module://views/includes/handlers.inc (line 340). I liked the wording over there: clearer but still short, so I decided to go for that solution. but to not have to define a dependency on Views, I copied the method case_transform() to this module.

Ajithlal’s picture

Thanks !. Works fine

Status: Fixed » Closed (fixed)

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