protected function Bean::checkDelta in Bean (for Drupal 7) 7
Set the delta function
File
- includes/
bean.core.inc, line 395 - Bean classes and plugin interface
Class
- Bean
- The Bean entity class
Code
protected function checkDelta() {
if (empty($this->delta)) {
$max_length = 32;
// Base it on the label and make sure it isn't too long for the database.
if (module_exists('transliteration')) {
$delta = drupal_clean_css_identifier(strtolower(transliteration_get($this->label)));
}
else {
$delta = drupal_clean_css_identifier(strtolower($this->label));
}
// Add 'bean-' prefix when it's need to avoid a purely numeric delta.
if (is_numeric($delta)) {
$delta = 'bean-' . $delta;
}
$this->delta = substr($delta, 0, $max_length);
// Check if delta is unique.
if ($this
->deltaExists($this->delta)) {
$i = 0;
$separator = '-';
$original_delta = $this->delta;
do {
$unique_suffix = $separator . $i++;
$this->delta = substr($original_delta, 0, $max_length - drupal_strlen($unique_suffix)) . $unique_suffix;
} while ($this
->deltaExists($this->delta));
}
}
return $this;
}