You are here

function ds_ui_limit_validate in Display Suite 7.2

Element validation function for ui limit field.

1 string reference to 'ds_ui_limit_validate'
ds_shared_form in modules/ds_ui/includes/ds.fields.inc
Shared form for all fields.

File

modules/ds_ui/includes/ds.fields.inc, line 198
Administrative functions for managing custom fields for every entity.

Code

function ds_ui_limit_validate($element, &$form_state, $form) {

  // Get all enabled entity types.
  $entity_types = array_filter($form_state['values']['entities']);
  if (!empty($element['#value'])) {
    $ui_limit = $element['#value'];
    $lines = explode("\n", str_replace("\r", "\n", $ui_limit));

    // Ensure that all strings are trimmed and filter out empty lines.
    $lines = array_filter(array_map('trim', $lines));
    $error = FALSE;
    foreach ($lines as $line) {

      // Each line should hold a pipe character to seperate bundle and view_mode.
      if (strpos($line, '|') === FALSE) {
        $error = TRUE;
        continue;
      }
      list($bundle, $view_mode) = explode('|', $line);
      if (empty($bundle) || empty($view_mode) || !_ds_check_existing_ui_limit($entity_types, $bundle, $view_mode)) {
        $error = TRUE;
      }
    }
    if ($error) {
      form_error($element, t('The values are in the form of $bundle|$view_mode, where $view_mode may be either a view mode set to use custom settings, or \'default\'.'));
    }

    // Set trimmed and validated entry back as value.
    form_set_value($element, implode("\n", $lines), $form_state);
  }
}