You are here

function webform_localization_get_config in Webform Localization 7.4

Same name and namespace in other branches
  1. 7 webform_localization.module \webform_localization_get_config()

Gets webform localization options that match a node ID.

@staticvar array $webform_localization_options An array of webform localization options group by nid.

Parameters

int $nid: A node Id.

bool $clear_cache: A flag to force a database reading in case that properties are cached.

Return value

array Webform localization options that match the nid.

21 calls to webform_localization_get_config()
webform_localization_entitycache_node_load in ./webform_localization.module
Implements hook_entitycache_node_load().
webform_localization_field_attach_prepare_translation_alter in ./webform_localization.module
Implements hook_field_attach_prepare_translation_alter().
webform_localization_form_webform_client_form_alter in ./webform_localization.module
Implements hook_form_webform_client_form_alter().
webform_localization_form_webform_component_edit_form_alter in ./webform_localization.module
Implements hook_form_FORM_ID_alter().
webform_localization_form_webform_configure_form_alter in ./webform_localization.module
Implements hook_form_FORM_ID_alter().

... See full list

File

./webform_localization.module, line 985
Webform localization module.

Code

function webform_localization_get_config($nid, $clear_cache = FALSE) {
  static $webform_localization_options = array();
  if ($clear_cache || !isset($webform_localization_options[$nid])) {
    $defaults = array_keys(webform_node_defaults());
    $webform_properties = array();
    foreach ($defaults as $key) {
      $webform_properties[$key] = $key;
    }
    unset($webform_properties['components']);
    unset($webform_properties['roles']);
    unset($webform_properties['emails']);
    unset($webform_properties['record_exists']);

    // If webform_uuid is being used since $component['nid'] is really a UUID
    // get the nid.
    if (module_exists('webform_uuid') && variable_get('webform_localization_using_uuid', FALSE)) {
      $record = entity_get_id_by_uuid('node', array(
        $nid,
      ));
      $nid = !empty($record) ? array_pop($record) : $nid;
    }

    // Select webform localization options that match this node ID.
    $options = db_select('webform_localization')
      ->fields('webform_localization')
      ->condition('nid', $nid, '=')
      ->execute()
      ->fetchAllAssoc('nid', PDO::FETCH_ASSOC);
    if (count($options) == 0) {
      $webform_localization_options[$nid] = array(
        'nid' => $nid,
        'expose_strings' => 0,
        'single_webform' => 0,
        'sync_components' => 0,
        'sync_roles' => 0,
        'sync_emails' => 0,
        'webform_properties' => array(),
        'webform_properties_structure' => $webform_properties,
        'no_persistent' => TRUE,
      );
    }
    else {
      $options[$nid]['webform_properties_structure'] = $webform_properties;
      if (empty($options[$nid]['webform_properties'])) {
        $options[$nid]['webform_properties'] = array();
      }
      else {
        $options[$nid]['webform_properties'] = unserialize($options[$nid]['webform_properties']);
      }
      $webform_localization_options[$nid] = $options[$nid];
    }
  }
  return $webform_localization_options[$nid];
}