diff --git a/entityreference.module b/entityreference.module index 8d1dbed..880ea3d 100644 --- a/entityreference.module +++ b/entityreference.module @@ -783,6 +783,7 @@ function entityreference_autocomplete_callback($type, $field_name, $entity_type, // Loop through the products and convert them into autocomplete output. foreach ($entity_labels as $entity_id => $label) { $key = "$label ($entity_id)"; + // Strip things like starting/trailing white spaces, line breaks and tags. $key = preg_replace('/\s\s+/', ' ', str_replace("\n", '', trim(decode_entities(strip_tags($key))))); // Names containing commas or quotes must be wrapped in quotes. if (strpos($key, ',') !== FALSE || strpos($key, '"') !== FALSE) { diff --git a/plugins/selection/EntityReference_SelectionHandler_Views.class.php b/plugins/selection/EntityReference_SelectionHandler_Views.class.php index c4e50dc..6ccd715 100644 --- a/plugins/selection/EntityReference_SelectionHandler_Views.class.php +++ b/plugins/selection/EntityReference_SelectionHandler_Views.class.php @@ -42,7 +42,7 @@ class EntityReference_SelectionHandler_Views implements EntityReference_Selectio $form['view']['#element_validate'] = array('entityreference_view_settings_validate'); $options = array('' => '<' . t('none') . '>') + $options; - $default = empty($view_settings['view_name']) ? '' : $view_settings['view_name'] . ':' .$view_settings['display_name']; + $default = !empty($view_settings['view_name']) ? $view_settings['view_name'] . ':' .$view_settings['display_name'] : ''; $form['view']['view_and_display'] = array( '#type' => 'select', '#title' => t('View used to select the entities'), @@ -51,7 +51,7 @@ class EntityReference_SelectionHandler_Views implements EntityReference_Selectio '#description' => '

' . t('Choose the view and display that select the entities that can be referenced.
Only views with a display of type "Entity Reference" are eligible.') . '

', ); - $default = empty($view_settings['args']) ? '' : implode(', ', $view_settings['args']); + $default = !empty($view_settings['args']) ? implode(', ', $view_settings['args']) : ''; $form['view']['args'] = array( '#type' => 'textfield', '#title' => t('View arguments'), @@ -85,7 +85,7 @@ class EntityReference_SelectionHandler_Views implements EntityReference_Selectio } $this->view->set_display($display_name); - // Make sure the query is not cached + // Make sure the query is not cached. $this->view->is_cacheable = FALSE; // Pass options to the display handler to make them available later. @@ -163,7 +163,13 @@ function entityreference_view_settings_validate($element, &$form_state, $form) { // empty string into an array with one empty string. We'll need an empty array // instead. $args_string = trim($element['args']['#value']); - $args = ($args_string === '') ? array() : array_map('trim', explode(',', $args_string)); + if ($args_string === '') { + $args = array(); + } + else { + // array_map is called to trim whitespaces from the arguments. + $args = array_map('trim', explode(',', $args_string)); + } $value = array('view_name' => $view, 'display_name' => $display, 'args' => $args); form_set_value($element, $value, $form_state); diff --git a/views/entityreference_plugin_display.inc b/views/entityreference_plugin_display.inc index 7068d75..fbd2cb7 100644 --- a/views/entityreference_plugin_display.inc +++ b/views/entityreference_plugin_display.inc @@ -93,4 +93,15 @@ class entityreference_plugin_display extends views_plugin_display { $this->view->set_items_per_page($options['limit']); } + + /** + * Extend the default validation. + */ + function validate() { + $errors = parent::validate(); + if (!isset($this->options['search_fields']) || count($this->options['search_fields']) == 0) { + $errors[] = t('Display "@display" needs a selected search fields to work properly. See the settings for the Entity Reference list format.', array('@display' => $this->display->display_title)); + } + return $errors; + } } diff --git a/views/entityreference_plugin_style.inc b/views/entityreference_plugin_style.inc index 6d0b116..2099a93 100644 --- a/views/entityreference_plugin_style.inc +++ b/views/entityreference_plugin_style.inc @@ -53,10 +53,9 @@ class entityreference_plugin_style extends views_plugin_style { // widget, though. $results = array(); $this->view->row_index = 0; - foreach ($sets as $title => $records) { - foreach ($records as $label => $values) { + foreach ($sets as $records) { + foreach ($records as $values) { // Decode html, remove line breaks and extra whitespace - //$results[$values->{$id_field_alias}] = preg_replace('/\s\s+/', ' ', str_replace("\n", '', trim(decode_entities(strip_tags($this->row_plugin->render($values)))))); $results[$values->{$id_field_alias}] = preg_replace('/\s\s+/', ' ', str_replace("\n", '', decode_entities($this->row_plugin->render($values)))); $this->view->row_index++; }