You are here

public function state_flow_entity_handler_area_events_form::render in State Machine 7.3

Render the area.

Overrides views_handler_area_text::render

File

modules/state_flow_entity/includes/views/state_flow_entity_handler_area_events_form.inc, line 65
Contains state_flow_entity_handler_area_events_form

Class

state_flow_entity_handler_area_events_form
Views area handlers. Insert a state flow entity form in a view.

Code

public function render($empty = FALSE) {
  if (!$empty || !empty($this->options['empty'])) {
    if (!empty($this->options['entity_type'])) {
      $entity_type = $this->options['entity_type'];

      // The default text format might return the entity wrapped in p tags and
      // with a line break. Remove those and the result should be a numeric
      // id.
      $entity_id = trim(strip_tags($this
        ->render_textarea($this->options['entity_id'], NULL)));
      if (!empty($entity_id) && is_numeric($entity_id)) {

        // Get the active revision id.
        $default_entity_array = entity_load($entity_type, array(
          $entity_id,
        ));
        if (!empty($default_entity_array) && ($default_entity = array_pop($default_entity_array))) {
          if (!empty($this->options['entity_to_use']) && $this->options['entity_to_use'] == 'active') {
            $entity_info = entity_get_info($entity_type);
            $revision_key = $entity_info['entity keys']['revision'];
            $machine = state_flow_entity_load_state_machine($default_entity, $entity_type);
            $active_revision_id = $machine
              ->get_active_revision();

            // Get the active revision object.
            $conditions = array(
              $revision_key => $active_revision_id,
            );
            $entities = entity_load($entity_type, array(
              $entity_id,
            ), $conditions);
            $entity = array_pop($entities);
          }
          else {
            $entity = $default_entity;
          }
          $form_options = array(
            'assemble_page_title' => FALSE,
            'event_element_type' => 'select',
          );
          module_load_include('inc', 'state_flow_entity', 'state_flow_entity.forms');
          $output = drupal_render(drupal_get_form('state_flow_entity_events_revision', $entity, $entity_type, NULL, $form_options));
          return $output;
        }
      }
    }
  }
}