1

I want create quite a few graphs and display them on my site. I am currently using the highcharts api/drupal module, but i'd like to be able to extend this to any js plotting library. To do this I need to render a graph which takes many fields to set the parameters for the plot. I need this to be tied to a node so that I can add other non-plot related attributes, such as 'category' to associate to the plot. I decided that a single field should be be what renders this plot. To do so I need to create a custom field and custom field formatter. This can be done easy enough with guides such as

http://evolvingweb.ca/story/poutine-maker-introduction-field-api-drupal-7-part-1

This would allow me to define a field which takes in not just a name but all the associated parameters by simply defining a fieldset which creates multiple fields so that I can use all the various parameters and then render the plot with the custom formatter.

I am also separating the data from the graph. I have another content type called 'dataset', since many graphs can be derived from various datasets. The problem is that I would like to reference these datasets from this single field as part of the 'plot' content type. To do so it needs to be part of field form widget which is created with hook_field_widget_form(). I'm not sure how to do this or if it's even possible. To clarify what I'm trying to do here is a snippet of my code (derived largely from the above link):

function plot_extender_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  $field_name = $instance['field_name'];
  $required = $element['#required'];

  $item = & $items[$delta];

  $element += array(
    '#type' => 'fieldset',
  );

  $element['name'] = array(
    '#title' => t('Dataset Name'),
    '#type' => 'textfield',
    '#required' => $required,
    '#default_value' => isset($item['name']) ? $item['name'] : '',
  );

  $element['type'] = array(
    '#type' => 'select',
    '#title' => t('Type'),
    '#options' => plot_extender_plot_type(),
    '#description' => t('The timer.'),
  );


$element['dataset_reference'] = array(
  '#title' => t('Dataset'),
  '#type' => 'textfield',
  'autocomplete'  // WHAT DO I DO HERE?????
);

);

I can list the different field widgets and field types with field_info_formatter_types() and field_info_widget_types(), but I don't know how I would add an 'entityreference' or 'entityreference_autocomplete' to this block. Everything I try

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.