Skip to content

Instantly share code, notes, and snippets.

@ccamara
Last active December 18, 2015 10:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccamara/5772934 to your computer and use it in GitHub Desktop.
Save ccamara/5772934 to your computer and use it in GitHub Desktop.
Example of implementation of a hook validate #drupal
<?php
/**
* Implements hook_node_validate().
*
* Makes image field required.
*/
function mymodule_node_validate($node, $form, &$form_state) {
if ($node->type == 'carrousel_item') {
if (! isset($form_state['values']['field_summary_image'][LANGUAGE_NONE]['0']['entity']->field_media_summary_image[LANGUAGE_NONE][0]['fid']) ||
$form_state['values']['field_summary_image'][LANGUAGE_NONE]['0']['entity']->field_media_summary_image[LANGUAGE_NONE][0]['fid'] == 0) {
form_set_error('field_summary_image', t('Image field is required'));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment