You are here

function panopoly_magic_reusable_entity_validate in Panopoly Magic 7

Validator to ensure that reusable entites have titles.

1 string reference to 'panopoly_magic_reusable_entity_validate'
panopoly_magic_form_fieldable_panels_panes_fieldable_panels_pane_content_type_edit_form_alter in ./panopoly_magic.module
Implementation of hook_form_FORM_ID_alter()

File

./panopoly_magic.module, line 1498

Code

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

  // Don't validate if we're just updating the preview.
  if (!empty($form_state['triggering_element']) && $form_state['triggering_element']['#value'] == 'Update Preview') {
    return;
  }

  // If the reusable entity checkbox is selected.
  if (!empty($form_state['values']['reusable'])) {

    // Ensure a title is present.
    if (empty($element['#value'])) {
      form_error($element, t('If you would like this entity to be reusable, please add a title.'));
    }
  }
}