You are here

function media_element_validate in D7 Media 7

Same name and namespace in other branches
  1. 7.4 media.module \media_element_validate()
  2. 7.2 media.module \media_element_validate()
  3. 7.3 media.module \media_element_validate()

Validate media form elements. The file type is validated during the upload process, but this is necessary in order to respect the #required property.

1 string reference to 'media_element_validate'
media_element_info in ./media.module
Implements hook_element_info().

File

./media.module, line 1014
Media API

Code

function media_element_validate(&$element, &$form_state) {
  if ($element['#required']) {
    $field_name = $element['#field_name'];
    $lang = $element['#language'];
    $has_value = FALSE;
    $widget_parents = $element['#array_parents'];
    array_pop($widget_parents);
    $items = drupal_array_get_nested_value($form_state['values'], $widget_parents);
    foreach ($items as $value) {
      if (is_array($value) && !empty($value['fid'])) {
        $has_value = TRUE;
      }
    }
    if (!$has_value) {
      form_error($element, t('%element_title is required.', array(
        '%element_title' => $element['#title'],
      )));
    }
  }
}