You are here

function parallax_block_validate_size in Parallax Toolkit 7.2

Same name and namespace in other branches
  1. 7.3 parallax_block/parallax_block.module \parallax_block_validate_size()

Validation for Background Size text values.

1 string reference to 'parallax_block_validate_size'
parallax_block_form_alter in parallax_block/parallax_block.module
Implements hook_form_alter().

File

parallax_block/parallax_block.module, line 132
Enable Parallax effect for any block created by the user.

Code

function parallax_block_validate_size($element, &$form_state) {
  $allowed_text_values = array(
    'none',
    'cover',
    'contain',
  );
  $value = strtolower($form_state['values']['background_size']);
  $value_length = strlen($value);
  $is_percentage = strpos($value, '%') && strpos($value, '%') == $value_length - 1 ? TRUE : FALSE;
  $is_pixel = strpos($value, 'px') && strpos($value, 'px') == $value_length - 2 ? TRUE : FALSE;
  $valid_text = in_array($value, $allowed_text_values) ? TRUE : FALSE;
  if (!$is_pixel && !$is_percentage && !$valid_text) {
    form_error($element, t('Allowed values include cover, contain, none. Pixel and percentage based sizes should be specified as "***px" and "***%", respectively, with no characters after the "%", "px"'));
  }
}