Last active
December 18, 2015 10:59
-
-
Save ccamara/5772934 to your computer and use it in GitHub Desktop.
Example of implementation of a hook validate #drupal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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