You are here

function markup_widget_process in Markup 6

Process the markup_widget element.

Build the form element. When creating a form using FAPI #process, note that $element['#value'] is already set.

The $fields array is in $form['#field_info'][$element['#field_name']].

1 string reference to 'markup_widget_process'
markup_elements in ./markup.module
Implements hook FAPI hook_elements().

File

./markup.module, line 189
Defines a field type for displaying markup on the node/edit form.

Code

function markup_widget_process($element, $edit, $form_state, $form) {
  $field = $form['#field_info'][$element['#field_name']];
  $markup = '';
  $valid_callback = FALSE;

  // Check to see if we have a markup callback, if so execute it.
  if (!empty($element['#markup_callback'])) {
    $callback = $element['#markup_callback'];
    if (function_exists($callback)) {
      $valid_callback = TRUE;
      $markup = $callback($element, $field, $form_state, $form);
    }
  }
  if (!$valid_callback) {

    // Check to see if there is a php value set, if so evaluate the code.
    if (!empty($element['#markup_php'])) {
      $node = array();

      // Check we are on a node edit form.
      if ($form['#id'] == 'node-form') {

        // Build a node element from the $form_state
        $node = markup_build_node($form, $form_state);
      }

      // Evaluate the php code, and pass in the $node object.
      $markup = markup_eval($field['markup_php'], array(
        'node' => $node,
      ));
    }
    else {
      if (!empty($element['#markup'])) {
        $markup = $element['#markup'];
      }
      else {

        // Check to see if the markup is empty, if so return element.
        return $element;
      }
    }
  }
  $element['element'] = array(
    '#type' => 'markup_element',
    '#title' => $element['#title'],
    '#markup' => $markup,
    '#display_style' => $field['widget']['display_style'],
    '#value' => array(),
  );
  return $element;
}