From fe69e59f751fbea86f4807446569c78bceb95398 Mon Sep 17 00:00:00 2001
From: Dan Chadwick <dan899@gmail.com>
Date: Wed, 5 Nov 2014 11:59:25 -0500
Subject: [PATCH] Issue #2117593 by Valentine94, DanChadwick: Fixed Select
 with empty (pre-built) option list should not be shown.

---
 components/select.inc |    4 ++++
 webform.module        |    6 ++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/components/select.inc b/components/select.inc
index 16e7c70..3ad24b3 100644
--- a/components/select.inc
+++ b/components/select.inc
@@ -314,6 +314,10 @@ function _webform_render_select($component, $value = NULL, $filter = TRUE) {
   // Convert the user-entered options list into an array.
   $default_value = $filter ? webform_replace_tokens($component['value'], $node) : $component['value'];
   $options = _webform_select_options($component, !$component['extra']['aslist'], $filter);
+  if (empty($options)) {
+    // Make element inaccessible if there are no options as there is no point in showing it.
+    $element['#access'] = FALSE;
+  }
 
   if ($component['extra']['optrand']) {
     _webform_shuffle_options($options);
diff --git a/webform.module b/webform.module
index f00da4a..3461ac3 100644
--- a/webform.module
+++ b/webform.module
@@ -2705,7 +2705,8 @@ function _webform_client_form_add_component($node, $component, $component_value,
     $data = empty($input_values[$cid]) ? NULL : $input_values[$cid];
     if ($display_element = webform_component_invoke($component['type'], 'display', $component, $data, $format)) {
       // Set access based on the private property.
-      $display_element['#access'] = $component_access;
+      $display_element += array('#access' => TRUE);
+      $display_element['#access'] = $display_element['#access'] && $component_access;
 
       // Ensure the component is added as a property.
       $display_element['#webform_component'] = $component;
@@ -2737,7 +2738,8 @@ function _webform_client_form_add_component($node, $component, $component_value,
     // Add this user-defined field to the form (with all the values that are always available).
     if ($element = webform_component_invoke($component['type'], 'render', $component, $component_value, $filter)) {
       // Set access based on the private property.
-      $element['#access'] = $component_access;
+      $element += array('#access' => TRUE);
+      $element['#access'] = $element['#access'] && $component_access;
 
       // Ensure the component is added as a property.
       $element['#webform_component'] = $component;
-- 
1.7.8.msysgit.0

