You are here

function _workflow_info_fields in Workflow 7.2

Same name and namespace in other branches
  1. 8 workflow.module \_workflow_info_fields()

Gets the workflow field names, if not known already.

For workflow_field, multiple workflows per bundle are supported. For workflow_node, only one 'field' structure is returned.

Parameters

$entity: Object to work with. May be empty, e.g., on menu build.

string $entity_type: Entity type of object. Optional, but required if $entity provided.

string $entity_bundle: Bundle of entity. Optional.

Return value

array $field_info An array of field_info structures.

12 calls to _workflow_info_fields()
theme_workflow_history_table in ./workflow.pages.inc
Theme entire workflow history table.
Workflow::isDeletable in includes/Entity/Workflow.php
Returns if the Workflow may be deleted.
WorkflowState::count in includes/Entity/WorkflowState.php
Returns the number of entities with this state.
WorkflowState::deactivate in includes/Entity/WorkflowState.php
Deactivate a Workflow State, moving existing nodes to a given State.
workflow_access_node_access_records in workflow_access/workflow_access.module
Implements hook_node_access_records().

... See full list

File

./workflow.module, line 1080
Support workflows made up of arbitrary states.

Code

function _workflow_info_fields($entity = NULL, $entity_type = '', $entity_bundle = '') {
  $field_info = array();

  // Unwrap the entity.
  if ($entity instanceof EntityDrupalWrapper) {
    $entity_type = $entity
      ->type();
    $entity = $entity
      ->value();
    list(, , $entity_bundle) = entity_extract_ids($entity_type, $entity);
  }

  // Check if this is a workflow_node sid.
  $workflow_node_sid = isset($entity->workflow) ? $entity->workflow : FALSE;
  if ($workflow_node_sid) {
    $field_name = '';
    $workflow = NULL;
    if ($state = workflow_state_load($workflow_node_sid)) {
      $workflow = workflow_load($state->wid);
    }

    // Call field_info_field().
    // Generates pseudo data for workflow_node to re-use Field API.
    $field = _workflow_info_field($field_name, $workflow);
    $field_info[$field_name] = $field;
  }
  else {

    // In Drupal 7.22, function field_info_field_map() was added, which is more
    // memory-efficient in certain cases than field_info_fields().
    // @see https://drupal.org/node/1915646
    $field_map_available = version_compare(VERSION, '7.22', '>=');
    $field_list = $field_map_available ? field_info_field_map() : field_info_fields();

    // Get the bundle, if not provided yet.
    if ($entity && !$entity_bundle) {
      list(, , $entity_bundle) = entity_extract_ids($entity_type, $entity);
    }
    foreach ($field_list as $field_name => $data) {
      if ($data['type'] == 'workflow' && (!$entity_type || array_key_exists($entity_type, $data['bundles'])) && (!$entity_bundle || in_array($entity_bundle, $data['bundles'][$entity_type]))) {
        $field_info[$field_name] = $field_map_available ? field_info_field($field_name) : $data;
      }
    }
  }
  return $field_info;
}