class TamperConvertCase in Tamper 7
Converts the case of a string.
Hierarchy
- class \TamperPluginBase implements TamperPluginInterface
- class \TamperConvertCase
 
 
Expanded class hierarchy of TamperConvertCase
1 string reference to 'TamperConvertCase'
- convert_case.inc in plugins/
convert_case.inc  
File
- src/
Plugins/ TamperConvertCase.php, line 11  - Contains TamperConvertCase.
 
View source
class TamperConvertCase extends TamperPluginBase {
  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return array(
      'mode' => 'upper',
    );
  }
  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, array &$form_state) {
    $form['mode'] = array(
      '#type' => 'radios',
      '#title' => t('How to convert case'),
      '#default_value' => $this->configuration['mode'],
      '#options' => array(
        'upper' => t('UPPERCASE THE STRING.'),
        'lower' => t('lowercase the string.'),
        'ucfirst' => t('Make the first char uppercase.'),
        'ucwords' => t('Make Each Word In The String Uppercase.'),
      ),
    );
    return $form;
  }
  /**
   * {@inheritdoc}
   */
  public function execute($value) {
    switch ($this->configuration['mode']) {
      case 'upper':
        return drupal_strtoupper($value);
      case 'lower':
        return drupal_strtolower($value);
      case 'ucfirst':
        return drupal_strtoupper(drupal_substr($value, 0, 1)) . drupal_substr($value, 1);
      case 'ucwords':
        global $multibyte;
        if ($multibyte == UNICODE_MULTIBYTE) {
          return mb_convert_case($value, MB_CASE_TITLE);
        }
        else {
          return ucwords($value);
        }
    }
  }
}