Commit af12bfee authored by Stéphane Corlosquet's avatar Stéphane Corlosquet
Browse files

support for field form

parent de85218d
Loading
Loading
Loading
Loading
+55 −1
Original line number Diff line number Diff line
@@ -57,7 +57,61 @@ function schemaorg_node_type_form_submit($form, &$form_state) {

  rdf_mapping_save(array(
    'type' => 'node',
    'bundle' => $form_state['values']['type'],
    'bundle' => $bundle,
    'mapping' => $mapping,
    )
  );
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function schemaorg_form_field_ui_field_edit_form_alter(&$form, &$form_state) {
  $field_name = $form['#field']['field_name'];
  $bundle = $form['instance']['bundle']['#value'];
  $instance = $form['instance'];
  $label = isset($instance['label']) ? $instance['label']['#default_value'] : $instance['field_name'];
  $entity_type = $instance['entity_type']['#value'];
  $mapping = rdf_mapping_load($entity_type, $instance['bundle']['#value']);

  $form['schemaorg'] = array(
    '#type' => 'fieldset',
    '#title' => t('%label schema.org mapping', array('%label' => $label)),
  );

  $form['schemaorg']['schemaorg_field_property'] = array(
    '#type' => 'textfield',
    '#title' => t('Property'),
    '#description' => t('Specify the property you want to associated to this field.'),
    '#default_value' => schemaorg_term_load('node', $bundle, $field_name),
    '#attributes' => array('class' => array('schemaorg-autocomplete-properties')),
  );

  $form['#submit'][] = 'schemaorg_field_ui_field_edit_form_submit';
  // Use jQuery UI autocomplete to provide a faster autocomplete without
  // callback to the server.
  $form['#attached']['library'][] = array('system', 'ui.autocomplete');
  $form['#attached']['css'][] = drupal_get_path('module', 'schemaorg') . '/css/schemaorg.jquery.ui.theme.css';
  $form['#attached']['js'][] = drupal_get_path('module', 'schemaorg') . '/js/schemaorg.js';
  $form['#attached']['js'][] =  array(
        'data' => array('schemaorgapiTermsPath' => base_path() . drupal_get_path('module', 'schemaorg') . '/js/schemaorg.terms.json'),
        'type' => 'setting'
  );
}

/**
 * Submit function for edit field form.
 */
function schemaorg_field_ui_field_edit_form_submit($form, &$form_state) {
  $bundle = $form['instance']['bundle']['#value'];
  $field_name = $form['#field']['field_name'];

  $mapping = rdf_mapping_load('node', $bundle);
  $mapping[$field_name]['predicates'] = schemaorg_terms_merge($form_state['values']['schemaorg_field_property'], $mapping[$field_name]['predicates']);

  rdf_mapping_save(array(
    'type' => 'node',
    'bundle' => $bundle,
    'mapping' => $mapping,
    )
  );