You are here

class TamperConvertCase in Tamper 7

Converts the case of a string.

Hierarchy

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);
        }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TamperConvertCase::buildConfigurationForm public function Form constructor. Overrides TamperPluginInterface::buildConfigurationForm
TamperConvertCase::defaultConfiguration public function Returns default configuration for this plugin. Overrides TamperPluginInterface::defaultConfiguration
TamperConvertCase::execute public function Executes the plugin. Overrides TamperPluginInterface::execute
TamperPluginBase::$configuration protected property Configuration information passed into the plugin.
TamperPluginBase::$pluginDefinition protected property The plugin implementation definition.
TamperPluginBase::$pluginId protected property The plugin id.
TamperPluginBase::executeMultiple public function Executes the plugin on multiple values. Overrides TamperPluginInterface::executeMultiple
TamperPluginBase::getConfiguration public function Returns this plugin's configuration. Overrides TamperPluginInterface::getConfiguration
TamperPluginBase::getPluginDefinition public function Returns the definition of the plugin implementation. Overrides TamperPluginInterface::getPluginDefinition
TamperPluginBase::getPluginId public function Returns the plugin_id of the plugin instance. Overrides TamperPluginInterface::getPluginId
TamperPluginBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides TamperPluginInterface::setConfiguration
TamperPluginBase::submitConfigurationForm public function Form submission handler. Overrides TamperPluginInterface::submitConfigurationForm
TamperPluginBase::validateConfigurationForm public function Form validation handler. Overrides TamperPluginInterface::validateConfigurationForm
TamperPluginBase::__construct public function Constructs a TamperPluginBase object.