You are here

function iframe_field_validate in Iframe 7

Implements hook_field_validate().

Possible error codes:

  • 'widthheight': The value should be between 1 and 9999, or between 1% and 100%

(entity_type: "node", entity: node-object, field: (field-settings + field-inst-settings) ..., items: current-items-of-page)

File

./iframe.module, line 245
Defines an iframe field with all attributes.

Code

function iframe_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
  foreach ($items as $delta => $item) {
    if (isset($item['url']) && !empty($item['url'])) {
      if (isset($item['width']) && (empty($item['width']) || (int) $item['width'] < 1)) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => '_iframe_widthsize_invalid',
          'message' => t('%name: the value of width may be no less than 1.', array(
            '%name' => t($instance['label']),
          )),
        );
      }
      if (isset($item['height']) && (empty($item['height']) || $item['height'] < 1)) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => '_iframe_heightsize_invalid',
          'message' => t('%name: the value of height may be no less than 1.', array(
            '%name' => t($instance['label']),
          )),
        );
      }
    }
  }
  iframe_debug(1, 'iframe_field_validate errors', $errors);
}